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

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

Issue 2308423002: Generalized the storage strategy used by UpdateProfileCounts. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 10 #include <limits>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/numerics/safe_conversions.h"
17 #include "base/path_service.h" 18 #include "base/path_service.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
22 #include "base/time/time.h" 23 #include "base/time/time.h"
23 #include "base/win/registry.h" 24 #include "base/win/registry.h"
24 #include "base/win/win_util.h" 25 #include "base/win/win_util.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/installer/util/app_registration_data.h" 27 #include "chrome/installer/util/app_registration_data.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 return true; 70 return true;
70 } 71 }
71 72
72 // Writes |value| into a user-specific value in the key |name| under 73 // Writes |value| into a user-specific value in the key |name| under
73 // |app_reg_data|'s ClientStateMedium key in HKLM along with the aggregation 74 // |app_reg_data|'s ClientStateMedium key in HKLM along with the aggregation
74 // method |aggregate|. This function is solely for use by system-level installs. 75 // method |aggregate|. This function is solely for use by system-level installs.
75 bool WriteGoogleUpdateAggregateNumKeyInternal( 76 bool WriteGoogleUpdateAggregateNumKeyInternal(
76 const AppRegistrationData& app_reg_data, 77 const AppRegistrationData& app_reg_data,
77 const wchar_t* const name, 78 const wchar_t* const name,
78 size_t value, 79 uint32_t value,
79 const wchar_t* const aggregate) { 80 const wchar_t* const aggregate) {
80 DCHECK(aggregate); 81 DCHECK(aggregate);
81 DCHECK(GoogleUpdateSettings::IsSystemInstall()); 82 DCHECK(GoogleUpdateSettings::IsSystemInstall());
82 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; 83 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY;
83 84
84 // Machine installs require each OS user to write a unique key under a 85 // Machine installs require each OS user to write a unique key under a
85 // named key in HKLM as well as an "aggregation" function that describes 86 // named key in HKLM as well as an "aggregation" function that describes
86 // how the values of multiple users are to be combined. 87 // how the values of multiple users are to be combined.
87 base::string16 uniquename; 88 base::string16 uniquename;
88 if (!base::win::GetUserSidString(&uniquename)) { 89 if (!base::win::GetUserSidString(&uniquename)) {
89 NOTREACHED(); 90 NOTREACHED();
90 return false; 91 return false;
91 } 92 }
92 93
93 base::string16 reg_path(app_reg_data.GetStateMediumKey()); 94 base::string16 reg_path(app_reg_data.GetStateMediumKey());
94 reg_path.append(L"\\"); 95 reg_path.append(L"\\");
95 reg_path.append(name); 96 reg_path.append(name);
96 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess); 97 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess);
97 key.WriteValue(google_update::kRegAggregateMethod, aggregate); 98 key.WriteValue(google_update::kRegAggregateMethod, aggregate);
98 99
99 DWORD dword_value = (value > std::numeric_limits<DWORD>::max() ? 100 return (key.WriteValue(uniquename.c_str(), value) == ERROR_SUCCESS);
100 std::numeric_limits<DWORD>::max() :
101 static_cast<DWORD>(value));
102 return (key.WriteValue(uniquename.c_str(), dword_value) == ERROR_SUCCESS);
103 } 101 }
104 102
105 // Updates a registry key |name| to be |value| for the given |app_reg_data|. 103 // Updates a registry key |name| to be |value| for the given |app_reg_data|.
106 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data, 104 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data,
107 const wchar_t* const name, 105 const wchar_t* const name,
108 const base::string16& value) { 106 const base::string16& value) {
109 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; 107 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY;
110 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess); 108 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess);
111 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); 109 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS);
112 } 110 }
113 111
112 // Writes the per-user stat |value_name|=|value| either in ClientStateMedium
113 // using summation as the aggregation function or in ClientState directly,
114 // depending on whether this is is a per-machine or a per-user install.
115 void WritePerUserStat(const AppRegistrationData& app_reg_data,
116 bool is_system_install,
117 const wchar_t* value_name,
118 uint32_t value) {
119 if (is_system_install) {
120 // Write |value| as a DWORD in a per-user value of subkey |value_name|.
121 WriteGoogleUpdateAggregateNumKeyInternal(app_reg_data, value_name, value,
122 L"sum()");
123 } else {
124 // Write |value| as a string in value |value_name|.
125 WriteGoogleUpdateStrKeyInternal(app_reg_data, value_name,
126 base::UintToString16(value));
127 }
128 }
129
114 bool WriteGoogleUpdateStrKey(const wchar_t* const name, 130 bool WriteGoogleUpdateStrKey(const wchar_t* const name,
115 const base::string16& value) { 131 const base::string16& value) {
116 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 132 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
117 return WriteGoogleUpdateStrKeyInternal( 133 return WriteGoogleUpdateStrKeyInternal(
118 dist->GetAppRegistrationData(), name, value); 134 dist->GetAppRegistrationData(), name, value);
119 } 135 }
120 136
121 bool ClearGoogleUpdateStrKey(const wchar_t* const name) { 137 bool ClearGoogleUpdateStrKey(const wchar_t* const name) {
122 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 138 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
123 base::string16 reg_path = dist->GetStateKey(); 139 base::string16 reg_path = dist->GetStateKey();
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 VLOG(1) << "Removed (legacy) stage information; switching to channel: " 623 VLOG(1) << "Removed (legacy) stage information; switching to channel: "
608 << value->value(); 624 << value->value();
609 modified = true; 625 modified = true;
610 } 626 }
611 627
612 return modified; 628 return modified;
613 } 629 }
614 630
615 void GoogleUpdateSettings::UpdateProfileCounts(size_t profiles_active, 631 void GoogleUpdateSettings::UpdateProfileCounts(size_t profiles_active,
616 size_t profiles_signedin) { 632 size_t profiles_signedin) {
617 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 633 const auto& app_reg_data =
618 // System-level installs must write into the ClientStateMedium key shared by 634 BrowserDistribution::GetDistribution()->GetAppRegistrationData();
619 // all users. Special treatment is used to aggregate across those users. 635 const bool is_system_install = IsSystemInstall();
620 if (IsSystemInstall()) { 636 WritePerUserStat(app_reg_data, is_system_install,
621 // Write the counts as ints that get aggregated across all users via 637 google_update::kRegProfilesActive,
622 // summation for system-level installs. 638 base::saturated_cast<uint32_t>(profiles_active));
623 WriteGoogleUpdateAggregateNumKeyInternal( 639 WritePerUserStat(app_reg_data, is_system_install,
624 dist->GetAppRegistrationData(), 640 google_update::kRegProfilesSignedIn,
625 google_update::kRegProfilesActive, 641 base::saturated_cast<uint32_t>(profiles_signedin));
626 profiles_active,
627 L"sum()");
628 WriteGoogleUpdateAggregateNumKeyInternal(
629 dist->GetAppRegistrationData(),
630 google_update::kRegProfilesSignedIn,
631 profiles_signedin,
632 L"sum()");
633 } else {
634 // Write the counts as strings since no aggregation function is needed for
635 // user-level installs.
636 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(),
637 google_update::kRegProfilesActive,
638 base::SizeTToString16(profiles_active));
639 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(),
640 google_update::kRegProfilesSignedIn,
641 base::SizeTToString16(profiles_signedin));
642 }
643 } 642 }
644 643
645 int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() { 644 int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() {
646 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 645 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
647 base::string16 reg_path = dist->GetStateKey(); 646 base::string16 reg_path = dist->GetStateKey();
648 647
649 // Minimum access needed is to be able to write to this key. 648 // Minimum access needed is to be able to write to this key.
650 RegKey reg_key( 649 RegKey reg_key(
651 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); 650 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY);
652 if (!reg_key.Valid()) 651 if (!reg_key.Valid())
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 } 1053 }
1055 1054
1056 // If the key or value was not present, return the empty string. 1055 // If the key or value was not present, return the empty string.
1057 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 1056 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
1058 experiment_labels->clear(); 1057 experiment_labels->clear();
1059 return true; 1058 return true;
1060 } 1059 }
1061 1060
1062 return result == ERROR_SUCCESS; 1061 return result == ERROR_SUCCESS;
1063 } 1062 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698