| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/prefs/pref_registry_simple.h" | 17 #include "base/prefs/pref_registry_simple.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/component_updater/component_updater_service.h" | 22 #include "chrome/browser/component_updater/component_updater_service.h" |
| 23 #include "chrome/common/chrome_paths.h" | 23 #include "components/component_updater/common/component_updater_paths.h" |
| 24 #include "chrome/common/chrome_version_info.h" | 24 #include "components/component_updater/common/pref_names.h" |
| 25 #include "chrome/common/pref_names.h" | |
| 26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 27 | 26 |
| 28 using content::BrowserThread; | 27 using content::BrowserThread; |
| 29 | 28 |
| 30 namespace component_updater { | 29 namespace component_updater { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 // CRX hash. The extension id is: npdjjkjlcidkjlamlmmdelcjbcpdjocm. | 33 // CRX hash. The extension id is: npdjjkjlcidkjlamlmmdelcjbcpdjocm. |
| 35 const uint8 kSha2Hash[] = {0xdf, 0x39, 0x9a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c, | 34 const uint8 kSha2Hash[] = {0xdf, 0x39, 0x9a, 0x9b, 0x28, 0x3a, 0x9b, 0x0c, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 std::string proposed_version; | 110 std::string proposed_version; |
| 112 manifest.GetStringASCII("version", &proposed_version); | 111 manifest.GetStringASCII("version", &proposed_version); |
| 113 Version version(proposed_version.c_str()); | 112 Version version(proposed_version.c_str()); |
| 114 if (!version.IsValid()) | 113 if (!version.IsValid()) |
| 115 return false; | 114 return false; |
| 116 if (current_version_.CompareTo(version) >= 0) | 115 if (current_version_.CompareTo(version) >= 0) |
| 117 return false; | 116 return false; |
| 118 | 117 |
| 119 // Passed the basic tests. Copy the installation to a permanent directory. | 118 // Passed the basic tests. Copy the installation to a permanent directory. |
| 120 base::FilePath path; | 119 base::FilePath path; |
| 121 if (!PathService::Get(chrome::DIR_RECOVERY_BASE, &path)) | 120 if (!PathService::Get(DIR_RECOVERY_BASE, &path)) |
| 122 return false; | 121 return false; |
| 123 path = path.AppendASCII(version.GetString()); | 122 path = path.AppendASCII(version.GetString()); |
| 124 if (base::PathExists(path) && !base::DeleteFile(path, true)) | 123 if (base::PathExists(path) && !base::DeleteFile(path, true)) |
| 125 return false; | 124 return false; |
| 126 if (!base::Move(unpack_path, path)) { | 125 if (!base::Move(unpack_path, path)) { |
| 127 DVLOG(1) << "Recovery component move failed."; | 126 DVLOG(1) << "Recovery component move failed."; |
| 128 return false; | 127 return false; |
| 129 } | 128 } |
| 130 | 129 |
| 131 base::FilePath main_file = path.Append(kRecoveryFileName); | 130 base::FilePath main_file = path.Append(kRecoveryFileName); |
| 132 if (!base::PathExists(main_file)) | 131 if (!base::PathExists(main_file)) |
| 133 return false; | 132 return false; |
| 134 // Run the recovery component. | 133 // Run the recovery component. |
| 135 CommandLine cmdline(main_file); | 134 CommandLine cmdline(main_file); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 base::Bind(&RecoveryRegisterHelper, cus, prefs), | 167 base::Bind(&RecoveryRegisterHelper, cus, prefs), |
| 169 base::TimeDelta::FromSeconds(6)); | 168 base::TimeDelta::FromSeconds(6)); |
| 170 #endif | 169 #endif |
| 171 } | 170 } |
| 172 | 171 |
| 173 void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) { | 172 void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) { |
| 174 registry->RegisterStringPref(prefs::kRecoveryComponentVersion, "0.0.0.0"); | 173 registry->RegisterStringPref(prefs::kRecoveryComponentVersion, "0.0.0.0"); |
| 175 } | 174 } |
| 176 | 175 |
| 177 } // namespace component_updater | 176 } // namespace component_updater |
| OLD | NEW |