| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ | 5 #ifndef COMPONENTS_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ |
| 6 #define COMPONENTS_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ | 6 #define COMPONENTS_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "base/version.h" | 19 #include "base/version.h" |
| 19 #include "components/update_client/update_client.h" | 20 #include "components/update_client/update_client.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class FilePath; | 23 class FilePath; |
| 23 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
| 24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 25 } // namespace base | 26 } // namespace base |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // ComponentReady is called in two cases: | 64 // ComponentReady is called in two cases: |
| 64 // 1) After an installation is successfully completed. | 65 // 1) After an installation is successfully completed. |
| 65 // 2) During component registration if the component is already installed. | 66 // 2) During component registration if the component is already installed. |
| 66 // In both cases the install is verified before this is called. This method | 67 // In both cases the install is verified before this is called. This method |
| 67 // is guaranteed to be called before any observers of the component are | 68 // is guaranteed to be called before any observers of the component are |
| 68 // notified of a successful install, and is meant to support follow-on work | 69 // notified of a successful install, and is meant to support follow-on work |
| 69 // such as updating paths elsewhere in Chrome. Called on the UI thread. | 70 // such as updating paths elsewhere in Chrome. Called on the UI thread. |
| 70 // |version| is the version of the component. | 71 // |version| is the version of the component. |
| 71 // |install_dir| is the path to the install directory for this version. | 72 // |install_dir| is the path to the install directory for this version. |
| 72 // |manifest| is the manifest for this version of the component. | 73 // |manifest| is the manifest for this version of the component. |
| 73 virtual void ComponentReady(const base::Version& version, | 74 virtual void ComponentReady( |
| 74 const base::FilePath& install_dir, | 75 const base::Version& version, |
| 75 scoped_ptr<base::DictionaryValue> manifest) = 0; | 76 const base::FilePath& install_dir, |
| 77 std::unique_ptr<base::DictionaryValue> manifest) = 0; |
| 76 | 78 |
| 77 // Returns the directory that the installer will place versioned installs of | 79 // Returns the directory that the installer will place versioned installs of |
| 78 // the component into. | 80 // the component into. |
| 79 virtual base::FilePath GetBaseDirectory() const = 0; | 81 virtual base::FilePath GetBaseDirectory() const = 0; |
| 80 | 82 |
| 81 // Returns the component's SHA2 hash as raw bytes. | 83 // Returns the component's SHA2 hash as raw bytes. |
| 82 virtual void GetHash(std::vector<uint8_t>* hash) const = 0; | 84 virtual void GetHash(std::vector<uint8_t>* hash) const = 0; |
| 83 | 85 |
| 84 // Returns the human-readable name of the component. | 86 // Returns the human-readable name of the component. |
| 85 virtual std::string GetName() const = 0; | 87 virtual std::string GetName() const = 0; |
| 86 | 88 |
| 87 // Returns the additional parameters to be used in the update checks for | 89 // Returns the additional parameters to be used in the update checks for |
| 88 // this component. A compatible server may use this attribute to negotiate | 90 // this component. A compatible server may use this attribute to negotiate |
| 89 // special update rules when issuing an update response. | 91 // special update rules when issuing an update response. |
| 90 // The current implementation restricts ap to ^([-+_=a-zA-Z0-9]{0,256})$ | 92 // The current implementation restricts ap to ^([-+_=a-zA-Z0-9]{0,256})$ |
| 91 virtual std::string GetAp() const = 0; | 93 virtual std::string GetAp() const = 0; |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 // A DefaultComponentInstaller is intended to be final, and not derived from. | 96 // A DefaultComponentInstaller is intended to be final, and not derived from. |
| 95 // Customization must be provided by passing a ComponentInstallerTraits object | 97 // Customization must be provided by passing a ComponentInstallerTraits object |
| 96 // to the constructor. | 98 // to the constructor. |
| 97 class DefaultComponentInstaller : public update_client::CrxInstaller { | 99 class DefaultComponentInstaller : public update_client::CrxInstaller { |
| 98 public: | 100 public: |
| 99 DefaultComponentInstaller( | 101 DefaultComponentInstaller( |
| 100 scoped_ptr<ComponentInstallerTraits> installer_traits); | 102 std::unique_ptr<ComponentInstallerTraits> installer_traits); |
| 101 | 103 |
| 102 // Registers the component for update checks and installs. | 104 // Registers the component for update checks and installs. |
| 103 // The passed |callback| will be called once the initial check for installed | 105 // The passed |callback| will be called once the initial check for installed |
| 104 // versions is done and the component has been registered. | 106 // versions is done and the component has been registered. |
| 105 void Register(ComponentUpdateService* cus, const base::Closure& callback); | 107 void Register(ComponentUpdateService* cus, const base::Closure& callback); |
| 106 | 108 |
| 107 // Overridden from ComponentInstaller: | 109 // Overridden from ComponentInstaller: |
| 108 void OnUpdateError(int error) override; | 110 void OnUpdateError(int error) override; |
| 109 bool Install(const base::DictionaryValue& manifest, | 111 bool Install(const base::DictionaryValue& manifest, |
| 110 const base::FilePath& unpack_path) override; | 112 const base::FilePath& unpack_path) override; |
| 111 bool GetInstalledFile(const std::string& file, | 113 bool GetInstalledFile(const std::string& file, |
| 112 base::FilePath* installed_file) override; | 114 base::FilePath* installed_file) override; |
| 113 bool Uninstall() override; | 115 bool Uninstall() override; |
| 114 | 116 |
| 115 private: | 117 private: |
| 116 ~DefaultComponentInstaller() override; | 118 ~DefaultComponentInstaller() override; |
| 117 | 119 |
| 118 base::FilePath GetInstallDirectory(); | 120 base::FilePath GetInstallDirectory(); |
| 119 bool InstallHelper(const base::DictionaryValue& manifest, | 121 bool InstallHelper(const base::DictionaryValue& manifest, |
| 120 const base::FilePath& unpack_path, | 122 const base::FilePath& unpack_path, |
| 121 const base::FilePath& install_path); | 123 const base::FilePath& install_path); |
| 122 void StartRegistration(ComponentUpdateService* cus); | 124 void StartRegistration(ComponentUpdateService* cus); |
| 123 void FinishRegistration(ComponentUpdateService* cus, | 125 void FinishRegistration(ComponentUpdateService* cus, |
| 124 const base::Closure& callback); | 126 const base::Closure& callback); |
| 125 void ComponentReady(scoped_ptr<base::DictionaryValue> manifest); | 127 void ComponentReady(std::unique_ptr<base::DictionaryValue> manifest); |
| 126 void UninstallOnTaskRunner(); | 128 void UninstallOnTaskRunner(); |
| 127 | 129 |
| 128 base::Version current_version_; | 130 base::Version current_version_; |
| 129 std::string current_fingerprint_; | 131 std::string current_fingerprint_; |
| 130 scoped_ptr<base::DictionaryValue> current_manifest_; | 132 std::unique_ptr<base::DictionaryValue> current_manifest_; |
| 131 scoped_ptr<ComponentInstallerTraits> installer_traits_; | 133 std::unique_ptr<ComponentInstallerTraits> installer_traits_; |
| 132 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 134 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 133 | 135 |
| 134 // Used to post responses back to the main thread. Initialized on the main | 136 // Used to post responses back to the main thread. Initialized on the main |
| 135 // loop but accessed from the task runner. | 137 // loop but accessed from the task runner. |
| 136 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 138 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 137 | 139 |
| 138 base::ThreadChecker thread_checker_; | 140 base::ThreadChecker thread_checker_; |
| 139 | 141 |
| 140 DISALLOW_COPY_AND_ASSIGN(DefaultComponentInstaller); | 142 DISALLOW_COPY_AND_ASSIGN(DefaultComponentInstaller); |
| 141 }; | 143 }; |
| 142 | 144 |
| 143 } // namespace component_updater | 145 } // namespace component_updater |
| 144 | 146 |
| 145 #endif // COMPONENTS_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ | 147 #endif // COMPONENTS_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ |
| OLD | NEW |