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

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

Issue 2476573004: Use InstallDetails in installer_util. (Closed)
Patch Set: sync to position 451835 Created 3 years, 10 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 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/numerics/safe_conversions.h" 15 #include "base/numerics/safe_conversions.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "base/win/registry.h" 22 #include "base/win/registry.h"
23 #include "base/win/win_util.h" 23 #include "base/win/win_util.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/install_static/install_util.h"
25 #include "chrome/installer/util/app_registration_data.h" 26 #include "chrome/installer/util/app_registration_data.h"
26 #include "chrome/installer/util/browser_distribution.h" 27 #include "chrome/installer/util/browser_distribution.h"
27 #include "chrome/installer/util/channel_info.h" 28 #include "chrome/installer/util/channel_info.h"
28 #include "chrome/installer/util/install_util.h" 29 #include "chrome/installer/util/install_util.h"
29 #include "chrome/installer/util/installation_state.h" 30 #include "chrome/installer/util/installation_state.h"
30 #include "chrome/installer/util/product.h" 31 #include "chrome/installer/util/product.h"
31 32
32 using base::win::RegKey; 33 using base::win::RegKey;
33 using installer::InstallationState; 34 using installer::InstallationState;
34 35
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // failure. 159 // failure.
159 bool InitChannelInfo(bool system_install, 160 bool InitChannelInfo(bool system_install,
160 installer::ChannelInfo* channel_info) { 161 installer::ChannelInfo* channel_info) {
161 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 162 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
162 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 163 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
163 RegKey key(root_key, dist->GetStateKey().c_str(), 164 RegKey key(root_key, dist->GetStateKey().c_str(),
164 KEY_QUERY_VALUE | KEY_WOW64_32KEY); 165 KEY_QUERY_VALUE | KEY_WOW64_32KEY);
165 return channel_info->Initialize(key); 166 return channel_info->Initialize(key);
166 } 167 }
167 168
168 bool GetChromeChannelInternal(bool system_install,
169 base::string16* channel) {
170 // Shortcut in case this distribution knows what channel it is (canary).
171 if (BrowserDistribution::GetDistribution()->GetChromeChannel(channel))
172 return true;
173
174 installer::ChannelInfo channel_info;
175 if (!InitChannelInfo(system_install, &channel_info)) {
176 channel->assign(installer::kChromeChannelUnknown);
177 return false;
178 }
179
180 if (!channel_info.GetChannelName(channel))
181 channel->assign(installer::kChromeChannelUnknown);
182
183 return true;
184 }
185
186 #if defined(GOOGLE_CHROME_BUILD) 169 #if defined(GOOGLE_CHROME_BUILD)
187 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a 170 // Populates |update_policy| with the UpdatePolicy enum value corresponding to a
188 // DWORD read from the registry and returns true if |value| is within range. 171 // DWORD read from the registry and returns true if |value| is within range.
189 // If |value| is out of range, returns false without modifying |update_policy|. 172 // If |value| is out of range, returns false without modifying |update_policy|.
190 bool GetUpdatePolicyFromDword( 173 bool GetUpdatePolicyFromDword(
191 const DWORD value, 174 const DWORD value,
192 GoogleUpdateSettings::UpdatePolicy* update_policy) { 175 GoogleUpdateSettings::UpdatePolicy* update_policy) {
193 switch (value) { 176 switch (value) {
194 case GoogleUpdateSettings::UPDATES_DISABLED: 177 case GoogleUpdateSettings::UPDATES_DISABLED:
195 case GoogleUpdateSettings::AUTOMATIC_UPDATES: 178 case GoogleUpdateSettings::AUTOMATIC_UPDATES:
196 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY: 179 case GoogleUpdateSettings::MANUAL_UPDATES_ONLY:
197 case GoogleUpdateSettings::AUTO_UPDATES_ONLY: 180 case GoogleUpdateSettings::AUTO_UPDATES_ONLY:
198 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value); 181 *update_policy = static_cast<GoogleUpdateSettings::UpdatePolicy>(value);
199 return true; 182 return true;
200 default: 183 default:
201 LOG(WARNING) << "Unexpected update policy override value: " << value; 184 LOG(WARNING) << "Unexpected update policy override value: " << value;
202 } 185 }
203 return false; 186 return false;
204 } 187 }
205 #endif // defined(GOOGLE_CHROME_BUILD) 188 #endif // defined(GOOGLE_CHROME_BUILD)
206 189
207 } // namespace 190 } // namespace
208 191
209 bool GoogleUpdateSettings::IsSystemInstall() { 192 bool GoogleUpdateSettings::IsSystemInstall() {
210 bool system_install = false; 193 // TODO(grt): Remove this unused argument.
211 base::FilePath module_dir; 194 base::FilePath unused;
212 if (!PathService::Get(base::DIR_MODULE, &module_dir)) { 195 return !InstallUtil::IsPerUserInstall(unused);
213 LOG(WARNING)
214 << "Failed to get directory of module; assuming per-user install.";
215 } else {
216 system_install = !InstallUtil::IsPerUserInstall(module_dir);
217 }
218 return system_install;
219 } 196 }
220 197
221 bool GoogleUpdateSettings::GetCollectStatsConsent() { 198 bool GoogleUpdateSettings::GetCollectStatsConsent() {
222 return GetCollectStatsConsentAtLevel(IsSystemInstall()); 199 return GetCollectStatsConsentAtLevel(IsSystemInstall());
223 } 200 }
224 201
225 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { 202 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
226 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented); 203 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented);
227 } 204 }
228 205
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 400 }
424 401
425 bool GoogleUpdateSettings::UpdateDidRunState(bool did_run) { 402 bool GoogleUpdateSettings::UpdateDidRunState(bool did_run) {
426 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 403 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
427 return WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(), 404 return WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(),
428 google_update::kRegDidRunField, 405 google_update::kRegDidRunField,
429 did_run ? L"1" : L"0"); 406 did_run ? L"1" : L"0");
430 } 407 }
431 408
432 base::string16 GoogleUpdateSettings::GetChromeChannel(bool system_install) { 409 base::string16 GoogleUpdateSettings::GetChromeChannel(bool system_install) {
433 base::string16 channel; 410 return install_static::GetChromeChannelName();
434 GetChromeChannelInternal(system_install, &channel);
435 return channel;
436 } 411 }
437 412
438 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, 413 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install,
439 installer::ArchiveType archive_type, int install_return_code, 414 installer::ArchiveType archive_type, int install_return_code,
440 const base::string16& product_guid) { 415 const base::string16& product_guid) {
441 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE || 416 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE ||
442 install_return_code != 0); 417 install_return_code != 0);
443 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 418 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
444 419
445 RegKey key; 420 RegKey key;
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 } 914 }
940 915
941 // If the key or value was not present, return the empty string. 916 // If the key or value was not present, return the empty string.
942 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 917 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
943 experiment_labels->clear(); 918 experiment_labels->clear();
944 return true; 919 return true;
945 } 920 }
946 921
947 return result == ERROR_SUCCESS; 922 return result == ERROR_SUCCESS;
948 } 923 }
OLDNEW
« no previous file with comments | « chrome/installer/util/channel_info_unittest.cc ('k') | chrome/installer/util/google_update_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698