| 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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #else // OS_LINUX, OS_MACOSX, etc. | 39 #else // OS_LINUX, OS_MACOSX, etc. |
| 40 FILE_PATH_LITERAL("ChromeRecovery"); | 40 FILE_PATH_LITERAL("ChromeRecovery"); |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 const char kRecoveryManifestName[] = "ChromeRecovery"; | 43 const char kRecoveryManifestName[] = "ChromeRecovery"; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 class RecoveryComponentInstaller : public ComponentInstaller { | 47 class RecoveryComponentInstaller : public ComponentInstaller { |
| 48 public: | 48 public: |
| 49 explicit RecoveryComponentInstaller(const Version& version, | 49 explicit RecoveryComponentInstaller(const base::Version& version, |
| 50 PrefService* prefs); | 50 PrefService* prefs); |
| 51 | 51 |
| 52 virtual ~RecoveryComponentInstaller() {} | 52 virtual ~RecoveryComponentInstaller() {} |
| 53 | 53 |
| 54 virtual void OnUpdateError(int error) OVERRIDE; | 54 virtual void OnUpdateError(int error) OVERRIDE; |
| 55 | 55 |
| 56 virtual bool Install(const base::DictionaryValue& manifest, | 56 virtual bool Install(const base::DictionaryValue& manifest, |
| 57 const base::FilePath& unpack_path) OVERRIDE; | 57 const base::FilePath& unpack_path) OVERRIDE; |
| 58 | 58 |
| 59 virtual bool GetInstalledFile(const std::string& file, | 59 virtual bool GetInstalledFile(const std::string& file, |
| 60 base::FilePath* installed_file) OVERRIDE; | 60 base::FilePath* installed_file) OVERRIDE; |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 Version current_version_; | 63 base::Version current_version_; |
| 64 PrefService* prefs_; | 64 PrefService* prefs_; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 void RecoveryRegisterHelper(ComponentUpdateService* cus, | 67 void RecoveryRegisterHelper(ComponentUpdateService* cus, |
| 68 PrefService* prefs) { | 68 PrefService* prefs) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 Version version(prefs->GetString(prefs::kRecoveryComponentVersion)); | 70 base::Version version(prefs->GetString(prefs::kRecoveryComponentVersion)); |
| 71 if (!version.IsValid()) { | 71 if (!version.IsValid()) { |
| 72 NOTREACHED(); | 72 NOTREACHED(); |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 | 75 |
| 76 CrxComponent recovery; | 76 CrxComponent recovery; |
| 77 recovery.name = "recovery"; | 77 recovery.name = "recovery"; |
| 78 recovery.installer = new RecoveryComponentInstaller(version, prefs); | 78 recovery.installer = new RecoveryComponentInstaller(version, prefs); |
| 79 recovery.version = version; | 79 recovery.version = version; |
| 80 recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); | 80 recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); |
| 81 if (cus->RegisterComponent(recovery) != ComponentUpdateService::kOk) { | 81 if (cus->RegisterComponent(recovery) != ComponentUpdateService::kOk) { |
| 82 NOTREACHED() << "Recovery component registration failed."; | 82 NOTREACHED() << "Recovery component registration failed."; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void RecoveryUpdateVersionHelper(const Version& version, PrefService* prefs) { | 86 void RecoveryUpdateVersionHelper(const base::Version& version, |
| 87 PrefService* prefs) { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 88 prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString()); | 89 prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString()); |
| 89 } | 90 } |
| 90 | 91 |
| 91 RecoveryComponentInstaller::RecoveryComponentInstaller( | 92 RecoveryComponentInstaller::RecoveryComponentInstaller( |
| 92 const Version& version, PrefService* prefs) | 93 const base::Version& version, PrefService* prefs) |
| 93 : current_version_(version), prefs_(prefs){ | 94 : current_version_(version), prefs_(prefs){ |
| 94 DCHECK(version.IsValid()); | 95 DCHECK(version.IsValid()); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void RecoveryComponentInstaller::OnUpdateError(int error) { | 98 void RecoveryComponentInstaller::OnUpdateError(int error) { |
| 98 NOTREACHED() << "Recovery component update error: " << error; | 99 NOTREACHED() << "Recovery component update error: " << error; |
| 99 } | 100 } |
| 100 | 101 |
| 101 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, | 102 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, |
| 102 const base::FilePath& unpack_path) { | 103 const base::FilePath& unpack_path) { |
| 103 std::string name; | 104 std::string name; |
| 104 manifest.GetStringASCII("name", &name); | 105 manifest.GetStringASCII("name", &name); |
| 105 if (name != kRecoveryManifestName) | 106 if (name != kRecoveryManifestName) |
| 106 return false; | 107 return false; |
| 107 std::string proposed_version; | 108 std::string proposed_version; |
| 108 manifest.GetStringASCII("version", &proposed_version); | 109 manifest.GetStringASCII("version", &proposed_version); |
| 109 Version version(proposed_version.c_str()); | 110 base::Version version(proposed_version.c_str()); |
| 110 if (!version.IsValid()) | 111 if (!version.IsValid()) |
| 111 return false; | 112 return false; |
| 112 if (current_version_.CompareTo(version) >= 0) | 113 if (current_version_.CompareTo(version) >= 0) |
| 113 return false; | 114 return false; |
| 114 base::FilePath main_file = unpack_path.Append(kRecoveryFileName); | 115 base::FilePath main_file = unpack_path.Append(kRecoveryFileName); |
| 115 if (!base::PathExists(main_file)) | 116 if (!base::PathExists(main_file)) |
| 116 return false; | 117 return false; |
| 117 // Passed the basic tests. The installation continues with the | 118 // Passed the basic tests. The installation continues with the |
| 118 // recovery component itself running from the temp directory. | 119 // recovery component itself running from the temp directory. |
| 119 CommandLine cmdline(main_file); | 120 CommandLine cmdline(main_file); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 147 BrowserThread::UI, | 148 BrowserThread::UI, |
| 148 FROM_HERE, | 149 FROM_HERE, |
| 149 base::Bind(&RecoveryRegisterHelper, cus, prefs), | 150 base::Bind(&RecoveryRegisterHelper, cus, prefs), |
| 150 base::TimeDelta::FromSeconds(6)); | 151 base::TimeDelta::FromSeconds(6)); |
| 151 #endif | 152 #endif |
| 152 } | 153 } |
| 153 | 154 |
| 154 void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) { | 155 void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) { |
| 155 registry->RegisterStringPref(prefs::kRecoveryComponentVersion, "0.0.0.0"); | 156 registry->RegisterStringPref(prefs::kRecoveryComponentVersion, "0.0.0.0"); |
| 156 } | 157 } |
| OLD | NEW |