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_util.h" | 5 #include "chrome/installer/util/google_update_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/environment.h" | 13 #include "base/environment.h" |
| 14 #include "base/file_util.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/path_service.h" |
17 #include "base/process/kill.h" | 19 #include "base/process/kill.h" |
18 #include "base/process/launch.h" | 20 #include "base/process/launch.h" |
19 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
20 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
22 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
23 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 26 #include "base/win/win_util.h" |
| 27 #include "base/win/windows_version.h" |
24 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | 28 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
25 #include "chrome/installer/util/google_update_constants.h" | 29 #include "chrome/installer/util/google_update_constants.h" |
26 #include "chrome/installer/util/google_update_settings.h" | 30 #include "chrome/installer/util/google_update_settings.h" |
| 31 #include "chrome/installer/util/install_util.h" |
27 | 32 |
28 using base::win::RegKey; | 33 using base::win::RegKey; |
29 | 34 |
30 namespace google_update { | 35 namespace google_update { |
31 | 36 |
32 namespace { | 37 namespace { |
33 | 38 |
34 const int kGoogleUpdateTimeoutMs = 20 * 1000; | 39 const int kGoogleUpdateTimeoutMs = 20 * 1000; |
35 | 40 |
36 const char kEnvVariableUntrustedData[] = "GoogleUpdateUntrustedData"; | 41 const char kEnvVariableUntrustedData[] = "GoogleUpdateUntrustedData"; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 GoogleUpdateSettings::GetUninstallCommandLine(system_install)); | 215 GoogleUpdateSettings::GetUninstallCommandLine(system_install)); |
211 if (cmd_string.empty()) { | 216 if (cmd_string.empty()) { |
212 success = true; // Nothing to; vacuous success. | 217 success = true; // Nothing to; vacuous success. |
213 } else { | 218 } else { |
214 success = LaunchProcessAndWaitWithTimeout(cmd_string, | 219 success = LaunchProcessAndWaitWithTimeout(cmd_string, |
215 base::TimeDelta::FromMilliseconds(kGoogleUpdateTimeoutMs)); | 220 base::TimeDelta::FromMilliseconds(kGoogleUpdateTimeoutMs)); |
216 } | 221 } |
217 return success; | 222 return success; |
218 } | 223 } |
219 | 224 |
| 225 bool ElevateIfNeededToReenableUpdates() { |
| 226 base::FilePath chrome_exe; |
| 227 PathService::Get(base::FILE_EXE, &chrome_exe); |
| 228 base::FilePath exe_path = |
| 229 base::FilePath(chrome_exe).DirName().Append(installer::kSetupExe); |
| 230 if (!base::PathExists(exe_path)) { |
| 231 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()) ? |
| 232 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 233 BrowserDistribution* dist = |
| 234 BrowserDistribution::GetSpecificDistribution( |
| 235 BrowserDistribution::CHROME_BROWSER); |
| 236 RegKey key(reg_root, dist->GetUninstallRegPath().c_str(), KEY_READ); |
| 237 base::string16 uninstall_string; |
| 238 key.ReadValue(installer::kUninstallStringField, &uninstall_string); |
| 239 CommandLine command_line = CommandLine::FromString(uninstall_string); |
| 240 exe_path = command_line.GetProgram(); |
| 241 } |
| 242 |
| 243 if (!base::PathExists(exe_path)) { |
| 244 LOG(ERROR) << "Could not find setup.exe to reenable updates."; |
| 245 return false; |
| 246 } |
| 247 |
| 248 CommandLine cmd(exe_path); |
| 249 cmd.AppendSwitch(installer::switches::kReenableAutoupdates); |
| 250 |
| 251 if (!InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())) |
| 252 cmd.AppendSwitch(installer::switches::kSystemLevel); |
| 253 |
| 254 base::LaunchOptions launch_options; |
| 255 launch_options.force_breakaway_from_job_ = true; |
| 256 |
| 257 if (base::win::GetVersion() >= base::win::VERSION_VISTA && |
| 258 base::win::UserAccountControlIsEnabled()) { |
| 259 return base::LaunchElevatedProcess(cmd, launch_options, NULL); |
| 260 } else { |
| 261 return base::LaunchProcess(cmd, launch_options, NULL); |
| 262 } |
| 263 } |
| 264 |
220 std::string GetUntrustedDataValue(const std::string& key) { | 265 std::string GetUntrustedDataValue(const std::string& key) { |
221 std::map<std::string, std::string> untrusted_data; | 266 std::map<std::string, std::string> untrusted_data; |
222 if (GetGoogleUpdateUntrustedData(&untrusted_data)) { | 267 if (GetGoogleUpdateUntrustedData(&untrusted_data)) { |
223 std::map<std::string, std::string>::const_iterator data_it( | 268 std::map<std::string, std::string>::const_iterator data_it( |
224 untrusted_data.find(key)); | 269 untrusted_data.find(key)); |
225 if (data_it != untrusted_data.end()) | 270 if (data_it != untrusted_data.end()) |
226 return data_it->second; | 271 return data_it->second; |
227 } | 272 } |
228 | 273 |
229 return std::string(); | 274 return std::string(); |
230 } | 275 } |
231 | 276 |
232 std::string GetUntrustedDataValueFromTag(const std::string& tag, | 277 std::string GetUntrustedDataValueFromTag(const std::string& tag, |
233 const std::string& key) { | 278 const std::string& key) { |
234 std::map<std::string, std::string> untrusted_data; | 279 std::map<std::string, std::string> untrusted_data; |
235 if (ParseUntrustedData(tag, &untrusted_data)) | 280 if (ParseUntrustedData(tag, &untrusted_data)) |
236 return untrusted_data[key]; | 281 return untrusted_data[key]; |
237 | 282 |
238 return std::string(); | 283 return std::string(); |
239 } | 284 } |
240 | 285 |
241 } // namespace google_update | 286 } // namespace google_update |
OLD | NEW |