Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/metrics/variations/chrome_variations_service_client.cc

Issue 2465003002: Removing Variations support for google_update_experiment_id. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/channel_info.h" 10 #include "chrome/common/channel_info.h"
11 #include "components/version_info/version_info.h" 11 #include "components/version_info/version_info.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 13
14 #if defined(OS_WIN)
15 #include "base/files/file_path.h"
16 #include "base/metrics/histogram_macros.h"
17 #include "base/path_service.h"
18 #include "base/strings/string16.h"
19 #include "base/threading/thread_restrictions.h"
20 #include "chrome/installer/util/google_update_settings.h"
21 #include "chrome/installer/util/install_util.h"
22 #include "components/variations/experiment_labels.h"
23 #endif
24
14 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 25 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
15 #include "chrome/browser/upgrade_detector_impl.h" 26 #include "chrome/browser/upgrade_detector_impl.h"
16 #endif 27 #endif
17 28
18 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 30 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #endif 31 #endif
21 32
22 namespace { 33 namespace {
23 34
24 // Gets the version number to use for variations seed simulation. Must be called 35 // Gets the version number to use for variations seed simulation. Must be called
25 // on a thread where IO is allowed. 36 // on a thread where IO is allowed.
26 base::Version GetVersionForSimulation() { 37 base::Version GetVersionForSimulation() {
27 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 38 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
28 const base::Version installed_version = 39 const base::Version installed_version =
29 UpgradeDetectorImpl::GetCurrentlyInstalledVersion(); 40 UpgradeDetectorImpl::GetCurrentlyInstalledVersion();
30 if (installed_version.IsValid()) 41 if (installed_version.IsValid())
31 return installed_version; 42 return installed_version;
32 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 43 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
33 44
34 // TODO(asvitkine): Get the version that will be used on restart instead of 45 // TODO(asvitkine): Get the version that will be used on restart instead of
35 // the current version on Android, iOS and ChromeOS. 46 // the current version on Android, iOS and ChromeOS.
36 return base::Version(version_info::GetVersionNumber()); 47 return base::Version(version_info::GetVersionNumber());
37 } 48 }
38 49
50 #if defined(OS_WIN)
51 // Clear all Variations experiment labels from Google Update Registry Labels.
52 // TODO(jwd): Remove this once we're confident most clients no longer have these
53 // labels (M57-M58 timeframe).
54 void ClearGoogleUpdateRegistryLabels() {
55 base::ThreadRestrictions::AssertIOAllowed();
56
57 // Note that all registry operations are done here on the UI thread as there
58 // are no threading restrictions on them.
59 base::FilePath chrome_exe;
60 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
61 NOTREACHED() << "Failed to get chrome exe path";
62 return;
63 }
64 const bool is_system_install = !InstallUtil::IsPerUserInstall(chrome_exe);
65
66 // Read the current bits from the registry.
67 base::string16 registry_labels;
68 bool success = GoogleUpdateSettings::ReadExperimentLabels(is_system_install,
69 &registry_labels);
70
71 if (!success) {
72 DVLOG(1) << "Error reading Variation labels from the registry.";
73 return;
74 }
75
76 // Only keep the non-Variations contents of experiment_labels.
77 const base::string16 labels_to_keep =
78 variations::ExtractNonVariationLabels(registry_labels);
79
80 // This is a weak check, which can give false positives if the implementation
81 // of variations::ExtractNonVariationLabels changes, but should be fine for
82 // temporary code.
83 bool needs_clearing = labels_to_keep != registry_labels;
84
85 UMA_HISTOGRAM_BOOLEAN("Variations.GoogleUpdateRegistryLabelsNeedClearing",
86 needs_clearing);
87
88 if (!needs_clearing)
89 return;
90
91 GoogleUpdateSettings::SetExperimentLabels(is_system_install, labels_to_keep);
92 }
93 #endif // defined(OS_WIN)
94
39 } // namespace 95 } // namespace
40 96
41 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {} 97 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {}
42 98
43 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {} 99 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {}
44 100
45 std::string ChromeVariationsServiceClient::GetApplicationLocale() { 101 std::string ChromeVariationsServiceClient::GetApplicationLocale() {
46 return g_browser_process->GetApplicationLocale(); 102 return g_browser_process->GetApplicationLocale();
47 } 103 }
48 104
(...skipping 26 matching lines...) Expand all
75 chromeos::CrosSettings::Get()->GetString( 131 chromeos::CrosSettings::Get()->GetString(
76 chromeos::kVariationsRestrictParameter, parameter); 132 chromeos::kVariationsRestrictParameter, parameter);
77 return true; 133 return true;
78 #else 134 #else
79 return false; 135 return false;
80 #endif 136 #endif
81 } 137 }
82 138
83 void ChromeVariationsServiceClient::OnInitialStartup() { 139 void ChromeVariationsServiceClient::OnInitialStartup() {
84 #if defined(OS_WIN) 140 #if defined(OS_WIN)
85 StartGoogleUpdateRegistrySync(); 141 // TODO(jwd): Remove this once we're confident most clients no longer have
142 // these labels (M57-M58 timeframe).
143 // Do the work on a blocking pool thread, as chrome://profiler has shown that
144 // it can cause jank if done on the UI thrread.
145 content::BrowserThread::GetBlockingPool()->PostTask(
146 FROM_HERE, base::Bind(&ClearGoogleUpdateRegistryLabels));
Alexei Svitkine (slow) 2016/11/03 17:09:36 Previously, it would be started with a delay. Can
jwd 2016/11/04 15:05:15 Done.
86 #endif 147 #endif
87 } 148 }
88
89 #if defined(OS_WIN)
90 void ChromeVariationsServiceClient::StartGoogleUpdateRegistrySync() {
91 registry_syncer_.RequestRegistrySync();
92 }
93 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698