Skip to content

Commit

Permalink
Service call to ReportProgress
Browse files Browse the repository at this point in the history
Bug: b/209384145
Change-Id: Ib94c8834abad044eea266a00a653bd91f64b51ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3789988
Commit-Queue: Julie Hockett <juliehockett@google.com>
Reviewed-by: Florian Gauger <fga@google.com>
Cr-Commit-Position: refs/heads/main@{#1035065}
  • Loading branch information
Julie Hockett authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent 17f7778 commit d575fe5
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ private byte[] getUserDataNative() {
return returnValue;
}

@CalledByNative
private byte[] reportProgressNative() {
return new byte[0];
}
@NativeMethods
interface Natives {
long javaServiceCreate(AutofillAssistantTestService service);
Expand Down
14 changes: 14 additions & 0 deletions components/autofill_assistant/browser/protocol_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,20 @@ std::string ProtocolUtils::CreateGetTriggerScriptsRequest(
return serialized_request_proto;
}

// static
std::string ProtocolUtils::CreateReportProgressRequest(
const std::string& token,
const std::string& payload) {
ReportProgressRequestProto request_proto;
*request_proto.mutable_token() = token;
*request_proto.mutable_payload() = payload;

std::string serialized_request_proto;
bool success = request_proto.SerializeToString(&serialized_request_proto);
DCHECK(success);
return serialized_request_proto;
}

// static
bool ProtocolUtils::ParseTriggerScripts(
const std::string& response,
Expand Down
4 changes: 4 additions & 0 deletions components/autofill_assistant/browser/protocol_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class ProtocolUtils {
const std::vector<std::string>& preexisting_payment_instrument_ids,
const std::string& client_token);

// Create request to report progress.
static std::string CreateReportProgressRequest(const std::string& token,
const std::string& payload);

// Create an action from the |action|.
static std::unique_ptr<Action> CreateAction(ActionDelegate* delegate,
const ActionProto& action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,13 @@ TEST_F(ProtocolUtilsTest, ComputeNetworkStats) {
expected_stats);
}

TEST_F(ProtocolUtilsTest, CreateReportProgressRequest) {
ReportProgressRequestProto request;
EXPECT_TRUE(request.ParseFromString(
ProtocolUtils::CreateReportProgressRequest("token", "payload")));

EXPECT_EQ("token", request.token());
EXPECT_EQ("payload", request.payload());
}

} // namespace autofill_assistant
13 changes: 13 additions & 0 deletions components/autofill_assistant/browser/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3600,3 +3600,16 @@ message ExternalActionProto {
optional external.ResultInfo result_info = 1;
}
}

// Fire-and-forget RPC request to report script progress.
message ReportProgressRequestProto {
// Token sent for the current flow by the initial call to GetActions.
optional bytes token = 1;
// Data to be logged; generated at script compile time.
optional bytes payload = 2;
}

message ReportProgressProto {
// Data to be logged; generated at script compile time.
optional string payload = 1;
}
13 changes: 13 additions & 0 deletions components/autofill_assistant/browser/service/java_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,17 @@ void JavaService::GetUserData(const CollectUserDataOptions& options,
ServiceRequestSender::ResponseInfo{});
}

void JavaService::ReportProgress(
const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) {
JNIEnv* env = base::android::AttachCurrentThread();
auto jresponse = Java_AutofillAssistantTestService_reportProgressNative(
env, java_service_);
std::string response;
base::android::JavaByteArrayToString(env, jresponse, &response);
std::move(callback).Run(net::HTTP_OK, response,
ServiceRequestSender::ResponseInfo{});
}

} // namespace autofill_assistant
4 changes: 4 additions & 0 deletions components/autofill_assistant/browser/service/java_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class JavaService : public Service {
const UserData* user_data,
ServiceRequestSender::ResponseCallback callback) override;

void ReportProgress(const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) override;

private:
base::android::ScopedJavaGlobalRef<jobject> java_service_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ void JavaTestEndpointService::GetUserData(
service_impl_->GetUserData(options, run_id, user_data, std::move(callback));
}

void JavaTestEndpointService::ReportProgress(
const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) {
service_impl_->ReportProgress(token, payload, std::move(callback));
}

} // namespace autofill_assistant
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class JavaTestEndpointService : public Service {
const UserData* user_data,
ServiceRequestSender::ResponseCallback callback) override;

void ReportProgress(const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) override;

