Commit 3c7da5b8 authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Server url as finch parameter.

R=rouslan@chromium.org, szermatt@chromium.org

Bug: 806868
Change-Id: I0e45696a6946e33312190498c9b1c89877a4d58e
Reviewed-on: https://chromium-review.googlesource.com/1245706Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595446}
parent e195437f
...@@ -14,6 +14,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -14,6 +14,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
import org.chromium.components.variations.VariationsAssociatedData;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -30,10 +31,24 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -30,10 +31,24 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
/** Prefix for Intent extras relevant to this feature. */ /** Prefix for Intent extras relevant to this feature. */
private static final String INTENT_EXTRA_PREFIX = private static final String INTENT_EXTRA_PREFIX =
"org.chromium.chrome.browser.autofill_assistant."; "org.chromium.chrome.browser.autofill_assistant.";
/** Autofill Assistant Study name. */
private static final String STUDY_NAME = "AutofillAssistant";
/** Variation url parameter name. */
private static final String URL_PARAMETER_NAME = "url";
private final long mUiControllerAndroid; private final long mUiControllerAndroid;
private final AutofillAssistantUiDelegate mUiDelegate; private final AutofillAssistantUiDelegate mUiDelegate;
/**
* Returns true if all conditions are satisfied to construct an AutofillAssistantUiController.
*
* @return True if a controller can be constructed.
*/
public static boolean isConfigured() {
return !VariationsAssociatedData.getVariationParamValue(STUDY_NAME, URL_PARAMETER_NAME)
.isEmpty();
}
/** /**
* Construct Autofill Assistant UI controller. * Construct Autofill Assistant UI controller.
* *
......
...@@ -683,7 +683,8 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent ...@@ -683,7 +683,8 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
// TODO(crbug.com/806868): Only enable Autofill Assistant when the flag is enabled in the // TODO(crbug.com/806868): Only enable Autofill Assistant when the flag is enabled in the
// intent. // intent.
if (mAutofillAssistantUiController == null if (mAutofillAssistantUiController == null
&& ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)) { && ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
&& AutofillAssistantUiController.isConfigured()) {
mAutofillAssistantUiController = new AutofillAssistantUiController(this); mAutofillAssistantUiController = new AutofillAssistantUiController(this);
} }
......
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "components/autofill_assistant/browser/controller.h" #include "components/autofill_assistant/browser/controller.h"
#include "components/variations/variations_associated_data.h"
#include "components/version_info/channel.h" #include "components/version_info/channel.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
...@@ -143,6 +145,11 @@ std::string UiControllerAndroid::GetApiKey() { ...@@ -143,6 +145,11 @@ std::string UiControllerAndroid::GetApiKey() {
return api_key; return api_key;
} }
std::string UiControllerAndroid::GetServerUrl() {
return variations::GetVariationParamValueByFeature(
chrome::android::kAutofillAssistant, "url");
}
UiController* UiControllerAndroid::GetUiController() { UiController* UiControllerAndroid::GetUiController() {
return this; return this;
} }
......
...@@ -39,6 +39,7 @@ class UiControllerAndroid : public UiController, public Client { ...@@ -39,6 +39,7 @@ class UiControllerAndroid : public UiController, public Client {
// Overrides Client: // Overrides Client:
std::string GetApiKey() override; std::string GetApiKey() override;
std::string GetServerUrl() override;
UiController* GetUiController() override; UiController* GetUiController() override;
// Called by Java. // Called by Java.
......
...@@ -19,6 +19,9 @@ class Client { ...@@ -19,6 +19,9 @@ class Client {
// Returns the API key to be used for requests to the backend. // Returns the API key to be used for requests to the backend.
virtual std::string GetApiKey() = 0; virtual std::string GetApiKey() = 0;
// Returns the server URL to be used for requests to the backend.
virtual std::string GetServerUrl() = 0;
// Returns a UiController. // Returns a UiController.
virtual UiController* GetUiController() = 0; virtual UiController* GetUiController() = 0;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "components/autofill_assistant/browser/ui_controller.h" #include "components/autofill_assistant/browser/ui_controller.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "url/gurl.h"
namespace autofill_assistant { namespace autofill_assistant {
// static // static
...@@ -19,11 +20,13 @@ void Controller::CreateAndStartForWebContents( ...@@ -19,11 +20,13 @@ void Controller::CreateAndStartForWebContents(
std::unique_ptr<std::map<std::string, std::string>> parameters) { std::unique_ptr<std::map<std::string, std::string>> parameters) {
// Get the key early since |client| will be invalidated when moved below. // Get the key early since |client| will be invalidated when moved below.
const std::string api_key = client->GetApiKey(); const std::string api_key = client->GetApiKey();
new Controller( GURL server_url(client->GetServerUrl());
web_contents, std::move(client), DCHECK(server_url.is_valid());
WebController::CreateForWebContents(web_contents), new Controller(web_contents, std::move(client),
std::make_unique<Service>(api_key, web_contents->GetBrowserContext()), WebController::CreateForWebContents(web_contents),
std::move(parameters)); std::make_unique<Service>(api_key, server_url,
web_contents->GetBrowserContext()),
std::move(parameters));
} }
Service* Controller::GetService() { Service* Controller::GetService() {
......
...@@ -40,7 +40,7 @@ class FakeClient : public Client { ...@@ -40,7 +40,7 @@ class FakeClient : public Client {
// Implements Client // Implements Client
std::string GetApiKey() override { return ""; } std::string GetApiKey() override { return ""; }
std::string GetServerUrl() override { return ""; }
UiController* GetUiController() override { return ui_controller_.get(); } UiController* GetUiController() override { return ui_controller_.get(); }
private: private:
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "components/autofill_assistant/browser/mock_service.h" #include "components/autofill_assistant/browser/mock_service.h"
#include "url/gurl.h"
namespace autofill_assistant { namespace autofill_assistant {
MockService::MockService() : Service("api_key", nullptr) {} MockService::MockService() : Service("api_key", GURL("http://fake"), nullptr) {}
MockService::~MockService() {} MockService::~MockService() {}
} // namespace autofill_assistant } // namespace autofill_assistant
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/command_line.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "components/autofill_assistant/browser/protocol_utils.h" #include "components/autofill_assistant/browser/protocol_utils.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -20,7 +19,6 @@ ...@@ -20,7 +19,6 @@
namespace { namespace {
// TODO(crbug.com/806868): Provide correct server and endpoint. // TODO(crbug.com/806868): Provide correct server and endpoint.
const char* const kAutofillAssistantServer = "";
const char* const kScriptEndpoint = "/v1/supportsSite2"; const char* const kScriptEndpoint = "/v1/supportsSite2";
const char* const kActionEndpoint = "/v1/actions2"; const char* const kActionEndpoint = "/v1/actions2";
...@@ -46,37 +44,22 @@ net::NetworkTrafficAnnotationTag traffic_annotation = ...@@ -46,37 +44,22 @@ net::NetworkTrafficAnnotationTag traffic_annotation =
namespace autofill_assistant { namespace autofill_assistant {
namespace switches { Service::Service(const std::string& api_key,
const char* const kAutofillAssistantServerURL = "autofill-assistant-url"; const GURL& server_url,
} // namespace switches content::BrowserContext* context)
Service::Service(const std::string& api_key, content::BrowserContext* context)
: context_(context) { : context_(context) {
const auto* command_line = base::CommandLine::ForCurrentProcess(); DCHECK(server_url.is_valid());
GURL service_url(kAutofillAssistantServer);
if (command_line->HasSwitch(switches::kAutofillAssistantServerURL)) {
GURL custom_url(command_line->GetSwitchValueASCII(
switches::kAutofillAssistantServerURL));
if (custom_url.is_valid()) {
service_url = custom_url;
} else {
LOG(WARNING) << "The following autofill assisstant URL specified in "
"the command line is invalid: "
<< custom_url;
}
}
std::string api_key_query = base::StrCat({"key=", api_key}); std::string api_key_query = base::StrCat({"key=", api_key});
url::StringPieceReplacements<std::string> script_replacements; url::StringPieceReplacements<std::string> script_replacements;
script_replacements.SetPathStr(kScriptEndpoint); script_replacements.SetPathStr(kScriptEndpoint);
script_replacements.SetQueryStr(api_key_query); script_replacements.SetQueryStr(api_key_query);
script_server_url_ = service_url.ReplaceComponents(script_replacements); script_server_url_ = server_url.ReplaceComponents(script_replacements);
url::StringPieceReplacements<std::string> action_replacements; url::StringPieceReplacements<std::string> action_replacements;
action_replacements.SetPathStr(kActionEndpoint); action_replacements.SetPathStr(kActionEndpoint);
action_replacements.SetQueryStr(api_key_query); action_replacements.SetQueryStr(api_key_query);
script_action_server_url_ = script_action_server_url_ = server_url.ReplaceComponents(action_replacements);
service_url.ReplaceComponents(action_replacements);
} }
Service::~Service() {} Service::~Service() {}
......
...@@ -24,8 +24,9 @@ namespace autofill_assistant { ...@@ -24,8 +24,9 @@ namespace autofill_assistant {
// client actions. // client actions.
class Service { class Service {
public: public:
explicit Service(const std::string& api_key, Service(const std::string& api_key,
content::BrowserContext* context); const GURL& server_url,
content::BrowserContext* context);
virtual ~Service(); virtual ~Service();
using ResponseCallback = using ResponseCallback =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment