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 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 bool SimulatingElevatedRecovery() { | 86 bool SimulatingElevatedRecovery() { |
87 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 87 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
88 switches::kSimulateElevatedRecovery); | 88 switches::kSimulateElevatedRecovery); |
89 } | 89 } |
90 #endif // !defined(OS_CHROMEOS) | 90 #endif // !defined(OS_CHROMEOS) |
91 | 91 |
92 base::CommandLine GetRecoveryInstallCommandLine( | 92 base::CommandLine GetRecoveryInstallCommandLine( |
93 const base::FilePath& command, | 93 const base::FilePath& command, |
94 const base::DictionaryValue& manifest, | 94 const base::DictionaryValue& manifest, |
95 bool is_deferred_run, | 95 bool is_deferred_run, |
96 const Version& version) { | 96 const base::Version& version) { |
97 base::CommandLine command_line(command); | 97 base::CommandLine command_line(command); |
98 | 98 |
99 // Add a flag to for re-attempted install with elevated privilege so that the | 99 // Add a flag to for re-attempted install with elevated privilege so that the |
100 // recovery executable can report back accordingly. | 100 // recovery executable can report back accordingly. |
101 if (is_deferred_run) | 101 if (is_deferred_run) |
102 command_line.AppendArg("/deferredrun"); | 102 command_line.AppendArg("/deferredrun"); |
103 | 103 |
104 std::string arguments; | 104 std::string arguments; |
105 if (manifest.GetStringASCII("x-recovery-args", &arguments)) | 105 if (manifest.GetStringASCII("x-recovery-args", &arguments)) |
106 command_line.AppendArg(arguments); | 106 command_line.AppendArg(arguments); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 if (!base::PathExists(main_file) || !base::PathExists(manifest_file)) | 144 if (!base::PathExists(main_file) || !base::PathExists(manifest_file)) |
145 return; | 145 return; |
146 | 146 |
147 std::unique_ptr<base::DictionaryValue> manifest(ReadManifest(manifest_file)); | 147 std::unique_ptr<base::DictionaryValue> manifest(ReadManifest(manifest_file)); |
148 std::string name; | 148 std::string name; |
149 manifest->GetStringASCII("name", &name); | 149 manifest->GetStringASCII("name", &name); |
150 if (name != kRecoveryManifestName) | 150 if (name != kRecoveryManifestName) |
151 return; | 151 return; |
152 std::string proposed_version; | 152 std::string proposed_version; |
153 manifest->GetStringASCII("version", &proposed_version); | 153 manifest->GetStringASCII("version", &proposed_version); |
154 const Version version(proposed_version.c_str()); | 154 const base::Version version(proposed_version.c_str()); |
155 if (!version.IsValid()) | 155 if (!version.IsValid()) |
156 return; | 156 return; |
157 | 157 |
158 const bool is_deferred_run = true; | 158 const bool is_deferred_run = true; |
159 const auto cmdline = GetRecoveryInstallCommandLine( | 159 const auto cmdline = GetRecoveryInstallCommandLine( |
160 main_file, *manifest, is_deferred_run, version); | 160 main_file, *manifest, is_deferred_run, version); |
161 | 161 |
162 RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED); | 162 RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED); |
163 | 163 |
164 base::LaunchOptions options; | 164 base::LaunchOptions options; |
(...skipping 20 matching lines...) Expand all Loading... |
185 // or repair the Google update installation. This is a last resort safety | 185 // or repair the Google update installation. This is a last resort safety |
186 // mechanism. | 186 // mechanism. |
187 // For user Chrome, recovery component just installs silently. For machine | 187 // For user Chrome, recovery component just installs silently. For machine |
188 // Chrome, elevation may be needed. If that happens, the installer will set | 188 // Chrome, elevation may be needed. If that happens, the installer will set |
189 // preference flag prefs::kRecoveryComponentNeedsElevation to request that. | 189 // preference flag prefs::kRecoveryComponentNeedsElevation to request that. |
190 // There is a global error service monitors this flag and will pop up | 190 // There is a global error service monitors this flag and will pop up |
191 // bubble if the flag is set to true. | 191 // bubble if the flag is set to true. |
192 // See chrome/browser/recovery/recovery_install_global_error.cc for details. | 192 // See chrome/browser/recovery/recovery_install_global_error.cc for details. |
193 class RecoveryComponentInstaller : public update_client::CrxInstaller { | 193 class RecoveryComponentInstaller : public update_client::CrxInstaller { |
194 public: | 194 public: |
195 RecoveryComponentInstaller(const Version& version, PrefService* prefs); | 195 RecoveryComponentInstaller(const base::Version& version, PrefService* prefs); |
196 | 196 |
197 // ComponentInstaller implementation: | 197 // ComponentInstaller implementation: |
198 void OnUpdateError(int error) override; | 198 void OnUpdateError(int error) override; |
199 | 199 |
200 bool Install(const base::DictionaryValue& manifest, | 200 bool Install(const base::DictionaryValue& manifest, |
201 const base::FilePath& unpack_path) override; | 201 const base::FilePath& unpack_path) override; |
202 | 202 |
203 bool GetInstalledFile(const std::string& file, | 203 bool GetInstalledFile(const std::string& file, |
204 base::FilePath* installed_file) override; | 204 base::FilePath* installed_file) override; |
205 | 205 |
206 bool Uninstall() override; | 206 bool Uninstall() override; |
207 | 207 |
208 private: | 208 private: |
209 ~RecoveryComponentInstaller() override {} | 209 ~RecoveryComponentInstaller() override {} |
210 | 210 |
211 bool RunInstallCommand(const base::CommandLine& cmdline, | 211 bool RunInstallCommand(const base::CommandLine& cmdline, |
212 const base::FilePath& installer_folder) const; | 212 const base::FilePath& installer_folder) const; |
213 | 213 |
214 Version current_version_; | 214 base::Version current_version_; |
215 PrefService* prefs_; | 215 PrefService* prefs_; |
216 }; | 216 }; |
217 | 217 |
218 void SimulateElevatedRecoveryHelper(PrefService* prefs) { | 218 void SimulateElevatedRecoveryHelper(PrefService* prefs) { |
219 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); | 219 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); |
220 } | 220 } |
221 | 221 |
222 void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) { | 222 void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) { |
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 223 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
224 Version version(prefs->GetString(prefs::kRecoveryComponentVersion)); | 224 base::Version version(prefs->GetString(prefs::kRecoveryComponentVersion)); |
225 if (!version.IsValid()) { | 225 if (!version.IsValid()) { |
226 NOTREACHED(); | 226 NOTREACHED(); |
227 return; | 227 return; |
228 } | 228 } |
229 | 229 |
230 update_client::CrxComponent recovery; | 230 update_client::CrxComponent recovery; |
231 recovery.name = "recovery"; | 231 recovery.name = "recovery"; |
232 recovery.installer = new RecoveryComponentInstaller(version, prefs); | 232 recovery.installer = new RecoveryComponentInstaller(version, prefs); |
233 recovery.version = version; | 233 recovery.version = version; |
234 recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); | 234 recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
235 if (!cus->RegisterComponent(recovery)) { | 235 if (!cus->RegisterComponent(recovery)) { |
236 NOTREACHED() << "Recovery component registration failed."; | 236 NOTREACHED() << "Recovery component registration failed."; |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 void RecoveryUpdateVersionHelper(const Version& version, PrefService* prefs) { | 240 void RecoveryUpdateVersionHelper( |
| 241 const base::Version& version, PrefService* prefs) { |
241 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 242 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
242 prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString()); | 243 prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString()); |
243 } | 244 } |
244 | 245 |
245 void SetPrefsForElevatedRecoveryInstall(const base::FilePath& unpack_path, | 246 void SetPrefsForElevatedRecoveryInstall(const base::FilePath& unpack_path, |
246 PrefService* prefs) { | 247 PrefService* prefs) { |
247 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 248 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
248 prefs->SetFilePath(prefs::kRecoveryComponentUnpackPath, unpack_path); | 249 prefs->SetFilePath(prefs::kRecoveryComponentUnpackPath, unpack_path); |
249 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); | 250 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); |
250 } | 251 } |
251 | 252 |
252 RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version, | 253 RecoveryComponentInstaller::RecoveryComponentInstaller( |
253 PrefService* prefs) | 254 const base::Version& version, PrefService* prefs) |
254 : current_version_(version), prefs_(prefs) { | 255 : current_version_(version), prefs_(prefs) { |
255 DCHECK(version.IsValid()); | 256 DCHECK(version.IsValid()); |
256 } | 257 } |
257 | 258 |
258 void RecoveryComponentInstaller::OnUpdateError(int error) { | 259 void RecoveryComponentInstaller::OnUpdateError(int error) { |
259 RecordRecoveryComponentUMAEvent(RCE_COMPONENT_DOWNLOAD_ERROR); | 260 RecordRecoveryComponentUMAEvent(RCE_COMPONENT_DOWNLOAD_ERROR); |
260 NOTREACHED() << "Recovery component update error: " << error; | 261 NOTREACHED() << "Recovery component update error: " << error; |
261 } | 262 } |
262 | 263 |
263 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 #endif // defined(OS_POSIX) | 334 #endif // defined(OS_POSIX) |
334 | 335 |
335 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, | 336 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, |
336 const base::FilePath& unpack_path) { | 337 const base::FilePath& unpack_path) { |
337 std::string name; | 338 std::string name; |
338 manifest.GetStringASCII("name", &name); | 339 manifest.GetStringASCII("name", &name); |
339 if (name != kRecoveryManifestName) | 340 if (name != kRecoveryManifestName) |
340 return false; | 341 return false; |
341 std::string proposed_version; | 342 std::string proposed_version; |
342 manifest.GetStringASCII("version", &proposed_version); | 343 manifest.GetStringASCII("version", &proposed_version); |
343 Version version(proposed_version.c_str()); | 344 base::Version version(proposed_version.c_str()); |
344 if (!version.IsValid()) | 345 if (!version.IsValid()) |
345 return false; | 346 return false; |
346 if (current_version_.CompareTo(version) >= 0) | 347 if (current_version_.CompareTo(version) >= 0) |
347 return false; | 348 return false; |
348 | 349 |
349 // Passed the basic tests. Copy the installation to a permanent directory. | 350 // Passed the basic tests. Copy the installation to a permanent directory. |
350 base::FilePath path; | 351 base::FilePath path; |
351 if (!PathService::Get(DIR_RECOVERY_BASE, &path)) | 352 if (!PathService::Get(DIR_RECOVERY_BASE, &path)) |
352 return false; | 353 return false; |
353 if (!base::PathExists(path) && !base::CreateDirectory(path)) | 354 if (!base::PathExists(path) && !base::CreateDirectory(path)) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 #endif // OS_WIN | 441 #endif // OS_WIN |
441 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); | 442 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); |
442 } | 443 } |
443 | 444 |
444 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { | 445 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { |
445 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 446 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
446 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); | 447 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); |
447 } | 448 } |
448 | 449 |
449 } // namespace component_updater | 450 } // namespace component_updater |
OLD | NEW |