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