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