| 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 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 kDeltaUnsupportedCommand, | 84 kDeltaUnsupportedCommand, |
| 85 kDeltaOperationFailure, | 85 kDeltaOperationFailure, |
| 86 kDeltaPatchProcessFailure, | 86 kDeltaPatchProcessFailure, |
| 87 kDeltaMissingExistingFile, | 87 kDeltaMissingExistingFile, |
| 88 kFingerprintWriteFailed, | 88 kFingerprintWriteFailed, |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 typedef base::Callback<void(Error, int)> Callback; | 91 typedef base::Callback<void(Error, int)> Callback; |
| 92 | 92 |
| 93 // Constructs an unpacker for a specific component unpacking operation. | 93 // Constructs an unpacker for a specific component unpacking operation. |
| 94 // |pk_hash| is the expected/ public key SHA256 hash. |path| is the current | 94 // |pk_hash| is the expected public key SHA256 hash. |path| is the current |
| 95 // location of the CRX. | 95 // location of the CRX. |
| 96 ComponentUnpacker(const std::vector<uint8>& pk_hash, | 96 ComponentUnpacker(const std::vector<uint8>& pk_hash, |
| 97 const base::FilePath& path, | 97 const base::FilePath& path, |
| 98 const std::string& fingerprint, | 98 const std::string& fingerprint, |
| 99 ComponentInstaller* installer, | 99 ComponentInstaller* installer, |
| 100 bool in_process, | 100 bool in_process, |
| 101 scoped_refptr<base::SequencedTaskRunner> task_runner); | 101 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 102 | 102 |
| 103 // Begins the actual unpacking of the files. May invoke a patcher if the | 103 // Begins the actual unpacking of the files. May invoke a patcher if the |
| 104 // package is a differential update. Calls |callback| with the result. | 104 // package is a differential update. Calls |callback| with the result. |
| 105 void Unpack(const Callback& callback); | 105 void Unpack(const Callback& callback); |
| 106 | 106 |
| 107 // Set the base directory where the unpack directory will be created. |
| 108 // If this is not set, files will be unzipped to temporary dir. |
| 109 void set_unpack_base_dir(const base::FilePath& path); |
| 110 |
| 111 // Creates a ComponentUnpacker by loading CRX and related install information |
| 112 // from |backup_path| that was previously saved by SaveInstallSource(). This |
| 113 // is to retry failed component installation. |pk_hash| is the expected public |
| 114 // key SHA256 hash. |
| 115 static scoped_refptr<ComponentUnpacker> CreateFromBackup( |
| 116 const base::FilePath& backup_path, |
| 117 const std::vector<uint8>& pk_hash, |
| 118 ComponentInstaller* installer, |
| 119 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 120 |
| 121 |
| 107 private: | 122 private: |
| 108 friend class base::RefCountedThreadSafe<ComponentUnpacker>; | 123 friend class base::RefCountedThreadSafe<ComponentUnpacker>; |
| 124 friend class ComponentUnpackerTest; |
| 109 | 125 |
| 110 virtual ~ComponentUnpacker(); | 126 virtual ~ComponentUnpacker(); |
| 111 | 127 |
| 112 bool UnpackInternal(); | 128 bool UnpackInternal(); |
| 113 | 129 |
| 114 // The first step of unpacking is to verify the file. Returns false if an | 130 // The first step of unpacking is to verify the file. Returns false if an |
| 115 // error is encountered, the file is malformed, or the file is incorrectly | 131 // error is encountered, the file is malformed, or the file is incorrectly |
| 116 // signed. | 132 // signed. |
| 117 bool Verify(); | 133 bool Verify(); |
| 118 | 134 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 131 | 147 |
| 132 // The fourth step is to install the unpacked component. | 148 // The fourth step is to install the unpacked component. |
| 133 void Install(); | 149 void Install(); |
| 134 | 150 |
| 135 // The final step is to do clean-up for things that can't be tidied as we go. | 151 // The final step is to do clean-up for things that can't be tidied as we go. |
| 136 // If there is an error at any step, the remaining steps are skipped and | 152 // If there is an error at any step, the remaining steps are skipped and |
| 137 // and Finish is called. | 153 // and Finish is called. |
| 138 // Finish is responsible for calling the callback provided in Start(). | 154 // Finish is responsible for calling the callback provided in Start(). |
| 139 void Finish(); | 155 void Finish(); |
| 140 | 156 |
| 157 // Saves the original CRX file, along with |fingerprint_|, |pk_hash_| and |
| 158 // |in_process_|, to |backup_path|. This is to re-create ComponentUnpacker for |
| 159 // retrying failed component patching. |
| 160 bool SaveInstallSource(const base::FilePath& backup_path) const; |
| 161 |
| 162 // Creates the directory for unzip. |new_dir| will be the full path to the |
| 163 // directory. |
| 164 bool CreateUnpackDirectory(base::FilePath* new_dir); |
| 165 |
| 166 base::FilePath unpack_base_dir_; |
| 141 std::vector<uint8> pk_hash_; | 167 std::vector<uint8> pk_hash_; |
| 142 base::FilePath path_; | 168 base::FilePath path_; |
| 143 base::FilePath unpack_path_; | 169 base::FilePath unpack_path_; |
| 144 base::FilePath unpack_diff_path_; | 170 base::FilePath unpack_diff_path_; |
| 145 bool is_delta_; | 171 bool is_delta_; |
| 146 std::string fingerprint_; | 172 std::string fingerprint_; |
| 147 scoped_refptr<ComponentPatcher> patcher_; | 173 scoped_refptr<ComponentPatcher> patcher_; |
| 148 ComponentInstaller* installer_; | 174 ComponentInstaller* installer_; |
| 149 Callback callback_; | 175 Callback callback_; |
| 150 const bool in_process_; | 176 const bool in_process_; |
| 151 Error error_; | 177 Error error_; |
| 152 int extended_error_; | 178 int extended_error_; |
| 153 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 179 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 154 | 180 |
| 155 DISALLOW_COPY_AND_ASSIGN(ComponentUnpacker); | 181 DISALLOW_COPY_AND_ASSIGN(ComponentUnpacker); |
| 156 }; | 182 }; |
| 157 | 183 |
| 158 } // namespace component_updater | 184 } // namespace component_updater |
| 159 | 185 |
| 160 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ | 186 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ |
| OLD | NEW |