| 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) | |
| 16 #include "base/metrics/histogram_macros.h" | |
| 17 #include "base/strings/string16.h" | |
| 18 #include "base/threading/thread_restrictions.h" | |
| 19 #include "chrome/installer/util/google_update_settings.h" | |
| 20 #include "chrome/installer/util/install_util.h" | |
| 21 #include "components/variations/experiment_labels.h" | |
| 22 #endif | |
| 23 | |
| 24 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 15 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 25 #include "chrome/browser/upgrade_detector_impl.h" | 16 #include "chrome/browser/upgrade_detector_impl.h" |
| 26 #endif | 17 #endif |
| 27 | 18 |
| 28 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 30 #endif | 21 #endif |
| 31 | 22 |
| 32 namespace { | 23 namespace { |
| 33 | 24 |
| 34 // Gets the version number to use for variations seed simulation. Must be called | 25 // Gets the version number to use for variations seed simulation. Must be called |
| 35 // on a thread where IO is allowed. | 26 // on a thread where IO is allowed. |
| 36 base::Version GetVersionForSimulation() { | 27 base::Version GetVersionForSimulation() { |
| 37 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 28 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 38 const base::Version installed_version = | 29 const base::Version installed_version = |
| 39 UpgradeDetectorImpl::GetCurrentlyInstalledVersion(); | 30 UpgradeDetectorImpl::GetCurrentlyInstalledVersion(); |
| 40 if (installed_version.IsValid()) | 31 if (installed_version.IsValid()) |
| 41 return installed_version; | 32 return installed_version; |
| 42 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 33 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 43 | 34 |
| 44 // TODO(asvitkine): Get the version that will be used on restart instead of | 35 // TODO(asvitkine): Get the version that will be used on restart instead of |
| 45 // the current version on Android, iOS and ChromeOS. | 36 // the current version on Android, iOS and ChromeOS. |
| 46 return base::Version(version_info::GetVersionNumber()); | 37 return base::Version(version_info::GetVersionNumber()); |
| 47 } | 38 } |
| 48 | 39 |
| 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 | 40 } // namespace |
| 90 | 41 |
| 91 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {} | 42 ChromeVariationsServiceClient::ChromeVariationsServiceClient() {} |
| 92 | 43 |
| 93 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {} | 44 ChromeVariationsServiceClient::~ChromeVariationsServiceClient() {} |
| 94 | 45 |
| 95 std::string ChromeVariationsServiceClient::GetApplicationLocale() { | 46 std::string ChromeVariationsServiceClient::GetApplicationLocale() { |
| 96 return g_browser_process->GetApplicationLocale(); | 47 return g_browser_process->GetApplicationLocale(); |
| 97 } | 48 } |
| 98 | 49 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 122 bool ChromeVariationsServiceClient::OverridesRestrictParameter( | 73 bool ChromeVariationsServiceClient::OverridesRestrictParameter( |
| 123 std::string* parameter) { | 74 std::string* parameter) { |
| 124 #if defined(OS_CHROMEOS) | 75 #if defined(OS_CHROMEOS) |
| 125 chromeos::CrosSettings::Get()->GetString( | 76 chromeos::CrosSettings::Get()->GetString( |
| 126 chromeos::kVariationsRestrictParameter, parameter); | 77 chromeos::kVariationsRestrictParameter, parameter); |
| 127 return true; | 78 return true; |
| 128 #else | 79 #else |
| 129 return false; | 80 return false; |
| 130 #endif | 81 #endif |
| 131 } | 82 } |
| 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 |