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;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
import org.chromium.components.variations.VariationsAssociatedData;
import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
......@@ -30,10 +31,24 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
/** Prefix for Intent extras relevant to this feature. */
private static final String INTENT_EXTRA_PREFIX =
"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 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.
*
......
......@@ -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
// intent.
if (mAutofillAssistantUiController == null
&& ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)) {
&& ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
&& AutofillAssistantUiController.isConfigured()) {
mAutofillAssistantUiController = new AutofillAssistantUiController(this);
}
......
......@@ -12,8 +12,10 @@
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/command_line.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/common/channel_info.h"
#include "components/autofill_assistant/browser/controller.h"
#include "components/variations/variations_associated_data.h"
#include "components/version_info/channel.h"
#include "content/public/browser/web_contents.h"
#include "google_apis/google_api_keys.h"
......@@ -143,6 +145,11 @@ std::string UiControllerAndroid::GetApiKey() {
return api_key;
}
std::string UiControllerAndroid::GetServerUrl() {
return variations::GetVariationParamValueByFeature(
chrome::android::kAutofillAssistant, "url");
}
UiController* UiControllerAndroid::GetUiController() {
return this;
}
......
......@@ -39,6 +39,7 @@ class UiControllerAndroid : public UiController, public Client {
// Overrides Client:
std::string GetApiKey() override;
std::string GetServerUrl() override;
UiController* GetUiController() override;
// Called by Java.
......
......@@ -19,6 +19,9 @@ class Client {
// Returns the API key to be used for requests to the backend.
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.
virtual UiController* GetUiController() = 0;
......
......@@ -10,6 +10,7 @@
#include "components/autofill_assistant/browser/ui_controller.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"
namespace autofill_assistant {
// static
......@@ -19,11 +20,13 @@ void Controller::CreateAndStartForWebContents(
std::unique_ptr<std::map<std::string, std::string>> parameters) {
// Get the key early since |client| will be invalidated when moved below.
const std::string api_key = client->GetApiKey();
new Controller(
web_contents, std::move(client),
WebController::CreateForWebContents(web_contents),
std::make_unique<Service>(api_key, web_contents->GetBrowserContext()),
std::move(parameters));
GURL server_url(client->GetServerUrl());
DCHECK(server_url.is_valid());
new Controller(web_contents, std::move(client),
WebController::CreateForWebContents(web_contents),
std::make_unique<Service>(api_key, server_url,
web_contents->GetBrowserContext()),
std::move(parameters));
}
Service* Controller::GetService() {
......
......@@ -40,7 +40,7 @@ class FakeClient : public Client {
// Implements Client
std::string GetApiKey() override { return ""; }
std::string GetServerUrl() override { return ""; }
UiController* GetUiController() override { return ui_controller_.get(); }
private:
......
......@@ -4,9 +4,11 @@
#include "components/autofill_assistant/browser/mock_service.h"
#include "url/gurl.h"
namespace autofill_assistant {
MockService::MockService() : Service("api_key", nullptr) {}
MockService::MockService() : Service("api_key", GURL("http://fake"), nullptr) {}
MockService::~MockService() {}
} // namespace autofill_assistant
......@@ -8,7 +8,6 @@
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/strings/strcat.h"
#include "components/autofill_assistant/browser/protocol_utils.h"
#include "content/public/browser/browser_context.h"
......@@ -20,7 +19,6 @@
namespace {
// TODO(crbug.com/806868): Provide correct server and endpoint.
const char* const kAutofillAssistantServer = "";
const char* const kScriptEndpoint = "/v1/supportsSite2";
const char* const kActionEndpoint = "/v1/actions2";
......@@ -46,37 +44,22 @@ net::NetworkTrafficAnnotationTag traffic_annotation =
namespace autofill_assistant {
namespace switches {
const char* const kAutofillAssistantServerURL = "autofill-assistant-url";
} // namespace switches
Service::Service(const std::string& api_key, content::BrowserContext* context)
Service::Service(const std::string& api_key,
const GURL& server_url,
content::BrowserContext* context)
: context_(context) {
const auto* command_line = base::CommandLine::ForCurrentProcess();
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;
}
}
DCHECK(server_url.is_valid());
std::string api_key_query = base::StrCat({"key=", api_key});
url::StringPieceReplacements<std::string> script_replacements;
script_replacements.SetPathStr(kScriptEndpoint);
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;
action_replacements.SetPathStr(kActionEndpoint);
action_replacements.SetQueryStr(api_key_query);
script_action_server_url_ =
service_url.ReplaceComponents(action_replacements);
script_action_server_url_ = server_url.ReplaceComponents(action_replacements);
}
Service::~Service() {}
......
......@@ -24,8 +24,9 @@ namespace autofill_assistant {
// client actions.
class Service {
public:
explicit Service(const std::string& api_key,
content::BrowserContext* context);
Service(const std::string& api_key,
const GURL& server_url,
content::BrowserContext* context);
virtual ~Service();
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