OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ |
6 #define CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
13 #include "base/version.h" | 15 #include "base/version.h" |
14 #include "chrome/browser/component_updater/component_updater_service.h" | 16 #include "chrome/browser/component_updater/component_updater_service.h" |
15 | 17 |
16 namespace base { | 18 namespace base { |
17 class DictionaryValue; | 19 class DictionaryValue; |
18 class FilePath; | 20 class FilePath; |
| 21 class SequencedTaskRunner; |
| 22 class SingleThreadTaskRunner; |
19 } // namespace base | 23 } // namespace base |
20 | 24 |
21 namespace component_updater { | 25 namespace component_updater { |
22 | 26 |
23 // Components should use a DefaultComponentInstaller by defining a class that | 27 // Components should use a DefaultComponentInstaller by defining a class that |
24 // implements the members of ComponentInstallerTraits, and then registering a | 28 // implements the members of ComponentInstallerTraits, and then registering a |
25 // DefaultComponentInstaller that has been constructed with an instance of that | 29 // DefaultComponentInstaller that has been constructed with an instance of that |
26 // class. | 30 // class. |
27 class ComponentInstallerTraits { | 31 class ComponentInstallerTraits { |
28 public: | 32 public: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 73 |
70 // Returns the human-readable name of the component. | 74 // Returns the human-readable name of the component. |
71 virtual std::string GetName() const = 0; | 75 virtual std::string GetName() const = 0; |
72 }; | 76 }; |
73 | 77 |
74 // A DefaultComponentInstaller is intended to be final, and not derived from. | 78 // A DefaultComponentInstaller is intended to be final, and not derived from. |
75 // Customization must be provided by passing a ComponentInstallerTraits object | 79 // Customization must be provided by passing a ComponentInstallerTraits object |
76 // to the constructor. | 80 // to the constructor. |
77 class DefaultComponentInstaller : public ComponentInstaller { | 81 class DefaultComponentInstaller : public ComponentInstaller { |
78 public: | 82 public: |
79 explicit DefaultComponentInstaller( | 83 DefaultComponentInstaller( |
80 scoped_ptr<ComponentInstallerTraits> installer_traits); | 84 scoped_ptr<ComponentInstallerTraits> installer_traits); |
81 | 85 |
82 // Registers the component for update checks and installs. | 86 // Registers the component for update checks and installs. |
83 void Register(ComponentUpdateService* cus); | 87 void Register(ComponentUpdateService* cus); |
84 | 88 |
85 // Overridden from ComponentInstaller: | 89 // Overridden from ComponentInstaller: |
86 virtual void OnUpdateError(int error) OVERRIDE; | 90 virtual void OnUpdateError(int error) OVERRIDE; |
87 virtual bool Install(const base::DictionaryValue& manifest, | 91 virtual bool Install(const base::DictionaryValue& manifest, |
88 const base::FilePath& unpack_path) OVERRIDE; | 92 const base::FilePath& unpack_path) OVERRIDE; |
89 virtual bool GetInstalledFile(const std::string& file, | 93 virtual bool GetInstalledFile(const std::string& file, |
90 base::FilePath* installed_file) OVERRIDE; | 94 base::FilePath* installed_file) OVERRIDE; |
91 | 95 |
92 virtual ~DefaultComponentInstaller(); | 96 virtual ~DefaultComponentInstaller(); |
93 | 97 |
94 private: | 98 private: |
95 base::FilePath GetInstallDirectory(); | 99 base::FilePath GetInstallDirectory(); |
96 bool InstallHelper(const base::DictionaryValue& manifest, | 100 bool InstallHelper(const base::DictionaryValue& manifest, |
97 const base::FilePath& unpack_path, | 101 const base::FilePath& unpack_path, |
98 const base::FilePath& install_path); | 102 const base::FilePath& install_path); |
99 void StartRegistration(ComponentUpdateService* cus); | 103 void StartRegistration(ComponentUpdateService* cus); |
100 void FinishRegistration(ComponentUpdateService* cus); | 104 void FinishRegistration(ComponentUpdateService* cus); |
101 | 105 |
102 base::Version current_version_; | 106 base::Version current_version_; |
103 std::string current_fingerprint_; | 107 std::string current_fingerprint_; |
104 scoped_ptr<base::DictionaryValue> current_manifest_; | 108 scoped_ptr<base::DictionaryValue> current_manifest_; |
105 scoped_ptr<ComponentInstallerTraits> installer_traits_; | 109 scoped_ptr<ComponentInstallerTraits> installer_traits_; |
| 110 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 111 |
| 112 // Used to post responses back to the main thread. Initialized on the main |
| 113 // loop but accessed from the task runner. |
| 114 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 115 |
| 116 base::ThreadChecker thread_checker_; |
106 | 117 |
107 DISALLOW_COPY_AND_ASSIGN(DefaultComponentInstaller); | 118 DISALLOW_COPY_AND_ASSIGN(DefaultComponentInstaller); |
108 }; | 119 }; |
109 | 120 |
110 } // namespace component_updater | 121 } // namespace component_updater |
111 | 122 |
112 #endif // CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ | 123 #endif // CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_ |
OLD | NEW |