OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" | 5 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/common/channel_info.h" | 11 #include "chrome/common/channel_info.h" |
12 #include "components/version_info/version_info.h" | 12 #include "components/version_info/version_info.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 | 14 |
15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
Alexei Svitkine (slow)
2017/06/02 20:56:57
Can some of these includes be removed now that you
nikunjb
2017/06/02 21:31:43
Done. Removed all includes here (none were needed
| |
19 #include "chrome/installer/util/google_update_settings.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
20 #include "chrome/installer/util/install_util.h" | 20 #include "chrome/installer/util/install_util.h" |
21 #include "components/variations/experiment_labels.h" | 21 #include "components/variations/experiment_labels.h" |
22 #endif | 22 #endif |
23 | 23 |
24 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 24 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
25 #include "chrome/browser/upgrade_detector_impl.h" | 25 #include "chrome/browser/upgrade_detector_impl.h" |
26 #endif | 26 #endif |
27 | 27 |
28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
(...skipping 10 matching lines...) Expand all Loading... | |
39 UpgradeDetectorImpl::GetCurrentlyInstalledVersion(); | 39 UpgradeDetectorImpl::GetCurrentlyInstalledVersion(); |
40 if (installed_version.IsValid()) | 40 if (installed_version.IsValid()) |
41 return installed_version; | 41 return installed_version; |
42 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 42 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
43 | 43 |
44 // TODO(asvitkine): Get the version that will be used on restart instead of | 44 // TODO(asvitkine): Get the version that will be used on restart instead of |
45 // the current version on Android, iOS and ChromeOS. | 45 // the current version on Android, iOS and ChromeOS. |
46 return base::Version(version_info::GetVersionNumber()); | 46 return base::Version(version_info::GetVersionNumber()); |
47 } | 47 } |
48 | 48 |
49 #if defined(OS_WIN) | |
50 // Clear all Variations experiment labels from Google Update Registry Labels. | |
51 // TODO(jwd): Remove this once we're confident most clients no longer have these | |
52 // labels (M57-M58 timeframe). | |
53 void ClearGoogleUpdateRegistryLabels() { | |
54 base::ThreadRestrictions::AssertIOAllowed(); | |
55 | |
56 // Note that all registry operations are done here on the UI thread as there | |
57 // are no threading restrictions on them. | |
58 const bool is_system_install = !InstallUtil::IsPerUserInstall(); | |
59 | |
60 // Read the current bits from the registry. | |
61 base::string16 registry_labels; | |
62 bool success = GoogleUpdateSettings::ReadExperimentLabels(is_system_install, | |
63 ®istry_labels); | |
64 | |
65 if (!success) { | |
66 DVLOG(1) << "Error reading Variation labels from the registry."; | |
67 return; | |
68 } | |
69 | |
70 // Only keep the non-Variations contents of experiment_labels. | |
71 const base::string16 labels_to_keep = | |
72 variations::ExtractNonVariationLabels(registry_labels); | |
73 | |
74 // This is a weak check, which can give false positives if the implementation | |
75 // of variations::ExtractNonVariationLabels changes, but should be fine for | |
76 // temporary code. | |
77 bool needs_clearing = labels_to_keep != registry_labels; | |
78 | |
79 UMA_HISTOGRAM_BOOLEAN("Variations.GoogleUpdateRegistryLabelsNeedClearing", | |
80 needs_clearing); | |
81 | |
82 if (!needs_clearing) | |
83 return; | |
84 | |
85 GoogleUpdateSettings::SetExperimentLabels(is_system_install, labels_to_keep); | |
86 } | |
87 #endif // defined(OS_WIN) | |
88 | |
89 } // namespace | 49 } // namespace |
90 | 50 |
91 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {} | 51 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {} |
92 | 52 |
93 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {} | 53 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {} |
94 | 54 |
95 std::string ChromeVariationsServiceClient::GetApplicationLocale() { | 55 std::string ChromeVariationsServiceClient::GetApplicationLocale() { |
96 return g_browser_process->GetApplicationLocale(); | 56 return g_browser_process->GetApplicationLocale(); |
97 } | 57 } |
98 | 58 |
(...skipping 23 matching lines...) Expand all Loading... | |
122 bool ChromeVariationsServiceClient::OverridesRestrictParameter( | 82 bool ChromeVariationsServiceClient::OverridesRestrictParameter( |
123 std::string* parameter) { | 83 std::string* parameter) { |
124 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
125 chromeos::CrosSettings::Get()->GetString( | 85 chromeos::CrosSettings::Get()->GetString( |
126 chromeos::kVariationsRestrictParameter, parameter); | 86 chromeos::kVariationsRestrictParameter, parameter); |
127 return true; | 87 return true; |
128 #else | 88 #else |
129 return false; | 89 return false; |
130 #endif | 90 #endif |
131 } | 91 } |
132 | |
133 void ChromeVariationsServiceClient::OnInitialStartup() { | |
134 #if defined(OS_WIN) | |
135 // TODO(jwd): Remove this once we're confident most clients no longer have | |
136 // these labels (M57-M58 timeframe). | |
137 // Do the work on a blocking pool thread, as chrome://profiler has shown that | |
138 // it can cause jank if done on the UI thrread. | |
139 content::BrowserThread::GetBlockingPool()->PostDelayedTask( | |
140 FROM_HERE, base::Bind(&ClearGoogleUpdateRegistryLabels), | |
141 base::TimeDelta::FromSeconds(5)); | |
142 #endif | |
143 } | |
OLD | NEW |