diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 15:23:58 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 15:23:58 +0000 |
commit | ca1abf67762946dca6b8988a16d027b650c9042e (patch) | |
tree | 87880e8e87c7ece51a08649c9c7d14b498335549 /chrome/installer/util/google_update_settings.cc | |
parent | 3daf923017ac77b354513b53259e80b4fb2a609d (diff) | |
download | chromium_src-ca1abf67762946dca6b8988a16d027b650c9042e.zip chromium_src-ca1abf67762946dca6b8988a16d027b650c9042e.tar.gz chromium_src-ca1abf67762946dca6b8988a16d027b650c9042e.tar.bz2 |
Control crash reporting and UMA collection in multi-install via a value in the multi-install binaries' ClientState{Medium} key.
BUG=none
TEST=Confirm no substantive change in single-install Chrome. In multi-install, usagestats should be in the ClientState\{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D} and/or ClientStateMedium\{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D} key. Enabling/disabling usage stats for multi-install Chrome (via Under the Hood) should control crash reports and UMA for multi-install Chrome Frame.
Review URL: http://codereview.chromium.org/6936001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84250 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/util/google_update_settings.cc')
-rw-r--r-- | chrome/installer/util/google_update_settings.cc | 96 |
1 files changed, 78 insertions, 18 deletions
diff --git a/chrome/installer/util/google_update_settings.cc b/chrome/installer/util/google_update_settings.cc index 2b6b8ea..702eabb 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -7,6 +7,7 @@ #include <algorithm> #include "base/command_line.h" +#include "base/path_service.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/threading/thread_restrictions.h" @@ -123,31 +124,90 @@ bool GetChromeChannelInternal(bool system_install, } // namespace +// Older versions of Chrome unconditionally read from HKCU\...\ClientState\... +// and then HKLM\...\ClientState\.... This means that system-level Chrome +// never checked ClientStateMedium (which has priority according to Google +// Update) and gave preference to a value in HKCU (which was never checked by +// Google Update). From now on, Chrome follows Google Update's policy. bool GoogleUpdateSettings::GetCollectStatsConsent() { + // Determine whether this is a system-level or a user-level install. + bool system_install = false; + FilePath module_dir; + if (!PathService::Get(base::DIR_MODULE, &module_dir)) { + LOG(WARNING) + << "Failed to get directory of module; assuming per-user install."; + } else { + system_install = !InstallUtil::IsPerUserInstall(module_dir.value().c_str()); + } BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - std::wstring reg_path = dist->GetStateKey(); - RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); - DWORD value = 0; - if (key.ReadValueDW(google_update::kRegUsageStatsField, &value) != - ERROR_SUCCESS) { - key.Open(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); - key.ReadValueDW(google_update::kRegUsageStatsField, &value); + + // Consent applies to all products in a multi-install package. + if (InstallUtil::IsMultiInstall(dist, system_install)) { + dist = BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BINARIES); } - return (1 == value); + + RegKey key; + DWORD value = 0; + bool have_value = false; + + // For system-level installs, try ClientStateMedium first. + have_value = + system_install && + key.Open(HKEY_LOCAL_MACHINE, dist->GetStateMediumKey().c_str(), + KEY_QUERY_VALUE) == ERROR_SUCCESS && + key.ReadValueDW(google_update::kRegUsageStatsField, + &value) == ERROR_SUCCESS; + + // Otherwise, try ClientState. + have_value = + !have_value && + key.Open(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, + dist->GetStateKey().c_str(), KEY_QUERY_VALUE) == ERROR_SUCCESS && + key.ReadValueDW(google_update::kRegUsageStatsField, + &value) == ERROR_SUCCESS; + + // Google Update specifically checks that the value is 1, so we do the same. + return have_value && value == 1; } bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { - DWORD value = consented? 1 : 0; - // Writing to HKLM is only a best effort deal. + // Google Update writes and expects 1 for true, 0 for false. + DWORD value = consented ? 1 : 0; + + // Determine whether this is a system-level or a user-level install. + bool system_install = false; + FilePath module_dir; + if (!PathService::Get(base::DIR_MODULE, &module_dir)) { + LOG(WARNING) + << "Failed to get directory of module; assuming per-user install."; + } else { + system_install = !InstallUtil::IsPerUserInstall(module_dir.value().c_str()); + } BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - std::wstring reg_path = dist->GetStateMediumKey(); - RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WRITE); - key.WriteValue(google_update::kRegUsageStatsField, value); - // Writing to HKCU is used both by chrome and by the crash reporter. - reg_path = dist->GetStateKey(); - key.Create(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); - return (key.WriteValue(google_update::kRegUsageStatsField, value) == - ERROR_SUCCESS); + + // Consent applies to all products in a multi-install package. + if (InstallUtil::IsMultiInstall(dist, system_install)) { + dist = BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BINARIES); + } + + // Write to ClientStateMedium for system-level; ClientState otherwise. + HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + std::wstring reg_path = + system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); + RegKey key; + LONG result = key.Create(root_key, reg_path.c_str(), KEY_SET_VALUE); + if (result != ERROR_SUCCESS) { + LOG(ERROR) << "Failed opening key " << reg_path << " to set " + << google_update::kRegUsageStatsField << "; result: " << result; + } else { + result = key.WriteValue(google_update::kRegUsageStatsField, value); + LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " + << google_update::kRegUsageStatsField << " in key " << reg_path + << "; result: " << result; + } + return (result == ERROR_SUCCESS); } bool GoogleUpdateSettings::GetMetricsId(std::wstring* metrics_id) { |