Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/installer/util/google_update_settings.h" | 5 #include "chrome/installer/util/google_update_settings.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/installer/util/browser_distribution.h" | 17 #include "chrome/installer/util/browser_distribution.h" |
| 18 #include "chrome/installer/util/channel_info.h" | 18 #include "chrome/installer/util/channel_info.h" |
| 19 #include "chrome/installer/util/google_update_constants.h" | 19 #include "chrome/installer/util/google_update_constants.h" |
| 20 #include "chrome/installer/util/install_util.h" | 20 #include "chrome/installer/util/install_util.h" |
| 21 #include "chrome/installer/util/installer_state.h" | 21 #include "chrome/installer/util/installer_state.h" |
| 22 #include "chrome/installer/util/product.h" | 22 #include "chrome/installer/util/product.h" |
| 23 | 23 |
| 24 using base::win::RegKey; | 24 using base::win::RegKey; |
| 25 using installer::InstallerState; | 25 using installer::InstallerState; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const wchar_t kGoogleUpdatePoliciesKey[] = | |
| 30 L"SOFTWARE\\Policies\\Google\\Update"; | |
| 31 const wchar_t kGoogleUpdateUpdatePolicyValue[] = L"UpdateDefault"; | |
| 32 const wchar_t kGoogleUpdateUpdateOverrideValuePrefix[] = L"Update"; | |
| 33 const GoogleUpdateSettings::UpdatePolicy kGoogleUpdateDefaultUpdatePolicy = | |
| 34 #if defined(GOOGLE_CHROME_BUILD) | |
| 35 GoogleUpdateSettings::AUTOMATIC_UPDATES; | |
| 36 #else | |
| 37 GoogleUpdateSettings::UPDATES_DISABLED; | |
| 38 #endif | |
| 39 | |
| 29 // An list of search results in increasing order of desirability. | 40 // An list of search results in increasing order of desirability. |
| 30 enum EulaSearchResult { | 41 enum EulaSearchResult { |
| 31 NO_SETTING, | 42 NO_SETTING, |
| 32 FOUND_CLIENT_STATE, | 43 FOUND_CLIENT_STATE, |
| 33 FOUND_OPPOSITE_SETTING, | 44 FOUND_OPPOSITE_SETTING, |
| 34 FOUND_SAME_SETTING | 45 FOUND_SAME_SETTING |
| 35 }; | 46 }; |
| 36 | 47 |
| 37 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { | 48 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { |
| 38 // The registry functions below will end up going to disk. Do this on another | 49 // The registry functions below will end up going to disk. Do this on another |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 if (add_multi_modifier && channel_info.IsMultiInstall()) { | 147 if (add_multi_modifier && channel_info.IsMultiInstall()) { |
| 137 if (!channel->empty()) { | 148 if (!channel->empty()) { |
| 138 channel->append(1, L'-'); | 149 channel->append(1, L'-'); |
| 139 } | 150 } |
| 140 channel->append(1, L'm'); | 151 channel->append(1, L'm'); |
| 141 } | 152 } |
| 142 | 153 |
| 143 return true; | 154 return true; |
| 144 } | 155 } |
| 145 | 156 |
| 157 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a | |
| 158 // DWORD read from the registry and returns true if |value| is within range. | |
| 159 // If |value| is out of range, returns false without modifying |update_policy|. | |
| 160 bool GetUpdatePolicyFromDword( | |
| 161 const DWORD value, | |
| 162 GoogleUpdateSettings::UpdatePolicy* update_policy) { | |
| 163 COMPILE_ASSERT(GoogleUpdateSettings::UPDATES_DISABLED == 0, | |
| 164 dont_reorder_GoogleUpdateSettings_UpdatePolicy); | |
| 165 COMPILE_ASSERT(GoogleUpdateSettings::AUTOMATIC_UPDATES == 1, | |
| 166 dont_reorder_GoogleUpdateSettings_UpdatePolicy); | |
| 167 COMPILE_ASSERT(GoogleUpdateSettings::MANUAL_UPDATES_ONLY == 2, | |
| 168 dont_reorder_GoogleUpdateSettings_UpdatePolicy); | |
|
robertshield
2011/06/08 16:06:52
Can these asserts go near the enum declaration? I
grt (UTC plus 2)
2011/06/08 16:31:32
Done.
| |
| 169 switch (value) { | |
| 170 case GoogleUpdateSettings::UPDATES_DISABLED: | |
| 171 case GoogleUpdateSettings::AUTOMATIC_UPDATES: | |
| 172 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY: | |
| 173 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value); | |
| 174 return true; | |
| 175 default: | |
| 176 LOG(WARNING) << "Unexpected update policy override value: " << value; | |
| 177 } | |
| 178 return false; | |
| 179 } | |
| 180 | |
| 146 } // namespace | 181 } // namespace |
| 147 | 182 |
| 148 // Older versions of Chrome unconditionally read from HKCU\...\ClientState\... | 183 // Older versions of Chrome unconditionally read from HKCU\...\ClientState\... |
| 149 // and then HKLM\...\ClientState\.... This means that system-level Chrome | 184 // and then HKLM\...\ClientState\.... This means that system-level Chrome |
| 150 // never checked ClientStateMedium (which has priority according to Google | 185 // never checked ClientStateMedium (which has priority according to Google |
| 151 // Update) and gave preference to a value in HKCU (which was never checked by | 186 // Update) and gave preference to a value in HKCU (which was never checked by |
| 152 // Google Update). From now on, Chrome follows Google Update's policy. | 187 // Google Update). From now on, Chrome follows Google Update's policy. |
| 153 bool GoogleUpdateSettings::GetCollectStatsConsent() { | 188 bool GoogleUpdateSettings::GetCollectStatsConsent() { |
| 154 // Determine whether this is a system-level or a user-level install. | 189 // Determine whether this is a system-level or a user-level install. |
| 155 bool system_install = false; | 190 bool system_install = false; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 } | 514 } |
| 480 | 515 |
| 481 bool GoogleUpdateSettings::IsOrganicFirstRun(const std::wstring& brand) { | 516 bool GoogleUpdateSettings::IsOrganicFirstRun(const std::wstring& brand) { |
| 482 // Used for testing, to force search engine selector to appear. | 517 // Used for testing, to force search engine selector to appear. |
| 483 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 518 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 484 if (command_line.HasSwitch(switches::kOrganicInstall)) | 519 if (command_line.HasSwitch(switches::kOrganicInstall)) |
| 485 return true; | 520 return true; |
| 486 | 521 |
| 487 return (StartsWith(brand, L"GG", true) || StartsWith(brand, L"EU", true)); | 522 return (StartsWith(brand, L"GG", true) || StartsWith(brand, L"EU", true)); |
| 488 } | 523 } |
| 524 | |
| 525 GoogleUpdateSettings::UpdatePolicy GoogleUpdateSettings::GetAppUpdatePolicy( | |
| 526 const std::wstring& app_guid, | |
| 527 bool* is_overridden) { | |
| 528 bool found_override = false; | |
| 529 UpdatePolicy update_policy = kGoogleUpdateDefaultUpdatePolicy; | |
| 530 | |
| 531 #if defined(GOOGLE_CHROME_BUILD) | |
| 532 DCHECK(!app_guid.empty()); | |
| 533 RegKey policy_key; | |
| 534 | |
| 535 // Google Update Group Policy settings are always in HKLM. | |
| 536 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, | |
| 537 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | |
| 538 static const size_t kPrefixLen = | |
| 539 arraysize(kGoogleUpdateUpdateOverrideValuePrefix) - 1; | |
| 540 DWORD value; | |
| 541 std::wstring app_update_override; | |
| 542 app_update_override.reserve(kPrefixLen + app_guid.size()); | |
| 543 app_update_override.append(kGoogleUpdateUpdateOverrideValuePrefix, | |
| 544 kPrefixLen); | |
| 545 app_update_override.append(app_guid); | |
| 546 // First try to read and comprehend the app-specific override. | |
| 547 found_override = (policy_key.ReadValueDW(app_update_override.c_str(), | |
| 548 &value) == ERROR_SUCCESS && | |
| 549 GetUpdatePolicyFromDword(value, &update_policy)); | |
| 550 | |
| 551 // Failing that, try to read and comprehend the default override. | |
| 552 if (!found_override && | |
| 553 policy_key.ReadValueDW(kGoogleUpdateUpdatePolicyValue, | |
| 554 &value) == ERROR_SUCCESS) { | |
| 555 GetUpdatePolicyFromDword(value, &update_policy); | |
| 556 } | |
| 557 } | |
| 558 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 559 | |
| 560 if (is_overridden != NULL) | |
| 561 *is_overridden = found_override; | |
| 562 | |
| 563 return update_policy; | |
| 564 } | |
| OLD | NEW |