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) {
TEST_F(FieldTrialUtilTest,
AssociateParamsFromFieldTrialConfigWithEachPlatform) {
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_CHROMEOS,
Study::PLATFORM_FUCHSIA,
......
......@@ -183,14 +183,15 @@ message Study {
// Possible Chrome operating system platforms.
// These names must match those in tools/variations/fieldtrial_to_struct.py.
enum Platform {
PLATFORM_WINDOWS = 0;
PLATFORM_MAC = 1;
PLATFORM_LINUX = 2;
PLATFORM_CHROMEOS = 3;
PLATFORM_ANDROID = 4;
PLATFORM_IOS = 5;
PLATFORM_WINDOWS = 0;
PLATFORM_MAC = 1;
PLATFORM_LINUX = 2;
PLATFORM_CHROMEOS = 3;
PLATFORM_ANDROID = 4;
PLATFORM_IOS = 5;
PLATFORM_ANDROID_WEBVIEW = 6;
PLATFORM_FUCHSIA = 7;
PLATFORM_FUCHSIA = 7;
PLATFORM_ANDROID_WEBLAYER = 8;
}
// Possible form factors Chrome is running on.
......
......@@ -399,8 +399,10 @@ GURL VariationsService::GetVariationsServerURL(HttpOptions http_options) {
server_url = net::AppendOrReplaceQueryParameter(server_url, "restrict",
restrict_mode);
}
server_url = net::AppendOrReplaceQueryParameter(server_url, "osname",
GetPlatformString());
server_url = net::AppendOrReplaceQueryParameter(
server_url, "osname",
osname_server_param_override_.empty() ? GetPlatformString()
: osname_server_param_override_);
// Add channel to the request URL.
version_info::Channel channel = client_->GetChannelForVariations();
......@@ -949,6 +951,13 @@ void VariationsService::StartRepeatedVariationsSeedFetchForTesting() {
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() {
return local_state_->GetString(prefs::kVariationsPermanentOverriddenCountry);
}
......
......@@ -219,6 +219,12 @@ class VariationsService
// Exposes StartRepeatedVariationsSeedFetch for testing.
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:
// Starts the fetching process once, where |OnURLFetchComplete| is called with
// the response. This calls DoFetchToURL with the set url.
......@@ -431,6 +437,10 @@ class VariationsService
// True if the last request was a retry over http.
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_);
base::WeakPtrFactory<VariationsService> weak_ptr_factory_{this};
......
......@@ -213,13 +213,17 @@ TEST(VariationsStudyFilteringTest, CheckStudyLocale) {
}
TEST(VariationsStudyFilteringTest, CheckStudyPlatform) {
const Study::Platform platforms[] = {
Study::PLATFORM_WINDOWS, Study::PLATFORM_MAC,
Study::PLATFORM_LINUX, Study::PLATFORM_CHROMEOS,
Study::PLATFORM_ANDROID, Study::PLATFORM_IOS,
Study::PLATFORM_ANDROID_WEBVIEW, Study::PLATFORM_FUCHSIA};
const Study::Platform platforms[] = {Study::PLATFORM_WINDOWS,
Study::PLATFORM_MAC,
Study::PLATFORM_LINUX,
Study::PLATFORM_CHROMEOS,
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)));
bool platform_added[base::size(platforms)] = {0};
bool platform_added[base::size(platforms)] = {false};
Study::Filter filter;
......
......@@ -31,20 +31,21 @@ finally:
sys.path.pop(0)
_platforms = [
'android',
'android_webview',
'chromeos',
'fuchsia',
'ios',
'linux',
'mac',
'windows',
'android',
'android_weblayer',
'android_webview',
'chromeos',
'fuchsia',
'ios',
'linux',
'mac',
'windows',
]
_form_factors = [
'desktop',
'phone',
'tablet',
'desktop',
'phone',
'tablet',
]
# Convert a platform argument to the matching Platform enum value in
......
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