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 switch (value) { |
| 164 case GoogleUpdateSettings::UPDATES_DISABLED: |
| 165 case GoogleUpdateSettings::AUTOMATIC_UPDATES: |
| 166 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY: |
| 167 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value); |
| 168 return true; |
| 169 default: |
| 170 LOG(WARNING) << "Unexpected update policy override value: " << value; |
| 171 } |
| 172 return false; |
| 173 } |
| 174 |
146 } // namespace | 175 } // namespace |
147 | 176 |
148 // Older versions of Chrome unconditionally read from HKCU\...\ClientState\... | 177 // Older versions of Chrome unconditionally read from HKCU\...\ClientState\... |
149 // and then HKLM\...\ClientState\.... This means that system-level Chrome | 178 // and then HKLM\...\ClientState\.... This means that system-level Chrome |
150 // never checked ClientStateMedium (which has priority according to Google | 179 // never checked ClientStateMedium (which has priority according to Google |
151 // Update) and gave preference to a value in HKCU (which was never checked by | 180 // 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. | 181 // Google Update). From now on, Chrome follows Google Update's policy. |
153 bool GoogleUpdateSettings::GetCollectStatsConsent() { | 182 bool GoogleUpdateSettings::GetCollectStatsConsent() { |
154 // Determine whether this is a system-level or a user-level install. | 183 // Determine whether this is a system-level or a user-level install. |
155 bool system_install = false; | 184 bool system_install = false; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } | 508 } |
480 | 509 |
481 bool GoogleUpdateSettings::IsOrganicFirstRun(const std::wstring& brand) { | 510 bool GoogleUpdateSettings::IsOrganicFirstRun(const std::wstring& brand) { |
482 // Used for testing, to force search engine selector to appear. | 511 // Used for testing, to force search engine selector to appear. |
483 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 512 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
484 if (command_line.HasSwitch(switches::kOrganicInstall)) | 513 if (command_line.HasSwitch(switches::kOrganicInstall)) |
485 return true; | 514 return true; |
486 | 515 |
487 return (StartsWith(brand, L"GG", true) || StartsWith(brand, L"EU", true)); | 516 return (StartsWith(brand, L"GG", true) || StartsWith(brand, L"EU", true)); |
488 } | 517 } |
| 518 |
| 519 GoogleUpdateSettings::UpdatePolicy GoogleUpdateSettings::GetAppUpdatePolicy( |
| 520 const std::wstring& app_guid, |
| 521 bool* is_overridden) { |
| 522 bool found_override = false; |
| 523 UpdatePolicy update_policy = kGoogleUpdateDefaultUpdatePolicy; |
| 524 |
| 525 #if defined(GOOGLE_CHROME_BUILD) |
| 526 DCHECK(!app_guid.empty()); |
| 527 RegKey policy_key; |
| 528 |
| 529 // Google Update Group Policy settings are always in HKLM. |
| 530 if (policy_key.Open(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, |
| 531 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 532 static const size_t kPrefixLen = |
| 533 arraysize(kGoogleUpdateUpdateOverrideValuePrefix) - 1; |
| 534 DWORD value; |
| 535 std::wstring app_update_override; |
| 536 app_update_override.reserve(kPrefixLen + app_guid.size()); |
| 537 app_update_override.append(kGoogleUpdateUpdateOverrideValuePrefix, |
| 538 kPrefixLen); |
| 539 app_update_override.append(app_guid); |
| 540 // First try to read and comprehend the app-specific override. |
| 541 found_override = (policy_key.ReadValueDW(app_update_override.c_str(), |
| 542 &value) == ERROR_SUCCESS && |
| 543 GetUpdatePolicyFromDword(value, &update_policy)); |
| 544 |
| 545 // Failing that, try to read and comprehend the default override. |
| 546 if (!found_override && |
| 547 policy_key.ReadValueDW(kGoogleUpdateUpdatePolicyValue, |
| 548 &value) == ERROR_SUCCESS) { |
| 549 GetUpdatePolicyFromDword(value, &update_policy); |
| 550 } |
| 551 } |
| 552 #endif // defined(GOOGLE_CHROME_BUILD) |
| 553 |
| 554 if (is_overridden != NULL) |
| 555 *is_overridden = found_override; |
| 556 |
| 557 return update_policy; |
| 558 } |
OLD | NEW |