1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/metrics/variations/generated_resources_map.h"
10 #include "chrome/common/channel_info.h"
11 #include "components/version_info/version_info.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "ui/base/resource/resource_bundle.h"
15 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
16 #include "chrome/browser/upgrade_detector_impl.h"
19 #if defined(OS_CHROMEOS)
20 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 // Gets the version number to use for variations seed simulation. Must be called
26 // on a thread where IO is allowed.
27 base::Version
GetVersionForSimulation() {
28 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
29 const base::Version installed_version
=
30 UpgradeDetectorImpl::GetCurrentlyInstalledVersion();
31 if (installed_version
.IsValid())
32 return installed_version
;
33 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
35 // TODO(asvitkine): Get the version that will be used on restart instead of
36 // the current version on Android, iOS and ChromeOS.
37 return base::Version(version_info::GetVersionNumber());
42 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {}
44 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {}
46 std::string
ChromeVariationsServiceClient::GetApplicationLocale() {
47 return g_browser_process
->GetApplicationLocale();
50 base::SequencedWorkerPool
* ChromeVariationsServiceClient::GetBlockingPool() {
51 return content::BrowserThread::GetBlockingPool();
54 base::Callback
<base::Version(void)>
55 ChromeVariationsServiceClient::GetVersionForSimulationCallback() {
56 return base::Bind(&GetVersionForSimulation
);
59 net::URLRequestContextGetter
*
60 ChromeVariationsServiceClient::GetURLRequestContext() {
61 return g_browser_process
->system_request_context();
64 network_time::NetworkTimeTracker
*
65 ChromeVariationsServiceClient::GetNetworkTimeTracker() {
66 return g_browser_process
->network_time_tracker();
69 version_info::Channel
ChromeVariationsServiceClient::GetChannel() {
70 return chrome::GetChannel();
73 bool ChromeVariationsServiceClient::OverridesRestrictParameter(
74 std::string
* parameter
) {
75 #if defined(OS_CHROMEOS)
76 chromeos::CrosSettings::Get()->GetString(
77 chromeos::kVariationsRestrictParameter
, parameter
);
84 void ChromeVariationsServiceClient::OverrideUIString(
86 const base::string16
& string
) {
87 int resource_id
= chrome_variations::GetResourceIndex(hash
);
88 if (resource_id
== -1)
91 ui::ResourceBundle::GetSharedInstance().OverrideLocaleStringResource(
95 void ChromeVariationsServiceClient::OnInitialStartup() {
97 StartGoogleUpdateRegistrySync();
102 void ChromeVariationsServiceClient::StartGoogleUpdateRegistrySync() {
103 registry_syncer_
.RequestRegistrySync();