| 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/browser/component_updater/recovery_component_installer.h" | 5 #include "chrome/browser/component_updater/recovery_component_installer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 enum ChromeRecoveryExitCode { | 55 enum ChromeRecoveryExitCode { |
| 56 EXIT_CODE_RECOVERY_SUCCEEDED = 0, | 56 EXIT_CODE_RECOVERY_SUCCEEDED = 0, |
| 57 EXIT_CODE_RECOVERY_SKIPPED = 1, | 57 EXIT_CODE_RECOVERY_SKIPPED = 1, |
| 58 EXIT_CODE_ELEVATION_NEEDED = 2, | 58 EXIT_CODE_ELEVATION_NEEDED = 2, |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 #if !defined(OS_CHROMEOS) | 61 #if !defined(OS_CHROMEOS) |
| 62 // Checks if elevated recovery simulation switch was present on the command | 62 // Checks if elevated recovery simulation switch was present on the command |
| 63 // line. This is for testing purpose. | 63 // line. This is for testing purpose. |
| 64 bool SimulatingElevatedRecovery() { | 64 bool SimulatingElevatedRecovery() { |
| 65 return CommandLine::ForCurrentProcess()-> | 65 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 66 HasSwitch(switches::kSimulateElevatedRecovery); | 66 switches::kSimulateElevatedRecovery); |
| 67 } | 67 } |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
| 71 scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) { | 71 scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) { |
| 72 JSONFileValueSerializer serializer(manifest); | 72 JSONFileValueSerializer serializer(manifest); |
| 73 std::string error; | 73 std::string error; |
| 74 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); | 74 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); |
| 75 if (root.get() && root->IsType(base::Value::TYPE_DICTIONARY)) { | 75 if (root.get() && root->IsType(base::Value::TYPE_DICTIONARY)) { |
| 76 return scoped_ptr<base::DictionaryValue>( | 76 return scoped_ptr<base::DictionaryValue>( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 std::string name; | 90 std::string name; |
| 91 manifest->GetStringASCII("name", &name); | 91 manifest->GetStringASCII("name", &name); |
| 92 if (name != kRecoveryManifestName) | 92 if (name != kRecoveryManifestName) |
| 93 return; | 93 return; |
| 94 std::string proposed_version; | 94 std::string proposed_version; |
| 95 manifest->GetStringASCII("version", &proposed_version); | 95 manifest->GetStringASCII("version", &proposed_version); |
| 96 const Version version(proposed_version.c_str()); | 96 const Version version(proposed_version.c_str()); |
| 97 if (!version.IsValid()) | 97 if (!version.IsValid()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 CommandLine cmdline(main_file); | 100 base::CommandLine cmdline(main_file); |
| 101 std::string arguments; | 101 std::string arguments; |
| 102 if (manifest->GetStringASCII("x-recovery-args", &arguments)) | 102 if (manifest->GetStringASCII("x-recovery-args", &arguments)) |
| 103 cmdline.AppendArg(arguments); | 103 cmdline.AppendArg(arguments); |
| 104 std::string add_version; | 104 std::string add_version; |
| 105 if (manifest->GetStringASCII("x-recovery-add-version", &add_version) && | 105 if (manifest->GetStringASCII("x-recovery-add-version", &add_version) && |
| 106 add_version == "yes") { | 106 add_version == "yes") { |
| 107 cmdline.AppendSwitchASCII("version", version.GetString()); | 107 cmdline.AppendSwitchASCII("version", version.GetString()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 base::LaunchOptions options; | 110 base::LaunchOptions options; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 138 | 138 |
| 139 void OnUpdateError(int error) override; | 139 void OnUpdateError(int error) override; |
| 140 | 140 |
| 141 bool Install(const base::DictionaryValue& manifest, | 141 bool Install(const base::DictionaryValue& manifest, |
| 142 const base::FilePath& unpack_path) override; | 142 const base::FilePath& unpack_path) override; |
| 143 | 143 |
| 144 bool GetInstalledFile(const std::string& file, | 144 bool GetInstalledFile(const std::string& file, |
| 145 base::FilePath* installed_file) override; | 145 base::FilePath* installed_file) override; |
| 146 | 146 |
| 147 private: | 147 private: |
| 148 bool RunInstallCommand(const CommandLine& cmdline, | 148 bool RunInstallCommand(const base::CommandLine& cmdline, |
| 149 const base::FilePath& installer_folder) const; | 149 const base::FilePath& installer_folder) const; |
| 150 | 150 |
| 151 Version current_version_; | 151 Version current_version_; |
| 152 PrefService* prefs_; | 152 PrefService* prefs_; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 void SimulateElevatedRecoveryHelper(PrefService* prefs) { | 155 void SimulateElevatedRecoveryHelper(PrefService* prefs) { |
| 156 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); | 156 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); |
| 157 } | 157 } |
| 158 | 158 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 BrowserThread::UI, | 210 BrowserThread::UI, |
| 211 FROM_HERE, | 211 FROM_HERE, |
| 212 base::Bind(&SetPrefsForElevatedRecoveryInstall, | 212 base::Bind(&SetPrefsForElevatedRecoveryInstall, |
| 213 installer_folder, | 213 installer_folder, |
| 214 prefs)); | 214 prefs)); |
| 215 } | 215 } |
| 216 base::CloseProcessHandle(process_handle); | 216 base::CloseProcessHandle(process_handle); |
| 217 } | 217 } |
| 218 | 218 |
| 219 bool RecoveryComponentInstaller::RunInstallCommand( | 219 bool RecoveryComponentInstaller::RunInstallCommand( |
| 220 const CommandLine& cmdline, const base::FilePath& installer_folder) const { | 220 const base::CommandLine& cmdline, |
| 221 const base::FilePath& installer_folder) const { |
| 221 base::ProcessHandle process_handle; | 222 base::ProcessHandle process_handle; |
| 222 base::LaunchOptions options; | 223 base::LaunchOptions options; |
| 223 options.start_hidden = true; | 224 options.start_hidden = true; |
| 224 if (!base::LaunchProcess(cmdline, options, &process_handle)) | 225 if (!base::LaunchProcess(cmdline, options, &process_handle)) |
| 225 return false; | 226 return false; |
| 226 | 227 |
| 227 // Let worker pool thread wait for us so we don't block Chrome shutdown. | 228 // Let worker pool thread wait for us so we don't block Chrome shutdown. |
| 228 base::WorkerPool::PostTask( | 229 base::WorkerPool::PostTask( |
| 229 FROM_HERE, | 230 FROM_HERE, |
| 230 base::Bind(&WaitForInstallToComplete, | 231 base::Bind(&WaitForInstallToComplete, |
| 231 process_handle, installer_folder, prefs_), | 232 process_handle, installer_folder, prefs_), |
| 232 true); | 233 true); |
| 233 | 234 |
| 234 // Returns true regardless of install result since from updater service | 235 // Returns true regardless of install result since from updater service |
| 235 // perspective the install is done, even we may need to do elevated | 236 // perspective the install is done, even we may need to do elevated |
| 236 // install later. | 237 // install later. |
| 237 return true; | 238 return true; |
| 238 } | 239 } |
| 239 #else | 240 #else |
| 240 bool RecoveryComponentInstaller::RunInstallCommand( | 241 bool RecoveryComponentInstaller::RunInstallCommand( |
| 241 const CommandLine& cmdline, const base::FilePath&) const { | 242 const base::CommandLine& cmdline, |
| 243 const base::FilePath&) const { |
| 242 return base::LaunchProcess(cmdline, base::LaunchOptions(), NULL); | 244 return base::LaunchProcess(cmdline, base::LaunchOptions(), NULL); |
| 243 } | 245 } |
| 244 #endif | 246 #endif |
| 245 | 247 |
| 246 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, | 248 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, |
| 247 const base::FilePath& unpack_path) { | 249 const base::FilePath& unpack_path) { |
| 248 std::string name; | 250 std::string name; |
| 249 manifest.GetStringASCII("name", &name); | 251 manifest.GetStringASCII("name", &name); |
| 250 if (name != kRecoveryManifestName) | 252 if (name != kRecoveryManifestName) |
| 251 return false; | 253 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 268 return false; | 270 return false; |
| 269 if (!base::Move(unpack_path, path)) { | 271 if (!base::Move(unpack_path, path)) { |
| 270 DVLOG(1) << "Recovery component move failed."; | 272 DVLOG(1) << "Recovery component move failed."; |
| 271 return false; | 273 return false; |
| 272 } | 274 } |
| 273 | 275 |
| 274 base::FilePath main_file = path.Append(kRecoveryFileName); | 276 base::FilePath main_file = path.Append(kRecoveryFileName); |
| 275 if (!base::PathExists(main_file)) | 277 if (!base::PathExists(main_file)) |
| 276 return false; | 278 return false; |
| 277 // Run the recovery component. | 279 // Run the recovery component. |
| 278 CommandLine cmdline(main_file); | 280 base::CommandLine cmdline(main_file); |
| 279 std::string arguments; | 281 std::string arguments; |
| 280 if (manifest.GetStringASCII("x-recovery-args", &arguments)) | 282 if (manifest.GetStringASCII("x-recovery-args", &arguments)) |
| 281 cmdline.AppendArg(arguments); | 283 cmdline.AppendArg(arguments); |
| 282 std::string add_version; | 284 std::string add_version; |
| 283 if (manifest.GetStringASCII("x-recovery-add-version", &add_version) && | 285 if (manifest.GetStringASCII("x-recovery-add-version", &add_version) && |
| 284 add_version == "yes") { | 286 add_version == "yes") { |
| 285 cmdline.AppendSwitchASCII("version", current_version_.GetString()); | 287 cmdline.AppendSwitchASCII("version", current_version_.GetString()); |
| 286 } | 288 } |
| 287 | 289 |
| 288 if (!RunInstallCommand(cmdline, path)) { | 290 if (!RunInstallCommand(cmdline, path)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 #endif | 343 #endif |
| 342 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); | 344 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); |
| 343 } | 345 } |
| 344 | 346 |
| 345 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { | 347 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { |
| 346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 347 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); | 349 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); |
| 348 } | 350 } |
| 349 | 351 |
| 350 } // namespace component_updater | 352 } // namespace component_updater |
| OLD | NEW |