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 #include "chrome/browser/component_updater/component_unpacker.h" | 5 #include "chrome/browser/component_updater/component_unpacker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool is_delta_; | 91 bool is_delta_; |
92 std::vector<uint8> public_key_; | 92 std::vector<uint8> public_key_; |
93 }; | 93 }; |
94 | 94 |
95 } // namespace | 95 } // namespace |
96 | 96 |
97 ComponentUnpacker::ComponentUnpacker( | 97 ComponentUnpacker::ComponentUnpacker( |
98 const std::vector<uint8>& pk_hash, | 98 const std::vector<uint8>& pk_hash, |
99 const base::FilePath& path, | 99 const base::FilePath& path, |
100 const std::string& fingerprint, | 100 const std::string& fingerprint, |
101 ComponentPatcher* patcher, | |
102 ComponentInstaller* installer, | 101 ComponentInstaller* installer, |
| 102 bool in_process, |
103 scoped_refptr<base::SequencedTaskRunner> task_runner) | 103 scoped_refptr<base::SequencedTaskRunner> task_runner) |
104 : pk_hash_(pk_hash), | 104 : pk_hash_(pk_hash), |
105 path_(path), | 105 path_(path), |
106 is_delta_(false), | 106 is_delta_(false), |
107 fingerprint_(fingerprint), | 107 fingerprint_(fingerprint), |
108 patcher_(patcher), | |
109 installer_(installer), | 108 installer_(installer), |
| 109 in_process_(in_process), |
110 error_(kNone), | 110 error_(kNone), |
111 extended_error_(0), | 111 extended_error_(0), |
112 ptr_factory_(this), | 112 ptr_factory_(this), |
113 task_runner_(task_runner) { | 113 task_runner_(task_runner) { |
114 } | 114 } |
115 | 115 |
116 // TODO(cpu): add a specific attribute check to a component json that the | 116 // TODO(cpu): add a specific attribute check to a component json that the |
117 // extension unpacker will reject, so that a component cannot be installed | 117 // extension unpacker will reject, so that a component cannot be installed |
118 // as an extension. | 118 // as an extension. |
119 scoped_ptr<base::DictionaryValue> ReadManifest( | 119 scoped_ptr<base::DictionaryValue> ReadManifest( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 | 198 |
199 bool ComponentUnpacker::BeginPatching() { | 199 bool ComponentUnpacker::BeginPatching() { |
200 if (is_delta_) { // Package is a diff package. | 200 if (is_delta_) { // Package is a diff package. |
201 // Use a different temp directory for the patch output files. | 201 // Use a different temp directory for the patch output files. |
202 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), | 202 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), |
203 &unpack_path_)) { | 203 &unpack_path_)) { |
204 error_ = kUnzipPathError; | 204 error_ = kUnzipPathError; |
205 return false; | 205 return false; |
206 } | 206 } |
| 207 patcher_.reset(new ComponentPatcher(unpack_diff_path_, |
| 208 unpack_path_, |
| 209 installer_, |
| 210 in_process_, |
| 211 task_runner_)); |
207 task_runner_->PostTask( | 212 task_runner_->PostTask( |
208 FROM_HERE, base::Bind(&DifferentialUpdatePatch, | 213 FROM_HERE, base::Bind(&ComponentPatcher::Start, |
209 unpack_diff_path_, | 214 patcher_->GetWeakPtr(), |
210 unpack_path_, | |
211 patcher_, | |
212 installer_, | |
213 base::Bind(&ComponentUnpacker::EndPatching, | 215 base::Bind(&ComponentUnpacker::EndPatching, |
214 GetWeakPtr()))); | 216 GetWeakPtr()))); |
215 } else { | 217 } else { |
216 task_runner_->PostTask( | 218 task_runner_->PostTask( |
217 FROM_HERE, base::Bind(&ComponentUnpacker::EndPatching, | 219 FROM_HERE, base::Bind(&ComponentUnpacker::EndPatching, |
218 GetWeakPtr(), | 220 GetWeakPtr(), |
219 kNone, | 221 kNone, |
220 0)); | 222 0)); |
221 } | 223 } |
222 return true; | 224 return true; |
223 } | 225 } |
224 | 226 |
225 void ComponentUnpacker::EndPatching(Error error, int extended_error) { | 227 void ComponentUnpacker::EndPatching(Error error, int extended_error) { |
| 228 patcher_.reset(); |
226 error_ = error; | 229 error_ = error; |
227 extended_error_ = extended_error; | 230 extended_error_ = extended_error; |
228 if (error_ != kNone) { | 231 if (error_ != kNone) { |
229 Finish(); | 232 Finish(); |
230 return; | 233 return; |
231 } | 234 } |
232 // Optimization: clean up patch files early, in case disk space is too low to | 235 // Optimization: clean up patch files early, in case disk space is too low to |
233 // install otherwise. | 236 // install otherwise. |
234 if (!unpack_diff_path_.empty()) { | 237 if (!unpack_diff_path_.empty()) { |
235 base::DeleteFile(unpack_diff_path_, true); | 238 base::DeleteFile(unpack_diff_path_, true); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 272 } |
270 | 273 |
271 base::WeakPtr<ComponentUnpacker> ComponentUnpacker::GetWeakPtr() { | 274 base::WeakPtr<ComponentUnpacker> ComponentUnpacker::GetWeakPtr() { |
272 return ptr_factory_.GetWeakPtr(); | 275 return ptr_factory_.GetWeakPtr(); |
273 } | 276 } |
274 | 277 |
275 ComponentUnpacker::~ComponentUnpacker() { | 278 ComponentUnpacker::~ComponentUnpacker() { |
276 } | 279 } |
277 | 280 |
278 } // namespace component_updater | 281 } // namespace component_updater |
OLD | NEW |