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