Commit 08ae48ad authored by Xi Han's avatar Xi Han Committed by Commit Bot

[FeatureList] Change GetApplicationLocale() in VariationsServiceClient to be a...

[FeatureList] Change GetApplicationLocale() in VariationsServiceClient to be a local function. [2/3]

Before this function uses a pref in Chrome so we need to override it in Chrome
to access that pref value.

As a followup for this cl https://crrev.com/c/1135198,
now we can access the pref directly in componment/ and we no longer need to do that.

This CL comes from https://crrev.com/c/1140356. See previous discussion there.

Bug:729596
TBR=asvitkine@chromium.org

Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I7bf5631b81436344ccb17aaa2a8d6ac4167f5d7f
Reviewed-on: https://chromium-review.googlesource.com/1147481
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586711}
parent 378d77b0
......@@ -28,10 +28,6 @@ AwVariationsServiceClient::AwVariationsServiceClient() {}
AwVariationsServiceClient::~AwVariationsServiceClient() {}
std::string AwVariationsServiceClient::GetApplicationLocale() {
return std::string();
}
base::Callback<base::Version(void)>
AwVariationsServiceClient::GetVersionForSimulationCallback() {
return base::BindRepeating(&GetVersionForSimulation);
......
......@@ -25,7 +25,6 @@ class AwVariationsServiceClient : public variations::VariationsServiceClient {
~AwVariationsServiceClient() override;
private:
std::string GetApplicationLocale() override;
base::Callback<base::Version(void)> GetVersionForSimulationCallback()
override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
......
......@@ -1162,5 +1162,15 @@ void ChromeMainDelegate::PreCreateMainMessageLoop() {
// Initialize NSApplication using the custom subclass.
chrome_browser_application_mac::RegisterBrowserCrApp();
if (l10n_util::GetLocaleOverride().empty()) {
// The browser process only wants to support the language Cocoa will use,
// so force the app locale to be overridden with that value. This must
// happen before the ResourceBundle is loaded, which happens in
// ChromeBrowserMainParts::PreEarlyInitialization().
// Don't do this if the locale is already set, which is done by integration
// tests to ensure tests always run with the same locale.
l10n_util::OverrideLocaleWithCocoaLocale();
}
#endif
}
......@@ -34,7 +34,6 @@
#include "components/metrics/metrics_service.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/result_codes.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_handle.h"
......@@ -88,15 +87,6 @@ int ChromeBrowserMainPartsMac::PreEarlyInitialization() {
singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
}
// If ui_task is not NULL, the app is actually a browser_test.
if (!parameters().ui_task) {
// The browser process only wants to support the language Cocoa will use,
// so force the app locale to be overriden with that value. This must
// happen before the ResourceBundle is loaded, which happens in
// ChromeBrowserMainParts::PreEarlyInitialization().
l10n_util::OverrideLocaleWithCocoaLocale();
}
return ChromeBrowserMainPartsPosix::PreEarlyInitialization();
}
......
......@@ -43,10 +43,6 @@ ChromeVariationsServiceClient::ChromeVariationsServiceClient() {}
ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {}
std::string ChromeVariationsServiceClient::GetApplicationLocale() {
return g_browser_process->GetApplicationLocale();
}
base::Callback<base::Version(void)>
ChromeVariationsServiceClient::GetVersionForSimulationCallback() {
return base::Bind(&GetVersionForSimulation);
......
......@@ -24,7 +24,6 @@ class ChromeVariationsServiceClient
~ChromeVariationsServiceClient() override;
// variations::VariationsServiceClient:
std::string GetApplicationLocale() override;
base::Callback<base::Version(void)> GetVersionForSimulationCallback()
override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
......
......@@ -20,6 +20,7 @@ static_library("service") {
"//base",
"//components/data_use_measurement/core",
"//components/encrypted_messages",
"//components/language/core/browser",
"//components/metrics",
"//components/network_time",
"//components/pref_registry",
......
include_rules = [
"+components/data_use_measurement/core",
"+components/encrypted_messages",
"+components/language/core/browser",
"+components/metrics",
"+components/network_time",
"+components/pref_registry",
......
......@@ -24,6 +24,7 @@
#include "base/trace_event/trace_event.h"
#include "base/version.h"
#include "build/build_config.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/variations/field_trial_config/field_trial_util.h"
#include "components/variations/platform_field_trials.h"
......@@ -35,6 +36,7 @@
#include "components/variations/variations_seed_processor.h"
#include "components/variations/variations_switches.h"
#include "ui/base/device_form_factor.h"
#include "ui/base/l10n/l10n_util.h"
namespace variations {
namespace {
......@@ -151,6 +153,15 @@ void ExitWithMessage(const std::string& message) {
exit(1);
}
// Returns the current application locale (e.g. "en-US").
std::string GetApplicationLocale(PrefService* local_state) {
if (!local_state->HasPrefPath(language::prefs::kApplicationLocale))
return std::string();
std::string locale =
local_state->GetString(language::prefs::kApplicationLocale);
return l10n_util::GetApplicationLocale(locale);
}
} // namespace
VariationsFieldTrialCreator::VariationsFieldTrialCreator(
......@@ -245,7 +256,7 @@ VariationsFieldTrialCreator::GetClientFilterableStateForVersion(
const base::Version& version) {
std::unique_ptr<ClientFilterableState> state =
std::make_unique<ClientFilterableState>();
state->locale = client_->GetApplicationLocale();
state->locale = GetApplicationLocale(local_state());
state->reference_date = GetReferenceDateForExpiryChecks(local_state());
state->version = version;
state->channel = GetChannelForVariations(client_->GetChannel());
......
......@@ -155,7 +155,6 @@ class TestVariationsServiceClient : public VariationsServiceClient {
~TestVariationsServiceClient() override = default;
// VariationsServiceClient:
std::string GetApplicationLocale() override { return std::string(); }
base::Callback<base::Version(void)> GetVersionForSimulationCallback()
override {
return base::Callback<base::Version(void)>();
......
......@@ -29,9 +29,6 @@ class VariationsServiceClient {
public:
virtual ~VariationsServiceClient() {}
// Returns the current application locale (e.g. "en-US").
virtual std::string GetApplicationLocale() = 0;
// Returns a callback that when run returns the base::Version to use for
// variations seed simulation. VariationsService guarantees that the callback
// will be run on a background thread that permits blocking.
......
......@@ -71,7 +71,6 @@ class TestVariationsServiceClient : public VariationsServiceClient {
~TestVariationsServiceClient() override {}
// VariationsServiceClient:
std::string GetApplicationLocale() override { return std::string(); }
base::Callback<base::Version(void)> GetVersionForSimulationCallback()
override {
return base::Bind(&StubGetVersionForSimulation);
......
......@@ -72,6 +72,7 @@
#include <cstring>
#include "base/trace_event/trace_event_etw_export_win.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/display/win/dpi.h"
#elif defined(OS_MACOSX)
#include "base/mac/mach_port_broker.h"
......@@ -878,6 +879,14 @@ int ContentMainRunnerImpl::Run(bool start_service_manager_only) {
}
delegate_->PreCreateMainMessageLoop();
#if defined(OS_WIN)
if (l10n_util::GetLocaleOverrides().empty()) {
// Override the configured locale with the user's preferred UI language.
// Don't do this if the locale is already set, which is done by
// integration tests to ensure tests always run with the same locale.
l10n_util::OverrideLocaleWithUILanguageList();
}
#endif
// Create a MessageLoop if one does not already exist for the current
// thread. This thread won't be promoted as BrowserThread::UI until
......
......@@ -186,7 +186,6 @@
#include "base/memory/memory_pressure_monitor_win.h"
#include "net/base/winsock_init.h"
#include "services/service_manager/sandbox/win/sandbox_win.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/display/win/screen_win.h"
#endif
......@@ -614,14 +613,6 @@ int BrowserMainLoop::EarlyInitialization() {
#endif // defined(USE_GLIB)
if (parts_) {
#if defined(OS_WIN)
// If we're running tests (ui_task is non-null), then the ResourceBundle
// has already been initialized.
if (!parameters_.ui_task) {
// Override the configured locale with the user's preferred UI language.
l10n_util::OverrideLocaleWithUILanguageList();
}
#endif
const int pre_early_init_error_code = parts_->PreEarlyInitialization();
if (pre_early_init_error_code != service_manager::RESULT_CODE_NORMAL_EXIT)
return pre_early_init_error_code;
......
......@@ -27,10 +27,6 @@ IOSChromeVariationsServiceClient::IOSChromeVariationsServiceClient() {}
IOSChromeVariationsServiceClient::~IOSChromeVariationsServiceClient() {}
std::string IOSChromeVariationsServiceClient::GetApplicationLocale() {
return GetApplicationContext()->GetApplicationLocale();
}
base::Callback<base::Version()>
IOSChromeVariationsServiceClient::GetVersionForSimulationCallback() {
return base::Bind(&GetVersionForSimulation);
......
......@@ -23,7 +23,6 @@ class IOSChromeVariationsServiceClient
private:
// variations::VariationsServiceClient implementation.
std::string GetApplicationLocale() override;
base::Callback<base::Version()> GetVersionForSimulationCallback() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
network_time::NetworkTimeTracker* GetNetworkTimeTracker() override;
......
......@@ -70,7 +70,7 @@ UI_BASE_EXPORT void OverrideLocaleWithUILanguageList();
// Retrieve the locale override, or an empty vector if the locale has not been
// or failed to be overridden.
const std::vector<std::string>& GetLocaleOverrides();
UI_BASE_EXPORT const std::vector<std::string>& GetLocaleOverrides();
} // namespace l10n_util
......
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