Commit 02ed4778 authored by Alex Clarke's avatar Alex Clarke Committed by Commit Bot

Variations changes to support WebLayer clients.

WebLayer will be using VariationsService but it's distinct from android
chrome so we need a way to override the platform in the variations url
request.

Bug: 1025612
Change-Id: Ie4f9f6bfabc3a6b9234fcf5589ad9f5b98c3224f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1951012
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736953}
parent 01aa6000
...@@ -157,7 +157,8 @@ TEST_F(FieldTrialUtilTest, AssociateParamsFromFieldTrialConfig) { ...@@ -157,7 +157,8 @@ TEST_F(FieldTrialUtilTest, AssociateParamsFromFieldTrialConfig) {
TEST_F(FieldTrialUtilTest, TEST_F(FieldTrialUtilTest,
AssociateParamsFromFieldTrialConfigWithEachPlatform) { AssociateParamsFromFieldTrialConfigWithEachPlatform) {
const Study::Platform all_platforms[] = { const Study::Platform all_platforms[] = {
Study::PLATFORM_ANDROID, Study::PLATFORM_ANDROID, // Comment to prevent clang format bin packing.
Study::PLATFORM_ANDROID_WEBLAYER,
Study::PLATFORM_ANDROID_WEBVIEW, Study::PLATFORM_ANDROID_WEBVIEW,
Study::PLATFORM_CHROMEOS, Study::PLATFORM_CHROMEOS,
Study::PLATFORM_FUCHSIA, Study::PLATFORM_FUCHSIA,
......
...@@ -191,6 +191,7 @@ message Study { ...@@ -191,6 +191,7 @@ message Study {
PLATFORM_IOS = 5; PLATFORM_IOS = 5;
PLATFORM_ANDROID_WEBVIEW = 6; PLATFORM_ANDROID_WEBVIEW = 6;
PLATFORM_FUCHSIA = 7; PLATFORM_FUCHSIA = 7;
PLATFORM_ANDROID_WEBLAYER = 8;
} }
// Possible form factors Chrome is running on. // Possible form factors Chrome is running on.
......
...@@ -399,8 +399,10 @@ GURL VariationsService::GetVariationsServerURL(HttpOptions http_options) { ...@@ -399,8 +399,10 @@ GURL VariationsService::GetVariationsServerURL(HttpOptions http_options) {
server_url = net::AppendOrReplaceQueryParameter(server_url, "restrict", server_url = net::AppendOrReplaceQueryParameter(server_url, "restrict",
restrict_mode); restrict_mode);
} }
server_url = net::AppendOrReplaceQueryParameter(server_url, "osname", server_url = net::AppendOrReplaceQueryParameter(
GetPlatformString()); server_url, "osname",
osname_server_param_override_.empty() ? GetPlatformString()
: osname_server_param_override_);
// Add channel to the request URL. // Add channel to the request URL.
version_info::Channel channel = client_->GetChannelForVariations(); version_info::Channel channel = client_->GetChannelForVariations();
...@@ -949,6 +951,13 @@ void VariationsService::StartRepeatedVariationsSeedFetchForTesting() { ...@@ -949,6 +951,13 @@ void VariationsService::StartRepeatedVariationsSeedFetchForTesting() {
return StartRepeatedVariationsSeedFetch(); return StartRepeatedVariationsSeedFetch();
} }
void VariationsService::OverridePlatform(
Study::Platform platform,
const std::string& osname_server_param_override) {
field_trial_creator_.OverrideVariationsPlatform(platform);
osname_server_param_override_ = osname_server_param_override;
}
std::string VariationsService::GetOverriddenPermanentCountry() { std::string VariationsService::GetOverriddenPermanentCountry() {
return local_state_->GetString(prefs::kVariationsPermanentOverriddenCountry); return local_state_->GetString(prefs::kVariationsPermanentOverriddenCountry);
} }
......
...@@ -219,6 +219,12 @@ class VariationsService ...@@ -219,6 +219,12 @@ class VariationsService
// Exposes StartRepeatedVariationsSeedFetch for testing. // Exposes StartRepeatedVariationsSeedFetch for testing.
void StartRepeatedVariationsSeedFetchForTesting(); void StartRepeatedVariationsSeedFetchForTesting();
// Allows the embedder to override the platform and override the OS name in
// the variations server url. This is useful for android webview and weblayer
// which are distinct from regular android chrome.
void OverridePlatform(Study::Platform platform,
const std::string& osname_server_param_override);
protected: protected:
// Starts the fetching process once, where |OnURLFetchComplete| is called with // Starts the fetching process once, where |OnURLFetchComplete| is called with
// the response. This calls DoFetchToURL with the set url. // the response. This calls DoFetchToURL with the set url.
...@@ -431,6 +437,10 @@ class VariationsService ...@@ -431,6 +437,10 @@ class VariationsService
// True if the last request was a retry over http. // True if the last request was a retry over http.
bool last_request_was_http_retry_; bool last_request_was_http_retry_;
// When not empty, contains an override for the os name in the variations
// server url.
std::string osname_server_param_override_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<VariationsService> weak_ptr_factory_{this}; base::WeakPtrFactory<VariationsService> weak_ptr_factory_{this};
......
...@@ -213,13 +213,17 @@ TEST(VariationsStudyFilteringTest, CheckStudyLocale) { ...@@ -213,13 +213,17 @@ TEST(VariationsStudyFilteringTest, CheckStudyLocale) {
} }
TEST(VariationsStudyFilteringTest, CheckStudyPlatform) { TEST(VariationsStudyFilteringTest, CheckStudyPlatform) {
const Study::Platform platforms[] = { const Study::Platform platforms[] = {Study::PLATFORM_WINDOWS,
Study::PLATFORM_WINDOWS, Study::PLATFORM_MAC, Study::PLATFORM_MAC,
Study::PLATFORM_LINUX, Study::PLATFORM_CHROMEOS, Study::PLATFORM_LINUX,
Study::PLATFORM_ANDROID, Study::PLATFORM_IOS, Study::PLATFORM_CHROMEOS,
Study::PLATFORM_ANDROID_WEBVIEW, Study::PLATFORM_FUCHSIA}; Study::PLATFORM_ANDROID,
Study::PLATFORM_IOS,
Study::PLATFORM_ANDROID_WEBLAYER,
Study::PLATFORM_FUCHSIA,
Study::PLATFORM_ANDROID_WEBVIEW};
ASSERT_EQ(Study::Platform_ARRAYSIZE, static_cast<int>(base::size(platforms))); ASSERT_EQ(Study::Platform_ARRAYSIZE, static_cast<int>(base::size(platforms)));
bool platform_added[base::size(platforms)] = {0}; bool platform_added[base::size(platforms)] = {false};
Study::Filter filter; Study::Filter filter;
......
...@@ -32,6 +32,7 @@ finally: ...@@ -32,6 +32,7 @@ finally:
_platforms = [ _platforms = [
'android', 'android',
'android_weblayer',
'android_webview', 'android_webview',
'chromeos', 'chromeos',
'fuchsia', 'fuchsia',
......
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