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

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

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 22 matching lines...) Expand all
33 FOUND_SAME_SETTING 33 FOUND_SAME_SETTING
34 }; 34 };
35 35
36 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { 36 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) {
37 // The registry functions below will end up going to disk. Do this on another 37 // The registry functions below will end up going to disk. Do this on another
38 // thread to avoid slowing the IO thread. http://crbug.com/62121 38 // thread to avoid slowing the IO thread. http://crbug.com/62121
39 base::ThreadRestrictions::ScopedAllowIO allow_io; 39 base::ThreadRestrictions::ScopedAllowIO allow_io;
40 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 40 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
41 std::wstring reg_path = dist->GetStateKey(); 41 std::wstring reg_path = dist->GetStateKey();
42 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); 42 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ);
43 if (!key.ReadValue(name, value)) { 43 if (key.ReadValue(name, value) != ERROR_SUCCESS) {
44 RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); 44 RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ);
45 return hklm_key.ReadValue(name, value); 45 return (hklm_key.ReadValue(name, value) == ERROR_SUCCESS);
46 } 46 }
47 return true; 47 return true;
48 } 48 }
49 49
50 bool WriteGoogleUpdateStrKey(const wchar_t* const name, 50 bool WriteGoogleUpdateStrKey(const wchar_t* const name,
51 const std::wstring& value) { 51 const std::wstring& value) {
52 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 52 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
53 std::wstring reg_path = dist->GetStateKey(); 53 std::wstring reg_path = dist->GetStateKey();
54 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); 54 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE);
55 return key.WriteValue(name, value.c_str()); 55 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS);
56 } 56 }
57 57
58 bool ClearGoogleUpdateStrKey(const wchar_t* const name) { 58 bool ClearGoogleUpdateStrKey(const wchar_t* const name) {
59 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 59 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
60 std::wstring reg_path = dist->GetStateKey(); 60 std::wstring reg_path = dist->GetStateKey();
61 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); 61 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE);
62 std::wstring value; 62 std::wstring value;
63 if (!key.ReadValue(name, &value)) 63 if (key.ReadValue(name, &value) != ERROR_SUCCESS)
64 return false; 64 return false;
65 return key.WriteValue(name, L""); 65 return (key.WriteValue(name, L"") == ERROR_SUCCESS);
66 } 66 }
67 67
68 bool RemoveGoogleUpdateStrKey(const wchar_t* const name) { 68 bool RemoveGoogleUpdateStrKey(const wchar_t* const name) {
69 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 69 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
70 std::wstring reg_path = dist->GetStateKey(); 70 std::wstring reg_path = dist->GetStateKey();
71 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); 71 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE);
72 if (!key.ValueExists(name)) 72 if (!key.ValueExists(name))
73 return true; 73 return true;
74 return key.DeleteValue(name); 74 return (key.DeleteValue(name) == ERROR_SUCCESS);
75 } 75 }
76 76
77 EulaSearchResult HasEULASetting(HKEY root, const std::wstring& state_key, 77 EulaSearchResult HasEULASetting(HKEY root, const std::wstring& state_key,
78 bool setting) { 78 bool setting) {
79 RegKey key; 79 RegKey key;
80 DWORD previous_value; 80 DWORD previous_value = setting ? 1 : 0;
81 81 if (key.Open(root, state_key.c_str(), KEY_QUERY_VALUE) != ERROR_SUCCESS)
82 if (!key.Open(root, state_key.c_str(), KEY_QUERY_VALUE))
83 return NO_SETTING; 82 return NO_SETTING;
84 83 if (key.ReadValueDW(google_update::kRegEULAAceptedField,
85 if (!key.ReadValueDW(google_update::kRegEULAAceptedField, &previous_value)) 84 &previous_value) != ERROR_SUCCESS)
86 return FOUND_CLIENT_STATE; 85 return FOUND_CLIENT_STATE;
87 86
88 return ((previous_value != 0) == setting) ? 87 return ((previous_value != 0) == setting) ?
89 FOUND_SAME_SETTING : FOUND_OPPOSITE_SETTING; 88 FOUND_SAME_SETTING : FOUND_OPPOSITE_SETTING;
90 } 89 }
91 90
92 } // namespace. 91 } // namespace.
93 92
94 bool GoogleUpdateSettings::GetCollectStatsConsent() { 93 bool GoogleUpdateSettings::GetCollectStatsConsent() {
95 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 94 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
96 std::wstring reg_path = dist->GetStateKey(); 95 std::wstring reg_path = dist->GetStateKey();
97 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); 96 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ);
98 DWORD value; 97 DWORD value = 0;
99 if (!key.ReadValueDW(google_update::kRegUsageStatsField, &value)) { 98 if (key.ReadValueDW(google_update::kRegUsageStatsField, &value)
100 RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); 99 != ERROR_SUCCESS) {
grt (UTC plus 2) 2011/01/16 04:19:48 Wrapping
amit 2011/01/16 07:54:28 Done.
101 if (!hklm_key.ReadValueDW(google_update::kRegUsageStatsField, &value)) 100 key.Open(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ);
102 return false; 101 key.ReadValueDW(google_update::kRegUsageStatsField, &value);
103 } 102 }
104 return (1 == value); 103 return (1 == value);
105 } 104 }
106 105
107 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { 106 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
108 DWORD value = consented? 1 : 0; 107 DWORD value = consented? 1 : 0;
109 // Writing to HKLM is only a best effort deal. 108 // Writing to HKLM is only a best effort deal.
110 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 109 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
111 std::wstring reg_path = dist->GetStateMediumKey(); 110 std::wstring reg_path = dist->GetStateMediumKey();
112 RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WRITE); 111 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WRITE);
113 key_hklm.WriteValue(google_update::kRegUsageStatsField, value); 112 key.WriteValue(google_update::kRegUsageStatsField, value);
114 // Writing to HKCU is used both by chrome and by the crash reporter. 113 // Writing to HKCU is used both by chrome and by the crash reporter.
115 reg_path = dist->GetStateKey(); 114 reg_path = dist->GetStateKey();
116 RegKey key_hkcu(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); 115 key.Open(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE);
117 return key_hkcu.WriteValue(google_update::kRegUsageStatsField, value); 116 return (key.WriteValue(google_update::kRegUsageStatsField, value)
117 == ERROR_SUCCESS);
grt (UTC plus 2) 2011/01/16 04:19:48 Wrapping and indentation
amit 2011/01/16 07:54:28 Done.
118 } 118 }
119 119
120 bool GoogleUpdateSettings::GetMetricsId(std::wstring* metrics_id) { 120 bool GoogleUpdateSettings::GetMetricsId(std::wstring* metrics_id) {
121 return ReadGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id); 121 return ReadGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id);
122 } 122 }
123 123
124 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& metrics_id) { 124 bool GoogleUpdateSettings::SetMetricsId(const std::wstring& metrics_id) {
125 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id); 125 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id);
126 } 126 }
127 127
(...skipping 21 matching lines...) Expand all
149 reg_path = product.distribution()->GetStateMediumKey(); 149 reg_path = product.distribution()->GetStateMediumKey();
150 } 150 }
151 } 151 }
152 if (status == NO_SETTING) { 152 if (status == NO_SETTING) {
153 LOG(WARNING) 153 LOG(WARNING)
154 << "eulaaccepted value not found; setting consent on package"; 154 << "eulaaccepted value not found; setting consent on package";
155 reg_path = package.properties()->GetStateMediumKey(); 155 reg_path = package.properties()->GetStateMediumKey();
156 } 156 }
157 } 157 }
158 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE); 158 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE);
159 return key.WriteValue(google_update::kRegEULAAceptedField, consented ? 1 : 0); 159 return (key.WriteValue(google_update::kRegEULAAceptedField,
160 consented ? 1 : 0) == ERROR_SUCCESS);
160 } 161 }
161 162
162 int GoogleUpdateSettings::GetLastRunTime() { 163 int GoogleUpdateSettings::GetLastRunTime() {
163 std::wstring time_s; 164 std::wstring time_s;
164 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) 165 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s))
165 return -1; 166 return -1;
166 int64 time_i; 167 int64 time_i;
167 if (!base::StringToInt64(time_s, &time_i)) 168 if (!base::StringToInt64(time_s, &time_i))
168 return -1; 169 return -1;
169 base::TimeDelta td = 170 base::TimeDelta td =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, 241 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install,
241 bool incremental_install, bool multi_install, int install_return_code, 242 bool incremental_install, bool multi_install, int install_return_code,
242 const std::wstring& product_guid) { 243 const std::wstring& product_guid) {
243 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 244 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
244 245
245 RegKey key; 246 RegKey key;
246 installer::ChannelInfo channel_info; 247 installer::ChannelInfo channel_info;
247 std::wstring reg_key(google_update::kRegPathClientState); 248 std::wstring reg_key(google_update::kRegPathClientState);
248 reg_key.append(L"\\"); 249 reg_key.append(L"\\");
249 reg_key.append(product_guid); 250 reg_key.append(product_guid);
250 if (!key.Open(reg_root, reg_key.c_str(), KEY_QUERY_VALUE | KEY_SET_VALUE) || 251 LONG result = key.Open(reg_root, reg_key.c_str(),
251 !channel_info.Initialize(key)) { 252 KEY_QUERY_VALUE | KEY_SET_VALUE);
253 if (result != ERROR_SUCCESS || !channel_info.Initialize(key)) {
252 VLOG(1) << "Application key not found."; 254 VLOG(1) << "Application key not found.";
253 if (!incremental_install && !multi_install || !install_return_code) { 255 if (!incremental_install && !multi_install || !install_return_code) {
254 VLOG(1) << "Returning without changing application key."; 256 VLOG(1) << "Returning without changing application key.";
255 return; 257 return;
256 } else if (!key.Valid()) { 258 } else if (!key.Valid()) {
257 reg_key.assign(google_update::kRegPathClientState); 259 reg_key.assign(google_update::kRegPathClientState);
258 if (!key.Open(reg_root, reg_key.c_str(), KEY_CREATE_SUB_KEY) || 260 result = key.Open(reg_root, reg_key.c_str(), KEY_CREATE_SUB_KEY);
259 !key.CreateKey(product_guid.c_str(), KEY_SET_VALUE)) { 261 if (result == ERROR_SUCCESS)
260 LOG(ERROR) << "Failed to create application key."; 262 result = key.CreateKey(product_guid.c_str(), KEY_SET_VALUE);
263
264 if (result != ERROR_SUCCESS) {
265 LOG(ERROR) << "Failed to create application key. Error: " << result;
261 return; 266 return;
262 } 267 }
263 } 268 }
264 } 269 }
265 270
266 if (UpdateGoogleUpdateApKey(incremental_install, multi_install, 271 if (UpdateGoogleUpdateApKey(incremental_install, multi_install,
267 install_return_code, &channel_info) && 272 install_return_code, &channel_info) &&
268 !channel_info.Write(&key)) { 273 !channel_info.Write(&key)) {
269 LOG(ERROR) << "Failed to write value " << channel_info.value() 274 LOG(ERROR) << "Failed to write value " << channel_info.value()
270 << " to the registry field " << google_update::kRegApField; 275 << " to the registry field " << google_update::kRegApField;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 }; 359 };
355 const wchar_t** end = &kBrands[arraysize(kBrands)]; 360 const wchar_t** end = &kBrands[arraysize(kBrands)];
356 const wchar_t** found = std::find(&kBrands[0], end, brand); 361 const wchar_t** found = std::find(&kBrands[0], end, brand);
357 if (found != end) 362 if (found != end)
358 return true; 363 return true;
359 if (StartsWith(brand, L"EUB", true) || StartsWith(brand, L"EUC", true) || 364 if (StartsWith(brand, L"EUB", true) || StartsWith(brand, L"EUC", true) ||
360 StartsWith(brand, L"GGR", true)) 365 StartsWith(brand, L"GGR", true))
361 return true; 366 return true;
362 return false; 367 return false;
363 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698