private:
void OnGetScriptsForUrl(
ServiceRequestSender::ResponseCallback callback,
Expand Down
7 changes: 7 additions & 0 deletions components/autofill_assistant/browser/service/mock_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class MockService : public Service {
UpdateJsFlowLibraryLoaded,
(bool js_flow_library_loaded),
(override));

MOCK_METHOD(void,
ReportProgress,
(const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback),
(override));
};

} // namespace autofill_assistant
Expand Down
1 change: 1 addition & 0 deletions components/autofill_assistant/browser/service/rpc_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class RpcType {
SUPPORTS_SCRIPT,
GET_CAPABILITIES_BY_HASH_PREFIX,
GET_USER_DATA,
REPORT_PROGRESS,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const char kActionEndpoint[] = "/v1/actions2";
const char kTriggersEndpoint[] = "/v1/triggers";
const char kCapabilitiesByHashEndpoint[] = "/v1/capabilitiesByHashPrefix2";
const char kUserDataEndpoint[] = "/v1/userData";
const char kProgressEndpoint[] = "/v1/reportProgress";
} // namespace

namespace autofill_assistant {
Expand Down Expand Up @@ -71,4 +72,10 @@ GURL ServerUrlFetcher::GetUserDataEndpoint() const {
return server_url_.ReplaceComponents(user_data_replacements);
}

GURL ServerUrlFetcher::GetReportProgressEndpoint() const {
GURL::Replacements trigger_replacements;
trigger_replacements.SetPathStr(kProgressEndpoint);
return server_url_.ReplaceComponents(trigger_replacements);
}

} // namespace autofill_assistant
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class ServerUrlFetcher {
virtual GURL GetCapabilitiesByHashEndpoint() const;
// Returns the endpoint to send the GetUserData RPC to.
virtual GURL GetUserDataEndpoint() const;
// Returns the endpoint to send the ReportProgress RPC to.
virtual GURL GetReportProgressEndpoint() const;

private:
GURL server_url_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ TEST(ServerUrlFetcherTest, GetUserDataEndpoint) {
Eq(GURL("https://www.example.com/v1/userData")));
}

TEST(ServerUrlFetcherTest, GetReportProgressEndpoint) {
EXPECT_THAT(ServerUrlFetcher(GURL("https://www.example.com"))
.GetReportProgressEndpoint(),
Eq(GURL("https://www.example.com/v1/reportProgress")));
}

} // namespace
} // namespace autofill_assistant
7 changes: 6 additions & 1 deletion components/autofill_assistant/browser/service/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ class Service {

virtual void UpdateAnnotateDomModelContext(int64_t model_version) {}

virtual void UpdateJsFlowLibraryLoaded(bool js_flow_library_loaded){};
virtual void UpdateJsFlowLibraryLoaded(bool js_flow_library_loaded) {}

virtual void ReportProgress(
const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) = 0;

protected:
Service() = default;
Expand Down
11 changes: 11 additions & 0 deletions components/autofill_assistant/browser/service/service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@ void ServiceImpl::UpdateJsFlowLibraryLoaded(const bool js_flow_library_loaded) {
client_context_->UpdateJsFlowLibraryLoaded(js_flow_library_loaded);
}

void ServiceImpl::ReportProgress(
const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) {
// TODO(b/242136158): Check for UMA & MSBB here before sending request.
request_sender_->SendRequest(
script_action_server_url_,
ProtocolUtils::CreateReportProgressRequest(token, payload),
GetDefaultAuthMode(), std::move(callback), RpcType::REPORT_PROGRESS);
}

} // namespace autofill_assistant
4 changes: 4 additions & 0 deletions components/autofill_assistant/browser/service/service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class ServiceImpl : public Service {
const UserData* user_data,
ServiceRequestSender::ResponseCallback callback) override;

void ReportProgress(const std::string& token,
const std::string& payload,
ServiceRequestSender::ResponseCallback callback) override;

void SetDisableRpcSigning(bool disable_rpc_signing) override;

void UpdateAnnotateDomModelContext(int64_t model_version) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,21 @@ TEST_F(ServiceImplTest, UpdateJsFlowLibraryLoaded) {
service_->UpdateJsFlowLibraryLoaded(true);
}

TEST_F(ServiceImplTest, ReportProgress) {
const std::string token = "token";
const std::string payload = "payload";

EXPECT_CALL(
*mock_request_sender_,
OnSendRequest(GURL(kActionServerUrl),
ProtocolUtils::CreateReportProgressRequest(token, payload),
_, RpcType::REPORT_PROGRESS))
.WillOnce(RunOnceCallback<2>(net::HTTP_OK, std::string(""),
ServiceRequestSender::ResponseInfo{}));
EXPECT_CALL(mock_response_callback_, Run(net::HTTP_OK, std::string(""), _));

service_->ReportProgress("token", "payload", mock_response_callback_.Get());
}

} // namespace
} // namespace autofill_assistant

0 comments on commit d575fe5

Please sign in to comment.