Chromium Code Reviews| Index: chrome/browser/component_updater/recovery_component_installer.cc |
| diff --git a/chrome/browser/component_updater/recovery_component_installer.cc b/chrome/browser/component_updater/recovery_component_installer.cc |
| index 4baa3666db5b1d6e3a8e2e4ab269c5ae4fb8d7f7..4befd240d036770da9a5ba5fd95f8356c61b2808 100644 |
| --- a/chrome/browser/component_updater/recovery_component_installer.cc |
| +++ b/chrome/browser/component_updater/recovery_component_installer.cc |
| @@ -20,9 +20,6 @@ |
| #include "base/strings/string_util.h" |
| #include "base/values.h" |
| #include "chrome/browser/component_updater/component_updater_service.h" |
| -#include "chrome/common/chrome_paths.h" |
| -#include "chrome/common/chrome_version_info.h" |
| -#include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| using content::BrowserThread; |
| @@ -47,12 +44,17 @@ const base::FilePath::CharType kRecoveryFileName[] = |
| const char kRecoveryManifestName[] = "ChromeRecovery"; |
| +// String that represents the recovery component last downloaded version. This |
| +// takes the usual 'a.b.c.d' notation. |
| +const char kRecoveryComponentVersionPrefName[] = "recovery_component.version"; |
| + |
| } // namespace |
| class RecoveryComponentInstaller : public ComponentInstaller { |
| public: |
| explicit RecoveryComponentInstaller(const Version& version, |
| - PrefService* prefs); |
| + PrefService* prefs, |
| + const base::FilePath& base_dir); |
| virtual ~RecoveryComponentInstaller() {} |
| @@ -67,11 +69,13 @@ class RecoveryComponentInstaller : public ComponentInstaller { |
| private: |
| Version current_version_; |
| PrefService* prefs_; |
| + base::FilePath base_dir_; |
| }; |
| -void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) { |
| +void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs, |
| + const base::FilePath& base_dir) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - Version version(prefs->GetString(prefs::kRecoveryComponentVersion)); |
|
blundell
2014/06/17 17:26:43
This pref could move into the component_updater co
tommycli
2014/06/17 19:01:57
Done.
|
| + Version version(prefs->GetString(kRecoveryComponentVersionPrefName)); |
| if (!version.IsValid()) { |
| NOTREACHED(); |
| return; |
| @@ -79,7 +83,8 @@ void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) { |
| CrxComponent recovery; |
| recovery.name = "recovery"; |
| - recovery.installer = new RecoveryComponentInstaller(version, prefs); |
| + recovery.installer = new RecoveryComponentInstaller(version, prefs, |
| + base_dir); |
| recovery.version = version; |
| recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
| if (cus->RegisterComponent(recovery) != ComponentUpdateService::kOk) { |
| @@ -89,12 +94,16 @@ void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) { |
| void RecoveryUpdateVersionHelper(const Version& version, PrefService* prefs) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString()); |
| + prefs->SetString(kRecoveryComponentVersionPrefName, version.GetString()); |
| } |
| -RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version, |
| - PrefService* prefs) |
| - : current_version_(version), prefs_(prefs) { |
| +RecoveryComponentInstaller::RecoveryComponentInstaller( |
| + const Version& version, |
| + PrefService* prefs, |
| + const base::FilePath& base_dir) |
| + : current_version_(version), |
| + prefs_(prefs), |
| + base_dir_(base_dir) { |
| DCHECK(version.IsValid()); |
| } |
| @@ -117,10 +126,8 @@ bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, |
| return false; |
| // Passed the basic tests. Copy the installation to a permanent directory. |
| - base::FilePath path; |
| - if (!PathService::Get(chrome::DIR_RECOVERY_BASE, &path)) |
| - return false; |
| - path = path.AppendASCII(version.GetString()); |
| + base::FilePath path = |
| + base_dir_.AppendASCII(version.GetString()); |
| if (base::PathExists(path) && !base::DeleteFile(path, true)) |
| return false; |
| if (!base::Move(unpack_path, path)) { |
| @@ -158,20 +165,21 @@ bool RecoveryComponentInstaller::GetInstalledFile( |
| } |
| void RegisterRecoveryComponent(ComponentUpdateService* cus, |
| - PrefService* prefs) { |
| + PrefService* prefs, |
| + const base::FilePath& base_dir) { |
| #if !defined(OS_CHROMEOS) |
| // We delay execute the registration because we are not required in |
| // the critical path during browser startup. |
| BrowserThread::PostDelayedTask( |
| BrowserThread::UI, |
| FROM_HERE, |
| - base::Bind(&RecoveryRegisterHelper, cus, prefs), |
| + base::Bind(&RecoveryRegisterHelper, cus, prefs, base_dir), |
| base::TimeDelta::FromSeconds(6)); |
| #endif |
| } |
| void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) { |
| - registry->RegisterStringPref(prefs::kRecoveryComponentVersion, "0.0.0.0"); |
| + registry->RegisterStringPref(kRecoveryComponentVersionPrefName, "0.0.0.0"); |
| } |
| } // namespace component_updater |