| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 64 } |
| 64 return true; | 65 return true; |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Writes |value| into a user-specific value in the key |name| under | 68 // Writes |value| into a user-specific value in the key |name| under |
| 68 // |app_reg_data|'s ClientStateMedium key in HKLM along with the aggregation | 69 // |app_reg_data|'s ClientStateMedium key in HKLM along with the aggregation |
| 69 // method |aggregate|. This function is solely for use by system-level installs. | 70 // method |aggregate|. This function is solely for use by system-level installs. |
| 70 bool WriteGoogleUpdateAggregateNumKeyInternal( | 71 bool WriteGoogleUpdateAggregateNumKeyInternal( |
| 71 const AppRegistrationData& app_reg_data, | 72 const AppRegistrationData& app_reg_data, |
| 72 const wchar_t* const name, | 73 const wchar_t* const name, |
| 73 int value, | 74 size_t value, |
| 74 const wchar_t* const aggregate) { | 75 const wchar_t* const aggregate) { |
| 75 DCHECK(aggregate); | 76 DCHECK(aggregate); |
| 76 DCHECK(GoogleUpdateSettings::IsSystemInstall()); | 77 DCHECK(GoogleUpdateSettings::IsSystemInstall()); |
| 77 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; | 78 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; |
| 78 | 79 |
| 79 // Machine installs require each OS user to write a unique key under a | 80 // Machine installs require each OS user to write a unique key under a |
| 80 // named key in HKLM as well as an "aggregation" function that describes | 81 // named key in HKLM as well as an "aggregation" function that describes |
| 81 // how the values of multiple users are to be combined. | 82 // how the values of multiple users are to be combined. |
| 82 base::string16 uniquename; | 83 base::string16 uniquename; |
| 83 if (!base::win::GetUserSidString(&uniquename)) { | 84 if (!base::win::GetUserSidString(&uniquename)) { |
| 84 NOTREACHED(); | 85 NOTREACHED(); |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| 87 | 88 |
| 88 base::string16 reg_path(app_reg_data.GetStateMediumKey()); | 89 base::string16 reg_path(app_reg_data.GetStateMediumKey()); |
| 89 reg_path.append(L"\\"); | 90 reg_path.append(L"\\"); |
| 90 reg_path.append(name); | 91 reg_path.append(name); |
| 91 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess); | 92 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess); |
| 92 key.WriteValue(google_update::kRegAggregateMethod, aggregate); | 93 key.WriteValue(google_update::kRegAggregateMethod, aggregate); |
| 93 return (key.WriteValue(uniquename.c_str(), value) == ERROR_SUCCESS); | 94 |
| 95 DWORD dword_value = (value > std::numeric_limits<DWORD>::max() ? |
| 96 std::numeric_limits<DWORD>::max() : |
| 97 static_cast<DWORD>(value)); |
| 98 return (key.WriteValue(uniquename.c_str(), dword_value) == ERROR_SUCCESS); |
| 94 } | 99 } |
| 95 | 100 |
| 96 // Updates a registry key |name| to be |value| for the given |app_reg_data|. | 101 // Updates a registry key |name| to be |value| for the given |app_reg_data|. |
| 97 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data, | 102 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data, |
| 98 const wchar_t* const name, | 103 const wchar_t* const name, |
| 99 const base::string16& value) { | 104 const base::string16& value) { |
| 100 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; | 105 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; |
| 101 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess); | 106 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess); |
| 102 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); | 107 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); |
| 103 } | 108 } |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 544 |
| 540 if (value->SetMultiFailSuffix(false)) { | 545 if (value->SetMultiFailSuffix(false)) { |
| 541 VLOG(1) << "Removed multi-install failure key; switching to channel: " | 546 VLOG(1) << "Removed multi-install failure key; switching to channel: " |
| 542 << value->value(); | 547 << value->value(); |
| 543 modified = true; | 548 modified = true; |
| 544 } | 549 } |
| 545 | 550 |
| 546 return modified; | 551 return modified; |
| 547 } | 552 } |
| 548 | 553 |
| 549 void GoogleUpdateSettings::UpdateProfileCounts(int profiles_active, | 554 void GoogleUpdateSettings::UpdateProfileCounts(size_t profiles_active, |
| 550 int profiles_signedin) { | 555 size_t profiles_signedin) { |
| 551 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 556 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 552 // System-level installs must write into the ClientStateMedium key shared by | 557 // System-level installs must write into the ClientStateMedium key shared by |
| 553 // all users. Special treatment is used to aggregate across those users. | 558 // all users. Special treatment is used to aggregate across those users. |
| 554 if (IsSystemInstall()) { | 559 if (IsSystemInstall()) { |
| 555 // Write the counts as ints that get aggregated across all users via | 560 // Write the counts as ints that get aggregated across all users via |
| 556 // summation for system-level installs. | 561 // summation for system-level installs. |
| 557 WriteGoogleUpdateAggregateNumKeyInternal( | 562 WriteGoogleUpdateAggregateNumKeyInternal( |
| 558 dist->GetAppRegistrationData(), | 563 dist->GetAppRegistrationData(), |
| 559 google_update::kRegProfilesActive, | 564 google_update::kRegProfilesActive, |
| 560 profiles_active, | 565 profiles_active, |
| 561 L"sum()"); | 566 L"sum()"); |
| 562 WriteGoogleUpdateAggregateNumKeyInternal( | 567 WriteGoogleUpdateAggregateNumKeyInternal( |
| 563 dist->GetAppRegistrationData(), | 568 dist->GetAppRegistrationData(), |
| 564 google_update::kRegProfilesSignedIn, | 569 google_update::kRegProfilesSignedIn, |
| 565 profiles_signedin, | 570 profiles_signedin, |
| 566 L"sum()"); | 571 L"sum()"); |
| 567 } else { | 572 } else { |
| 568 // Write the counts as strings since no aggregation function is needed for | 573 // Write the counts as strings since no aggregation function is needed for |
| 569 // user-level installs. | 574 // user-level installs. |
| 570 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(), | 575 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(), |
| 571 google_update::kRegProfilesActive, | 576 google_update::kRegProfilesActive, |
| 572 base::IntToString16(profiles_active)); | 577 base::SizeTToString16(profiles_active)); |
| 573 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(), | 578 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(), |
| 574 google_update::kRegProfilesSignedIn, | 579 google_update::kRegProfilesSignedIn, |
| 575 base::IntToString16(profiles_signedin)); | 580 base::SizeTToString16(profiles_signedin)); |
| 576 } | 581 } |
| 577 } | 582 } |
| 578 | 583 |
| 579 int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() { | 584 int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() { |
| 580 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 585 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 581 base::string16 reg_path = dist->GetStateKey(); | 586 base::string16 reg_path = dist->GetStateKey(); |
| 582 | 587 |
| 583 // Minimum access needed is to be able to write to this key. | 588 // Minimum access needed is to be able to write to this key. |
| 584 RegKey reg_key( | 589 RegKey reg_key( |
| 585 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); | 590 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 } | 963 } |
| 959 | 964 |
| 960 // If the key or value was not present, return the empty string. | 965 // If the key or value was not present, return the empty string. |
| 961 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { | 966 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { |
| 962 experiment_labels->clear(); | 967 experiment_labels->clear(); |
| 963 return true; | 968 return true; |
| 964 } | 969 } |
| 965 | 970 |
| 966 return result == ERROR_SUCCESS; | 971 return result == ERROR_SUCCESS; |
| 967 } | 972 } |
| OLD | NEW |