OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_UPDATE_CLIENT_UPDATE_CLIENT_H_ | 5 #ifndef COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_ |
6 #define COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_ | 6 #define COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/memory/ref_counted.h" |
12 #include "base/version.h" | 13 #include "base/version.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class DictionaryValue; | 16 class DictionaryValue; |
16 class FilePath; | 17 class FilePath; |
17 } | 18 } |
18 | 19 |
19 namespace update_client { | 20 namespace update_client { |
20 | 21 |
21 // Component specific installers must derive from this class and implement | 22 // Component specific installers must derive from this class and implement |
22 // OnUpdateError() and Install(). A valid instance of this class must be | 23 // OnUpdateError() and Install(). A valid instance of this class must be |
23 // given to ComponentUpdateService::RegisterComponent(). | 24 // given to ComponentUpdateService::RegisterComponent(). |
24 class ComponentInstaller { | 25 class ComponentInstaller |
| 26 : public base::RefCountedThreadSafe<ComponentInstaller> { |
25 public: | 27 public: |
26 // Called by the component updater on the main thread when there was a | 28 // Called by the component updater on the main thread when there was a |
27 // problem unpacking or verifying the component. |error| is a non-zero | 29 // problem unpacking or verifying the component. |error| is a non-zero |
28 // value which is only meaningful to the component updater. | 30 // value which is only meaningful to the component updater. |
29 virtual void OnUpdateError(int error) = 0; | 31 virtual void OnUpdateError(int error) = 0; |
30 | 32 |
31 // Called by the component updater when a component has been unpacked | 33 // Called by the component updater when a component has been unpacked |
32 // and is ready to be installed. |manifest| contains the CRX manifest | 34 // and is ready to be installed. |manifest| contains the CRX manifest |
33 // json dictionary and |unpack_path| contains the temporary directory | 35 // json dictionary and |unpack_path| contains the temporary directory |
34 // with all the unpacked CRX files. This method may be called from | 36 // with all the unpacked CRX files. This method may be called from |
35 // a thread other than the main thread. | 37 // a thread other than the main thread. |
36 virtual bool Install(const base::DictionaryValue& manifest, | 38 virtual bool Install(const base::DictionaryValue& manifest, |
37 const base::FilePath& unpack_path) = 0; | 39 const base::FilePath& unpack_path) = 0; |
38 | 40 |
39 // Set |installed_file| to the full path to the installed |file|. |file| is | 41 // Set |installed_file| to the full path to the installed |file|. |file| is |
40 // the filename of the file in this component's CRX. Returns false if this is | 42 // the filename of the file in this component's CRX. Returns false if this is |
41 // not possible (the file has been removed or modified, or its current | 43 // not possible (the file has been removed or modified, or its current |
42 // location is unknown). Otherwise, returns true. | 44 // location is unknown). Otherwise, returns true. |
43 virtual bool GetInstalledFile(const std::string& file, | 45 virtual bool GetInstalledFile(const std::string& file, |
44 base::FilePath* installed_file) = 0; | 46 base::FilePath* installed_file) = 0; |
45 | 47 |
| 48 protected: |
| 49 friend class base::RefCountedThreadSafe<ComponentInstaller>; |
| 50 |
46 virtual ~ComponentInstaller() {} | 51 virtual ~ComponentInstaller() {} |
47 }; | 52 }; |
48 | 53 |
49 // Describes a particular component that can be installed or updated. This | 54 // Describes a particular component that can be installed or updated. This |
50 // structure is required to register a component with the component updater. | 55 // structure is required to register a component with the component updater. |
51 // |pk_hash| is the SHA256 hash of the component's public key. If the component | 56 // |pk_hash| is the SHA256 hash of the component's public key. If the component |
52 // is to be installed then version should be "0" or "0.0", else it should be | 57 // is to be installed then version should be "0" or "0.0", else it should be |
53 // the current version. |fingerprint|, and |name| are optional. | 58 // the current version. |fingerprint|, and |name| are optional. |
54 // |allow_background_download| specifies that the component can be background | 59 // |allow_background_download| specifies that the component can be background |
55 // downloaded in some cases. The default for this value is |true| and the value | 60 // downloaded in some cases. The default for this value is |true| and the value |
56 // can be overriden at the registration time. This is a temporary change until | 61 // can be overriden at the registration time. This is a temporary change until |
57 // the issue 340448 is resolved. | 62 // the issue 340448 is resolved. |
58 struct CrxComponent { | 63 struct CrxComponent { |
59 std::vector<uint8_t> pk_hash; | 64 std::vector<uint8_t> pk_hash; |
60 ComponentInstaller* installer; | 65 scoped_refptr<ComponentInstaller> installer; |
61 Version version; | 66 Version version; |
62 std::string fingerprint; | 67 std::string fingerprint; |
63 std::string name; | 68 std::string name; |
64 bool allow_background_download; | 69 bool allow_background_download; |
65 CrxComponent(); | 70 CrxComponent(); |
66 ~CrxComponent(); | 71 ~CrxComponent(); |
67 }; | 72 }; |
68 | 73 |
69 } // namespace update_client | 74 } // namespace update_client |
70 | 75 |
71 #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_ | 76 #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_ |
OLD | NEW |