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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ |
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/sequenced_task_runner.h" | |
15 | 18 |
16 namespace component_updater { | 19 namespace component_updater { |
17 | 20 |
18 class ComponentInstaller; | 21 class ComponentInstaller; |
19 class ComponentPatcher; | 22 class ComponentPatcher; |
20 | 23 |
21 // Deserializes the CRX manifest. The top level must be a dictionary. | 24 // Deserializes the CRX manifest. The top level must be a dictionary. |
22 scoped_ptr<base::DictionaryValue> ReadManifest( | 25 scoped_ptr<base::DictionaryValue> ReadManifest( |
23 const base::FilePath& unpack_path); | 26 const base::FilePath& unpack_path); |
24 | 27 |
25 // In charge of unpacking the component CRX package and verifying that it is | 28 // In charge of unpacking the component CRX package and verifying that it is |
26 // well formed and the cryptographic signature is correct. If there is no | 29 // well formed and the cryptographic signature is correct. If there is no |
27 // error the component specific installer will be invoked to proceed with | 30 // error the component specific installer will be invoked to proceed with |
28 // the component installation or update. | 31 // the component installation or update. |
29 // | 32 // |
30 // This class should be used only by the component updater. It is inspired | 33 // This class should be used only by the component updater. It is inspired by |
31 // and overlaps with code in the extension's SandboxedUnpacker. | 34 // and overlaps with code in the extension's SandboxedUnpacker. |
32 // The main differences are: | 35 // The main differences are: |
33 // - The public key hash is full SHA256. | 36 // - The public key hash is full SHA256. |
34 // - Does not use a sandboxed unpacker. A valid component is fully trusted. | 37 // - Does not use a sandboxed unpacker. A valid component is fully trusted. |
35 // - The manifest can have different attributes and resources are not | 38 // - The manifest can have different attributes and resources are not |
36 // transcoded. | 39 // transcoded. |
40 // | |
41 // If the CRX is a delta CRX, the flow is: | |
42 // [ComponentUpdater] [ComponentPatcher] | |
43 // Unpack | |
44 // \_ Verify | |
45 // \_ Unzip | |
46 // \_ BeginPatching ---> DifferentialUpdatePatch | |
47 // ... | |
48 // DonePatching <----------- ... | |
49 // \_ Install | |
50 // \_ Finish | |
51 // | |
52 // For a full CRX, the flow is: | |
53 // [ComponentUpdater] | |
54 // Unpack | |
55 // \_ Verify | |
56 // \_ Unzip | |
57 // \_ BeginPatching | |
Sorin Jianu
2014/01/25 02:30:21
could we do the same outflow as above, and say tha
waffles
2014/01/28 21:06:31
Discussed, we decided not to change it.
| |
58 // | | |
59 // V | |
60 // DonePatching | |
61 // \_ Install | |
62 // \_ Finish | |
63 // | |
64 // In both cases, if there is an error at any point, the remaining steps will | |
65 // be skipped and Finish will be called. | |
37 class ComponentUnpacker { | 66 class ComponentUnpacker { |
38 public: | 67 public: |
39 // Possible error conditions. | 68 // Possible error conditions. |
40 // Add only to the bottom of this enum; the order must be kept stable. | 69 // Add only to the bottom of this enum; the order must be kept stable. |
41 enum Error { | 70 enum Error { |
42 kNone, | 71 kNone, |
43 kInvalidParams, | 72 kInvalidParams, |
44 kInvalidFile, | 73 kInvalidFile, |
45 kUnzipPathError, | 74 kUnzipPathError, |
46 kUnzipFailed, | 75 kUnzipFailed, |
47 kNoManifest, | 76 kNoManifest, |
48 kBadManifest, | 77 kBadManifest, |
49 kBadExtension, | 78 kBadExtension, |
50 kInvalidId, | 79 kInvalidId, |
51 kInstallerError, | 80 kInstallerError, |
52 kIoError, | 81 kIoError, |
53 kDeltaVerificationFailure, | 82 kDeltaVerificationFailure, |
54 kDeltaBadCommands, | 83 kDeltaBadCommands, |
55 kDeltaUnsupportedCommand, | 84 kDeltaUnsupportedCommand, |
56 kDeltaOperationFailure, | 85 kDeltaOperationFailure, |
57 kDeltaPatchProcessFailure, | 86 kDeltaPatchProcessFailure, |
58 kDeltaMissingExistingFile, | 87 kDeltaMissingExistingFile, |
59 kFingerprintWriteFailed, | 88 kFingerprintWriteFailed, |
60 }; | 89 }; |
61 // Unpacks, verifies and calls the installer. |pk_hash| is the expected | 90 |
62 // public key SHA256 hash. |path| is the current location of the CRX. | 91 // Constructs an unpacker for a specific component unpacking operation. |
92 // |pk_hash| is the expected/ public key SHA256 hash. |path| is the current | |
93 // location of the CRX. | |
63 ComponentUnpacker(const std::vector<uint8>& pk_hash, | 94 ComponentUnpacker(const std::vector<uint8>& pk_hash, |
64 const base::FilePath& path, | 95 const base::FilePath& path, |
65 const std::string& fingerprint, | 96 const std::string& fingerprint, |
66 ComponentPatcher* patcher, | 97 ComponentPatcher* patcher, |
67 ComponentInstaller* installer); | 98 ComponentInstaller* installer, |
99 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
68 | 100 |
69 // If something went wrong during unpacking or installer invocation, the | 101 virtual ~ComponentUnpacker(); |
70 // destructor will delete the unpacked CRX files. | |
71 ~ComponentUnpacker(); | |
72 | 102 |
73 Error error() const { return error_; } | 103 // Begins the actual unpacking of the files. May invoke a patcher if the |
74 | 104 // package is a differential update. Call |callback| with the result. |
75 int extended_error() const { return extended_error_; } | 105 void Unpack( |
106 const base::Callback<void(Error, int)>& callback); | |
76 | 107 |
77 private: | 108 private: |
109 // Before unpacking, verify that the file is well-formed and correctly signed. | |
Sorin Jianu
2014/01/25 02:30:21
We could say that verification is the first step,
waffles
2014/01/28 21:06:31
Done.
| |
110 bool Verify(); | |
111 | |
112 // The first step of unpacking is to unzip. Returns false if an error | |
113 // occurred as part of unzipping. | |
114 bool Unzip(); | |
115 | |
116 // The second step is to optionally patch files - this is a no-op for | |
117 // full (non-differential) updates. This step is asynchronous. Returns false | |
Sorin Jianu
2014/01/25 02:30:21
I am thinking we can name it BeginPatchingAsync to
waffles
2014/01/28 21:06:31
I'm not sure I like that idea so much, unless we s
| |
118 // if an error occurs. | |
119 bool BeginPatching(); | |
120 | |
121 // When patching is complete, DonePatching is called before moving on to step | |
122 // three. | |
123 void DonePatching(Error error, int extended_error); | |
124 | |
125 // The third step is to install the component. | |
126 void Install(); | |
127 | |
128 // The final step is to do clean-up for things that can't be tidied as we go. | |
129 // If there is an error at any step, the remaining steps are skipped and | |
130 // and Finish is called. | |
131 // Finish is responsible for calling the callback provided in Start(). | |
132 void Finish(); | |
Sorin Jianu
2014/01/25 02:30:21
Maybe call this function DoneUnpacking?
So far I'
waffles
2014/01/28 21:06:31
I thought about this. There is already ComponentUp
| |
133 | |
134 // Returns a weak pointer to this object. | |
135 base::WeakPtr<ComponentUnpacker> GetWeakPtr(); | |
136 | |
137 std::vector<uint8> pk_hash_; | |
138 base::FilePath path_; | |
78 base::FilePath unpack_path_; | 139 base::FilePath unpack_path_; |
140 base::FilePath unpack_diff_path_; | |
141 bool is_delta_; | |
142 std::string fingerprint_; | |
143 ComponentPatcher* patcher_; | |
144 ComponentInstaller* installer_; | |
145 base::Callback<void(Error, int)> callback_; | |
79 Error error_; | 146 Error error_; |
80 int extended_error_; // Provides additional error information. | 147 int extended_error_; |
148 base::WeakPtrFactory<ComponentUnpacker> ptr_factory_; | |
149 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
Sorin Jianu
2014/01/25 02:30:21
disallow copy and assign?
waffles
2014/01/28 21:06:31
Done.
| |
81 }; | 150 }; |
82 | 151 |
83 } // namespace component_updater | 152 } // namespace component_updater |
84 | 153 |
85 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ | 154 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ |
OLD | NEW |