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

Side by Side Diff: chrome/browser/component_updater/recovery_component_installer.cc

Issue 2479633003: Makes the component installers return a Result instead of a bool. (Closed)
Patch Set: rebase Created 4 years, 1 month 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/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>
11 11
12 #include "base/base_paths.h" 12 #include "base/base_paths.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
17 #include "base/json/json_file_value_serializer.h" 18 #include "base/json/json_file_value_serializer.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
20 #include "base/path_service.h" 21 #include "base/path_service.h"
21 #include "base/process/kill.h" 22 #include "base/process/kill.h"
22 #include "base/process/launch.h" 23 #include "base/process/launch.h"
23 #include "base/process/process.h" 24 #include "base/process/process.h"
24 #include "base/threading/worker_pool.h" 25 #include "base/threading/worker_pool.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #if defined(OS_WIN) 29 #if defined(OS_WIN)
29 #include "chrome/installer/util/install_util.h" 30 #include "chrome/installer/util/install_util.h"
30 #endif // OS_WIN 31 #endif // OS_WIN
31 #include "components/component_updater/component_updater_paths.h" 32 #include "components/component_updater/component_updater_paths.h"
32 #include "components/component_updater/component_updater_service.h" 33 #include "components/component_updater/component_updater_service.h"
33 #include "components/component_updater/pref_names.h" 34 #include "components/component_updater/pref_names.h"
34 #include "components/prefs/pref_registry_simple.h" 35 #include "components/prefs/pref_registry_simple.h"
35 #include "components/prefs/pref_service.h" 36 #include "components/prefs/pref_service.h"
36 #include "components/update_client/update_client.h" 37 #include "components/update_client/update_client.h"
38 #include "components/update_client/utils.h"
37 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
38 40
39 using content::BrowserThread; 41 using content::BrowserThread;
40 42
41 namespace component_updater { 43 namespace component_updater {
42 44
43 namespace { 45 namespace {
44 46
45 // CRX hash. The extension id is: npdjjkjlcidkjlamlmmdelcjbcpdjocm. 47 // CRX hash. The extension id is: npdjjkjlcidkjlamlmmdelcjbcpdjocm.
46 const uint8_t kSha2Hash[] = {0xdf, 0x39, 0x9a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c, 48 const uint8_t kSha2Hash[] = {0xdf, 0x39, 0x9a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // There is a global error service monitors this flag and will pop up 195 // There is a global error service monitors this flag and will pop up
194 // bubble if the flag is set to true. 196 // bubble if the flag is set to true.
195 // See chrome/browser/recovery/recovery_install_global_error.cc for details. 197 // See chrome/browser/recovery/recovery_install_global_error.cc for details.
196 class RecoveryComponentInstaller : public update_client::CrxInstaller { 198 class RecoveryComponentInstaller : public update_client::CrxInstaller {
197 public: 199 public:
198 RecoveryComponentInstaller(const base::Version& version, PrefService* prefs); 200 RecoveryComponentInstaller(const base::Version& version, PrefService* prefs);
199 201
200 // ComponentInstaller implementation: 202 // ComponentInstaller implementation:
201 void OnUpdateError(int error) override; 203 void OnUpdateError(int error) override;
202 204
203 bool Install(const base::DictionaryValue& manifest, 205 update_client::CrxInstaller::Result Install(
204 const base::FilePath& unpack_path) override; 206 const base::DictionaryValue& manifest,
207 const base::FilePath& unpack_path) override;
205 208
206 bool GetInstalledFile(const std::string& file, 209 bool GetInstalledFile(const std::string& file,
207 base::FilePath* installed_file) override; 210 base::FilePath* installed_file) override;
208 211
209 bool Uninstall() override; 212 bool Uninstall() override;
210 213
211 private: 214 private:
212 ~RecoveryComponentInstaller() override {} 215 ~RecoveryComponentInstaller() override {}
213 216
217 bool DoInstall(const base::DictionaryValue& manifest,
218 const base::FilePath& unpack_path);
219
214 bool RunInstallCommand(const base::CommandLine& cmdline, 220 bool RunInstallCommand(const base::CommandLine& cmdline,
215 const base::FilePath& installer_folder) const; 221 const base::FilePath& installer_folder) const;
216 222
217 base::Version current_version_; 223 base::Version current_version_;
218 PrefService* prefs_; 224 PrefService* prefs_;
219 }; 225 };
220 226
221 void SimulateElevatedRecoveryHelper(PrefService* prefs) { 227 void SimulateElevatedRecoveryHelper(PrefService* prefs) {
222 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); 228 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true);
223 } 229 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 return false; 346 return false;
341 const int kExecutableMask = base::FILE_PERMISSION_EXECUTE_BY_USER | 347 const int kExecutableMask = base::FILE_PERMISSION_EXECUTE_BY_USER |
342 base::FILE_PERMISSION_EXECUTE_BY_GROUP | 348 base::FILE_PERMISSION_EXECUTE_BY_GROUP |
343 base::FILE_PERMISSION_EXECUTE_BY_OTHERS; 349 base::FILE_PERMISSION_EXECUTE_BY_OTHERS;
344 if ((permissions & kExecutableMask) == kExecutableMask) 350 if ((permissions & kExecutableMask) == kExecutableMask)
345 return true; // No need to update 351 return true; // No need to update
346 return base::SetPosixFilePermissions(path, permissions | kExecutableMask); 352 return base::SetPosixFilePermissions(path, permissions | kExecutableMask);
347 } 353 }
348 #endif // defined(OS_POSIX) 354 #endif // defined(OS_POSIX)
349 355
350 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, 356 update_client::CrxInstaller::Result RecoveryComponentInstaller::Install(
351 const base::FilePath& unpack_path) { 357 const base::DictionaryValue& manifest,
358 const base::FilePath& unpack_path) {
359 return update_client::InstallFunctionWrapper(
360 base::Bind(&RecoveryComponentInstaller::DoInstall, base::Unretained(this),
361 base::ConstRef(manifest), base::ConstRef(unpack_path)));
362 }
363
364 bool RecoveryComponentInstaller::DoInstall(
365 const base::DictionaryValue& manifest,
366 const base::FilePath& unpack_path) {
352 std::string name; 367 std::string name;
353 manifest.GetStringASCII("name", &name); 368 manifest.GetStringASCII("name", &name);
354 if (name != kRecoveryManifestName) 369 if (name != kRecoveryManifestName)
355 return false; 370 return false;
356 std::string proposed_version; 371 std::string proposed_version;
357 manifest.GetStringASCII("version", &proposed_version); 372 manifest.GetStringASCII("version", &proposed_version);
358 base::Version version(proposed_version.c_str()); 373 base::Version version(proposed_version.c_str());
359 if (!version.IsValid()) 374 if (!version.IsValid())
360 return false; 375 return false;
361 if (current_version_.CompareTo(version) >= 0) 376 if (current_version_.CompareTo(version) >= 0)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 #endif // OS_WIN 470 #endif // OS_WIN
456 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); 471 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
457 } 472 }
458 473
459 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { 474 void DeclinedElevatedRecoveryInstall(PrefService* prefs) {
460 DCHECK_CURRENTLY_ON(BrowserThread::UI); 475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
461 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); 476 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
462 } 477 }
463 478
464 } // namespace component_updater 479 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698