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

Side by Side Diff: chrome/installer/util/google_update_settings.cc

Issue 2619323003: Remove uses of BrowserDistribution::CHROME_BINARIES in installer_util. (Closed)
Patch Set: sync to position 442533 Created 3 years, 11 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits>
11 #include <vector>
12 10
13 #include "base/command_line.h" 11 #include "base/command_line.h"
14 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
15 #include "base/logging.h" 13 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
17 #include "base/numerics/safe_conversions.h" 15 #include "base/numerics/safe_conversions.h"
18 #include "base/path_service.h" 16 #include "base/path_service.h"
19 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 147 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
150 base::string16 reg_path = dist->GetStateKey(); 148 base::string16 reg_path = dist->GetStateKey();
151 RegKey key(HKEY_CURRENT_USER, 149 RegKey key(HKEY_CURRENT_USER,
152 reg_path.c_str(), 150 reg_path.c_str(),
153 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY); 151 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY);
154 if (!key.HasValue(name)) 152 if (!key.HasValue(name))
155 return true; 153 return true;
156 return (key.DeleteValue(name) == ERROR_SUCCESS); 154 return (key.DeleteValue(name) == ERROR_SUCCESS);
157 } 155 }
158 156
159 // Initializes |channel_info| based on |system_install| and |dist|. Also 157 // Initializes |channel_info| based on |system_install|. Returns false on
160 // returns whether the install is a multi-install via output parameter 158 // failure.
161 // |is_multi_install|. Returns false on failure.
162 bool InitChannelInfo(bool system_install, 159 bool InitChannelInfo(bool system_install,
163 installer::ChannelInfo* channel_info, 160 installer::ChannelInfo* channel_info) {
164 bool* is_multi_install) { 161 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
165 // Determine whether or not chrome is multi-install. If so, updates are 162 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
166 // delivered under the binaries' app guid, so that's where the relevant 163 RegKey key(root_key, dist->GetStateKey().c_str(),
167 // channel is found. 164 KEY_QUERY_VALUE | KEY_WOW64_32KEY);
168 installer::ProductState state; 165 return channel_info->Initialize(key);
169 ignore_result(state.Initialize(system_install));
170 if (!state.is_multi_install()) {
171 // Use the channel info that was just read for this single-install chrome.
172 *channel_info = state.channel();
173 } else {
174 // Read the channel info from the binaries' state key.
175 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
176 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
177 BrowserDistribution::CHROME_BINARIES);
178 RegKey key(root_key, dist->GetStateKey().c_str(),
179 KEY_READ | KEY_WOW64_32KEY);
180
181 if (!channel_info->Initialize(key))
182 return false;
183 }
184 *is_multi_install = state.is_multi_install();
185 return true;
186 } 166 }
187 167
188 bool GetChromeChannelInternal(bool system_install, 168 bool GetChromeChannelInternal(bool system_install,
189 bool add_multi_modifier,
190 base::string16* channel) { 169 base::string16* channel) {
191 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
192
193 // Shortcut in case this distribution knows what channel it is (canary). 170 // Shortcut in case this distribution knows what channel it is (canary).
194 if (dist->GetChromeChannel(channel)) 171 if (BrowserDistribution::GetDistribution()->GetChromeChannel(channel))
195 return true; 172 return true;
196 173
197 installer::ChannelInfo channel_info; 174 installer::ChannelInfo channel_info;
198 bool is_multi_install = false; 175 if (!InitChannelInfo(system_install, &channel_info)) {
199 if (!InitChannelInfo(system_install, &channel_info, &is_multi_install)) {
200 channel->assign(installer::kChromeChannelUnknown); 176 channel->assign(installer::kChromeChannelUnknown);
201 return false; 177 return false;
202 } 178 }
203 179
204 if (!channel_info.GetChannelName(channel)) 180 if (!channel_info.GetChannelName(channel))
205 channel->assign(installer::kChromeChannelUnknown); 181 channel->assign(installer::kChromeChannelUnknown);
206 182
207 // Tag the channel name if this is a multi-install.
208 if (add_multi_modifier && is_multi_install) {
209 if (!channel->empty())
210 channel->push_back(L'-');
211 channel->push_back(L'm');
212 }
213
214 return true; 183 return true;
215 } 184 }
216 185
217 #if defined(GOOGLE_CHROME_BUILD) 186 #if defined(GOOGLE_CHROME_BUILD)
218 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a 187 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a
219 // DWORD read from the registry and returns true if |value| is within range. 188 // DWORD read from the registry and returns true if |value| is within range.
220 // If |value| is out of range, returns false without modifying |update_policy|. 189 // If |value| is out of range, returns false without modifying |update_policy|.
221 bool GetUpdatePolicyFromDword( 190 bool GetUpdatePolicyFromDword(
222 const DWORD value, 191 const DWORD value,
223 GoogleUpdateSettings::UpdatePolicy* update_policy) { 192 GoogleUpdateSettings::UpdatePolicy* update_policy) {
224 switch (value) { 193 switch (value) {
225 case GoogleUpdateSettings::UPDATES_DISABLED: 194 case GoogleUpdateSettings::UPDATES_DISABLED:
226 case GoogleUpdateSettings::AUTOMATIC_UPDATES: 195 case GoogleUpdateSettings::AUTOMATIC_UPDATES:
227 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY: 196 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY:
228 case GoogleUpdateSettings::AUTO_UPDATES_ONLY: 197 case GoogleUpdateSettings::AUTO_UPDATES_ONLY:
229 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value); 198 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value);
230 return true; 199 return true;
231 default: 200 default:
232 LOG(WARNING) << "Unexpected update policy override value: " << value; 201 LOG(WARNING) << "Unexpected update policy override value: " << value;
233 } 202 }
234 return false; 203 return false;
235 } 204 }
236 #endif // defined(GOOGLE_CHROME_BUILD) 205 #endif // defined(GOOGLE_CHROME_BUILD)
237 206
238 bool UpdateDidRunStateForApp(const AppRegistrationData& app_reg_data,
239 bool did_run) {
240 return WriteGoogleUpdateStrKeyInternal(
241 app_reg_data, google_update::kRegDidRunField, did_run ? L"1" : L"0");
242 }
243
244 // Convenience routine: GoogleUpdateSettings::UpdateDidRunStateForApp()
245 // specialized for Chrome Binaries.
246 bool UpdateDidRunStateForBinaries(bool did_run) {
247 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
248 BrowserDistribution::CHROME_BINARIES);
249 return UpdateDidRunStateForApp(dist->GetAppRegistrationData(), did_run);
250 }
251
252 } // namespace 207 } // namespace
253 208
254 bool GoogleUpdateSettings::IsSystemInstall() { 209 bool GoogleUpdateSettings::IsSystemInstall() {
255 bool system_install = false; 210 bool system_install = false;
256 base::FilePath module_dir; 211 base::FilePath module_dir;
257 if (!PathService::Get(base::DIR_MODULE, &module_dir)) { 212 if (!PathService::Get(base::DIR_MODULE, &module_dir)) {
258 LOG(WARNING) 213 LOG(WARNING)
259 << "Failed to get directory of module; assuming per-user install."; 214 << "Failed to get directory of module; assuming per-user install.";
260 } else { 215 } else {
261 system_install = !InstallUtil::IsPerUserInstall(module_dir); 216 system_install = !InstallUtil::IsPerUserInstall(module_dir);
262 } 217 }
263 return system_install; 218 return system_install;
264 } 219 }
265 220
266 bool GoogleUpdateSettings::GetCollectStatsConsent() { 221 bool GoogleUpdateSettings::GetCollectStatsConsent() {
267 return GetCollectStatsConsentAtLevel(IsSystemInstall()); 222 return GetCollectStatsConsentAtLevel(IsSystemInstall());
268 } 223 }
269 224
270 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { 225 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
271 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented); 226 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented);
272 } 227 }
273 228
274 bool GoogleUpdateSettings::GetCollectStatsConsentAtLevel(bool system_install) { 229 bool GoogleUpdateSettings::GetCollectStatsConsentAtLevel(bool system_install) {
275 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
276
277 // Consent applies to all products in a multi-install package.
278 if (InstallUtil::IsMultiInstall(system_install)) {
279 dist = BrowserDistribution::GetSpecificDistribution(
280 BrowserDistribution::CHROME_BINARIES);
281 }
282
283 return GetCollectStatsConsentForApp(system_install, 230 return GetCollectStatsConsentForApp(system_install,
284 dist->GetAppRegistrationData()) == 231 BrowserDistribution::GetDistribution()
232 ->GetAppRegistrationData()) ==
285 google_update::TRISTATE_TRUE; 233 google_update::TRISTATE_TRUE;
286 } 234 }
287 235
288 google_update::Tristate GoogleUpdateSettings::GetCollectStatsConsentForApp( 236 google_update::Tristate GoogleUpdateSettings::GetCollectStatsConsentForApp(
289 bool system_install, 237 bool system_install,
290 const AppRegistrationData& reg_data) { 238 const AppRegistrationData& reg_data) {
291 RegKey key; 239 RegKey key;
292 DWORD value = google_update::TRISTATE_NONE; 240 DWORD value = google_update::TRISTATE_NONE;
293 bool have_value = false; 241 bool have_value = false;
294 const REGSAM kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY; 242 const REGSAM kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY;
(...skipping 20 matching lines...) Expand all
315 263
316 return value == google_update::TRISTATE_TRUE ? google_update::TRISTATE_TRUE 264 return value == google_update::TRISTATE_TRUE ? google_update::TRISTATE_TRUE
317 : google_update::TRISTATE_FALSE; 265 : google_update::TRISTATE_FALSE;
318 } 266 }
319 267
320 // static 268 // static
321 bool GoogleUpdateSettings::SetCollectStatsConsentAtLevel(bool system_install, 269 bool GoogleUpdateSettings::SetCollectStatsConsentAtLevel(bool system_install,
322 bool consented) { 270 bool consented) {
323 DWORD value = 271 DWORD value =
324 consented ? google_update::TRISTATE_TRUE : google_update::TRISTATE_FALSE; 272 consented ? google_update::TRISTATE_TRUE : google_update::TRISTATE_FALSE;
325
326 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 273 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
327 274
328 // Consent applies to all products in a multi-install package.
329 if (InstallUtil::IsMultiInstall(system_install)) {
330 dist = BrowserDistribution::GetSpecificDistribution(
331 BrowserDistribution::CHROME_BINARIES);
332 }
333
334 // Write to ClientStateMedium for system-level; ClientState otherwise. 275 // Write to ClientStateMedium for system-level; ClientState otherwise.
335 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 276 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
336 base::string16 reg_path = 277 base::string16 reg_path =
337 system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); 278 system_install ? dist->GetStateMediumKey() : dist->GetStateKey();
338 RegKey key; 279 RegKey key;
339 LONG result = key.Create( 280 LONG result = key.Create(
340 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); 281 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY);
341 if (result != ERROR_SUCCESS) { 282 if (result != ERROR_SUCCESS) {
342 LOG(ERROR) << "Failed opening key " << reg_path << " to set " 283 LOG(ERROR) << "Failed opening key " << reg_path << " to set "
343 << google_update::kRegUsageStatsField << "; result: " << result; 284 << google_update::kRegUsageStatsField << "; result: " << result;
344 } else { 285 } else {
345 result = key.WriteValue(google_update::kRegUsageStatsField, value); 286 result = key.WriteValue(google_update::kRegUsageStatsField, value);
346 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " 287 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting "
347 << google_update::kRegUsageStatsField << " in key " << reg_path 288 << google_update::kRegUsageStatsField << " in key " << reg_path
348 << "; result: " << result; 289 << "; result: " << result;
349 } 290 }
350 291
351 // When opting out, clear registry backup of client id and related values. 292 // When opting out, clear registry backup of client id and related values.
352 if (result == ERROR_SUCCESS && !consented) 293 if (result == ERROR_SUCCESS && !consented)
353 StoreMetricsClientInfo(metrics::ClientInfo()); 294 StoreMetricsClientInfo(metrics::ClientInfo());
354 295
355 return (result == ERROR_SUCCESS); 296 return (result == ERROR_SUCCESS);
356 } 297 }
357 298
358 // static 299 // static
359 bool GoogleUpdateSettings::GetCollectStatsConsentDefault( 300 bool GoogleUpdateSettings::GetCollectStatsConsentDefault(
360 bool* stats_consent_default) { 301 bool* stats_consent_default) {
361 installer::ChannelInfo channel_info; 302 installer::ChannelInfo channel_info;
362 bool is_multi_install = false; 303 if (InitChannelInfo(IsSystemInstall(), &channel_info)) {
363 if (InitChannelInfo(IsSystemInstall(), &channel_info, &is_multi_install)) {
364 base::string16 stats_default = channel_info.GetStatsDefault(); 304 base::string16 stats_default = channel_info.GetStatsDefault();
365 if (stats_default == L"0" || stats_default == L"1") { 305 if (stats_default == L"0" || stats_default == L"1") {
366 *stats_consent_default = (stats_default == L"1"); 306 *stats_consent_default = (stats_default == L"1");
367 return true; 307 return true;
368 } 308 }
369 } 309 }
370 return false; 310 return false;
371 } 311 }
372 312
373 std::unique_ptr<metrics::ClientInfo> 313 std::unique_ptr<metrics::ClientInfo>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 415 }
476 416
477 bool GoogleUpdateSettings::GetReferral(base::string16* referral) { 417 bool GoogleUpdateSettings::GetReferral(base::string16* referral) {
478 return ReadGoogleUpdateStrKey(google_update::kRegReferralField, referral); 418 return ReadGoogleUpdateStrKey(google_update::kRegReferralField, referral);
479 } 419 }
480 420
481 bool GoogleUpdateSettings::ClearReferral() { 421 bool GoogleUpdateSettings::ClearReferral() {
482 return ClearGoogleUpdateStrKey(google_update::kRegReferralField); 422 return ClearGoogleUpdateStrKey(google_update::kRegReferralField);
483 } 423 }
484 424
485 bool GoogleUpdateSettings::UpdateDidRunState(bool did_run, bool system_level) { 425 bool GoogleUpdateSettings::UpdateDidRunState(bool did_run) {
486 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 426 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
487 bool result = UpdateDidRunStateForApp(dist->GetAppRegistrationData(), 427 return WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(),
488 did_run); 428 google_update::kRegDidRunField,
489 // Update state for binaries, even if the previous call was unsuccessful. 429 did_run ? L"1" : L"0");
490 if (InstallUtil::IsMultiInstall(system_level))
491 result = UpdateDidRunStateForBinaries(did_run) && result;
492 return result;
493 } 430 }
494 431
495 base::string16 GoogleUpdateSettings::GetChromeChannel(bool system_install) { 432 base::string16 GoogleUpdateSettings::GetChromeChannel(bool system_install) {
496 base::string16 channel; 433 base::string16 channel;
497 GetChromeChannelInternal(system_install, false, &channel); 434 GetChromeChannelInternal(system_install, &channel);
498 return channel; 435 return channel;
499 } 436 }
500 437
501 bool GoogleUpdateSettings::GetChromeChannelAndModifiers(
502 bool system_install,
503 base::string16* channel) {
504 return GetChromeChannelInternal(system_install, true, channel);
505 }
506
507 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, 438 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install,
508 installer::ArchiveType archive_type, int install_return_code, 439 installer::ArchiveType archive_type, int install_return_code,
509 const base::string16& product_guid) { 440 const base::string16& product_guid) {
510 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE || 441 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE ||
511 install_return_code != 0); 442 install_return_code != 0);
512 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 443 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
513 444
514 RegKey key; 445 RegKey key;
515 installer::ChannelInfo channel_info; 446 installer::ChannelInfo channel_info;
516 base::string16 reg_key(google_update::kRegPathClientState); 447 base::string16 reg_key(google_update::kRegPathClientState);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 } else { 514 } else {
584 VLOG(1) << "Incremental installer failure; already on channel: " 515 VLOG(1) << "Incremental installer failure; already on channel: "
585 << value->value(); 516 << value->value();
586 } 517 }
587 } else { 518 } else {
588 // It's okay if we don't know the archive type. In this case, leave the 519 // It's okay if we don't know the archive type. In this case, leave the
589 // "-full" suffix as we found it. 520 // "-full" suffix as we found it.
590 DCHECK_EQ(installer::UNKNOWN_ARCHIVE_TYPE, archive_type); 521 DCHECK_EQ(installer::UNKNOWN_ARCHIVE_TYPE, archive_type);
591 } 522 }
592 523
524 // The mini_installer in Chrome 10 through 12 added "-multifail" to the "ap"
525 // value if "--multi-install" was on the command line. Unconditionally remove
526 // it if present.
527 // TODO(grt): Move this cleanup into mini_installer.cc's SetInstallerFlags.
593 if (value->SetMultiFailSuffix(false)) { 528 if (value->SetMultiFailSuffix(false)) {
594 VLOG(1) << "Removed multi-install failure key; switching to channel: " 529 VLOG(1) << "Removed multi-install failure key; switching to channel: "
595 << value->value(); 530 << value->value();
596 modified = true; 531 modified = true;
597 } 532 }
598 533
599 if (value->ClearStage()) { 534 if (value->ClearStage()) {
600 VLOG(1) << "Removed (legacy) stage information; switching to channel: " 535 VLOG(1) << "Removed (legacy) stage information; switching to channel: "
601 << value->value(); 536 << value->value();
602 modified = true; 537 modified = true;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 RegKey policy_key; 627 RegKey policy_key;
693 DWORD value = 0; 628 DWORD value = 0;
694 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, 629 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey,
695 KEY_QUERY_VALUE) == ERROR_SUCCESS && 630 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
696 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes, 631 policy_key.ReadValueDW(kCheckPeriodOverrideMinutes,
697 &value) == ERROR_SUCCESS && 632 &value) == ERROR_SUCCESS &&
698 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) { 633 (value == 0 || value > kCheckPeriodOverrideMinutesMax)) {
699 return false; 634 return false;
700 } 635 }
701 636
702 // Auto updates are subtly broken when Chrome and the binaries have different
703 // overrides in place. If this Chrome cannot possibly be multi-install by
704 // virtue of being a side-by-side installation, simply check Chrome's policy.
705 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 637 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
706 UpdatePolicy app_policy = GetAppUpdatePolicy(dist->GetAppGuid(), nullptr); 638 UpdatePolicy app_policy = GetAppUpdatePolicy(dist->GetAppGuid(), nullptr);
707 if (InstallUtil::IsChromeSxSProcess()) 639 return app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY;
708 return app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY;
709
710 // Otherwise, check for consistency between Chrome and the binaries regardless
711 // of whether or not this Chrome is multi-install since the next update likely
712 // will attempt to migrate it to such.
713 BrowserDistribution* binaries = BrowserDistribution::GetSpecificDistribution(
714 BrowserDistribution::CHROME_BINARIES);
715 return (GetAppUpdatePolicy(binaries->GetAppGuid(), nullptr) == app_policy &&
716 (app_policy == AUTOMATIC_UPDATES || app_policy == AUTO_UPDATES_ONLY));
717 #else // defined(GOOGLE_CHROME_BUILD) 640 #else // defined(GOOGLE_CHROME_BUILD)
718 // Chromium does not auto update. 641 // Chromium does not auto update.
719 return false; 642 return false;
720 #endif // !defined(GOOGLE_CHROME_BUILD) 643 #endif // !defined(GOOGLE_CHROME_BUILD)
721 } 644 }
722 645
723 // static 646 // static
724 bool GoogleUpdateSettings::ReenableAutoupdates() { 647 bool GoogleUpdateSettings::ReenableAutoupdates() {
725 #if defined(GOOGLE_CHROME_BUILD) 648 #if defined(GOOGLE_CHROME_BUILD)
726 int needs_reset_count = 0; 649 int needs_reset_count = 0;
727 int did_reset_count = 0; 650 int did_reset_count = 0;
728 651
729 // Reset overrides for Chrome and for the binaries if this Chrome supports
730 // multi-install.
731 std::vector<base::string16> app_guids;
732 app_guids.push_back(BrowserDistribution::GetDistribution()->GetAppGuid());
733 if (!InstallUtil::IsChromeSxSProcess()) {
734 app_guids.push_back(BrowserDistribution::GetSpecificDistribution(
735 BrowserDistribution::CHROME_BINARIES)->GetAppGuid());
736 }
737
738 UpdatePolicy update_policy = kDefaultUpdatePolicy; 652 UpdatePolicy update_policy = kDefaultUpdatePolicy;
739 RegKey policy_key; 653 RegKey policy_key;
740 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey, 654 if (policy_key.Open(HKEY_LOCAL_MACHINE, kPoliciesKey,
741 KEY_SET_VALUE | KEY_QUERY_VALUE) == ERROR_SUCCESS) { 655 KEY_SET_VALUE | KEY_QUERY_VALUE) == ERROR_SUCCESS) {
742 // Set to true while app-specific overrides are present that allow automatic 656 // Set to true while app-specific overrides are present that allow automatic
743 // updates. When this is the case, the defaults are irrelevant and don't 657 // updates. When this is the case, the defaults are irrelevant and don't
744 // need to be checked or reset. 658 // need to be checked or reset.
745 bool automatic_updates_allowed_by_overrides = true; 659 bool automatic_updates_allowed_by_overrides = true;
746 DWORD value = 0; 660 DWORD value = 0;
747 for (const base::string16& app_guid : app_guids) { 661
748 // First check the app-specific override value and reset that if needed. 662 // First check the app-specific override value and reset that if needed.
749 // Note that this intentionally sets the override to AUTOMATIC_UPDATES 663 // Note that this intentionally sets the override to AUTOMATIC_UPDATES even
750 // even if it was previously AUTO_UPDATES_ONLY. The thinking is that 664 // if it was previously AUTO_UPDATES_ONLY. The thinking is that
751 // AUTOMATIC_UPDATES is marginally more likely to let a user update and 665 // AUTOMATIC_UPDATES is marginally more likely to let a user update and this
752 // this code is only called when a stuck user asks for updates. 666 // code is only called when a stuck user asks for updates.
753 base::string16 app_update_override(kUpdateOverrideValuePrefix); 667 base::string16 app_update_override(kUpdateOverrideValuePrefix);
754 app_update_override.append(app_guid); 668 app_update_override.append(
755 if (policy_key.ReadValueDW(app_update_override.c_str(), 669 BrowserDistribution::GetDistribution()->GetAppGuid());
756 &value) != ERROR_SUCCESS) { 670 if (policy_key.ReadValueDW(app_update_override.c_str(), &value) !=
757 automatic_updates_allowed_by_overrides = false; 671 ERROR_SUCCESS) {
758 } else if (!GetUpdatePolicyFromDword(value, &update_policy) || 672 automatic_updates_allowed_by_overrides = false;
759 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES) { 673 } else if (!GetUpdatePolicyFromDword(value, &update_policy) ||
760 automatic_updates_allowed_by_overrides = false; 674 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES) {
761 ++needs_reset_count; 675 automatic_updates_allowed_by_overrides = false;
762 if (policy_key.WriteValue( 676 ++needs_reset_count;
763 app_update_override.c_str(), 677 if (policy_key.WriteValue(
764 static_cast<DWORD>(GoogleUpdateSettings::AUTOMATIC_UPDATES)) == 678 app_update_override.c_str(),
765 ERROR_SUCCESS) { 679 static_cast<DWORD>(GoogleUpdateSettings::AUTOMATIC_UPDATES)) ==
766 ++did_reset_count; 680 ERROR_SUCCESS) {
767 } 681 ++did_reset_count;
768 } 682 }
769 } 683 }
770 684
771 // If there were no app-specific override policies, see if there's a global 685 // If there were no app-specific override policies, see if there's a global
772 // policy preventing updates and delete it if so. 686 // policy preventing updates and delete it if so.
773 if (!automatic_updates_allowed_by_overrides && 687 if (!automatic_updates_allowed_by_overrides &&
774 policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS && 688 policy_key.ReadValueDW(kUpdatePolicyValue, &value) == ERROR_SUCCESS &&
775 (!GetUpdatePolicyFromDword(value, &update_policy) || 689 (!GetUpdatePolicyFromDword(value, &update_policy) ||
776 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES)) { 690 update_policy != GoogleUpdateSettings::AUTOMATIC_UPDATES)) {
777 ++needs_reset_count; 691 ++needs_reset_count;
(...skipping 13 matching lines...) Expand all
791 705
792 // Return whether the number of successful resets is the same as the 706 // Return whether the number of successful resets is the same as the
793 // number of things that appeared to need resetting. 707 // number of things that appeared to need resetting.
794 return (needs_reset_count == did_reset_count); 708 return (needs_reset_count == did_reset_count);
795 } else { 709 } else {
796 // For some reason we couldn't open the policy key with the desired 710 // For some reason we couldn't open the policy key with the desired
797 // permissions to make changes (the most likely reason is that there is no 711 // permissions to make changes (the most likely reason is that there is no
798 // policy set). Simply return whether or not we think updates are enabled. 712 // policy set). Simply return whether or not we think updates are enabled.
799 return AreAutoupdatesEnabled(); 713 return AreAutoupdatesEnabled();
800 } 714 }
801
802 #endif 715 #endif
803 // Non Google Chrome isn't going to autoupdate. 716 // Non Google Chrome isn't going to autoupdate.
804 return true; 717 return true;
805 } 718 }
806 719
807 // Reads and sanitizes the value of 720 // Reads and sanitizes the value of
808 // "HKLM\SOFTWARE\Policies\Google\Update\DownloadPreference". A valid 721 // "HKLM\SOFTWARE\Policies\Google\Update\DownloadPreference". A valid
809 // group policy option must be a single alpha numeric word of up to 32 722 // group policy option must be a single alpha numeric word of up to 32
810 // characters. 723 // characters.
811 base::string16 GoogleUpdateSettings::GetDownloadPreference() { 724 base::string16 GoogleUpdateSettings::GetDownloadPreference() {
(...skipping 10 matching lines...) Expand all
822 for (auto ch : value) { 735 for (auto ch : value) {
823 if (!base::IsAsciiAlpha(ch)) 736 if (!base::IsAsciiAlpha(ch))
824 return base::string16(); 737 return base::string16();
825 } 738 }
826 return value; 739 return value;
827 } 740 }
828 return base::string16(); 741 return base::string16();
829 } 742 }
830 743
831 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() { 744 void GoogleUpdateSettings::RecordChromeUpdatePolicyHistograms() {
832 const bool is_multi_install = InstallUtil::IsMultiInstall(IsSystemInstall());
833 const base::string16 app_guid = 745 const base::string16 app_guid =
834 BrowserDistribution::GetSpecificDistribution( 746 BrowserDistribution::GetDistribution()->GetAppGuid();
835 is_multi_install ? BrowserDistribution::CHROME_BINARIES :
836 BrowserDistribution::CHROME_BROWSER)->GetAppGuid();
837 747
838 bool is_overridden = false; 748 bool is_overridden = false;
839 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid, 749 const UpdatePolicy update_policy = GetAppUpdatePolicy(app_guid,
840 &is_overridden); 750 &is_overridden);
841 UMA_HISTOGRAM_BOOLEAN("GoogleUpdate.UpdatePolicyIsOverridden", is_overridden); 751 UMA_HISTOGRAM_BOOLEAN("GoogleUpdate.UpdatePolicyIsOverridden", is_overridden);
842 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.EffectivePolicy", update_policy, 752 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.EffectivePolicy", update_policy,
843 UPDATE_POLICIES_COUNT); 753 UPDATE_POLICIES_COUNT);
844 } 754 }
845 755
846 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( 756 base::string16 GoogleUpdateSettings::GetUninstallCommandLine(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 } 939 }
1030 940
1031 // If the key or value was not present, return the empty string. 941 // If the key or value was not present, return the empty string.
1032 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 942 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
1033 experiment_labels->clear(); 943 experiment_labels->clear();
1034 return true; 944 return true;
1035 } 945 }
1036 946
1037 return result == ERROR_SUCCESS; 947 return result == ERROR_SUCCESS;
1038 } 948 }
OLDNEW
« no previous file with comments | « chrome/installer/util/google_update_settings.h ('k') | chrome/installer/util/google_update_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698