| 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), | |
| 113 task_runner_(task_runner) { | 112 task_runner_(task_runner) { |
| 114 } | 113 } |
| 115 | 114 |
| 116 // TODO(cpu): add a specific attribute check to a component json that the | 115 // 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 | 116 // extension unpacker will reject, so that a component cannot be installed |
| 118 // as an extension. | 117 // as an extension. |
| 119 scoped_ptr<base::DictionaryValue> ReadManifest( | 118 scoped_ptr<base::DictionaryValue> ReadManifest( |
| 120 const base::FilePath& unpack_path) { | 119 const base::FilePath& unpack_path) { |
| 121 base::FilePath manifest = | 120 base::FilePath manifest = |
| 122 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); | 121 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 194 |
| 196 | 195 |
| 197 bool ComponentUnpacker::BeginPatching() { | 196 bool ComponentUnpacker::BeginPatching() { |
| 198 if (is_delta_) { // Package is a diff package. | 197 if (is_delta_) { // Package is a diff package. |
| 199 // Use a different temp directory for the patch output files. | 198 // Use a different temp directory for the patch output files. |
| 200 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), | 199 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), |
| 201 &unpack_path_)) { | 200 &unpack_path_)) { |
| 202 error_ = kUnzipPathError; | 201 error_ = kUnzipPathError; |
| 203 return false; | 202 return false; |
| 204 } | 203 } |
| 204 patcher_ = new ComponentPatcher(unpack_diff_path_, |
| 205 unpack_path_, |
| 206 installer_, |
| 207 in_process_, |
| 208 task_runner_); |
| 205 task_runner_->PostTask( | 209 task_runner_->PostTask( |
| 206 FROM_HERE, base::Bind(&DifferentialUpdatePatch, | 210 FROM_HERE, |
| 207 unpack_diff_path_, | 211 base::Bind(&ComponentPatcher::Start, |
| 208 unpack_path_, | 212 patcher_, |
| 209 patcher_, | 213 base::Bind(&ComponentUnpacker::EndPatching, |
| 210 installer_, | 214 scoped_refptr<ComponentUnpacker>(this)))); |
| 211 base::Bind(&ComponentUnpacker::EndPatching, | |
| 212 GetWeakPtr()))); | |
| 213 } else { | 215 } else { |
| 214 task_runner_->PostTask( | 216 task_runner_->PostTask(FROM_HERE, |
| 215 FROM_HERE, base::Bind(&ComponentUnpacker::EndPatching, | 217 base::Bind(&ComponentUnpacker::EndPatching, |
| 216 GetWeakPtr(), | 218 scoped_refptr<ComponentUnpacker>(this), |
| 217 kNone, | 219 kNone, |
| 218 0)); | 220 0)); |
| 219 } | 221 } |
| 220 return true; | 222 return true; |
| 221 } | 223 } |
| 222 | 224 |
| 223 void ComponentUnpacker::EndPatching(Error error, int extended_error) { | 225 void ComponentUnpacker::EndPatching(Error error, int extended_error) { |
| 224 error_ = error; | 226 error_ = error; |
| 225 extended_error_ = extended_error; | 227 extended_error_ = extended_error; |
| 226 if (error_ != kNone) { | 228 if (error_ != kNone) { |
| 227 Finish(); | 229 Finish(); |
| 228 return; | 230 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 262 } |
| 261 | 263 |
| 262 void ComponentUnpacker::Finish() { | 264 void ComponentUnpacker::Finish() { |
| 263 if (!unpack_diff_path_.empty()) | 265 if (!unpack_diff_path_.empty()) |
| 264 base::DeleteFile(unpack_diff_path_, true); | 266 base::DeleteFile(unpack_diff_path_, true); |
| 265 if (!unpack_path_.empty()) | 267 if (!unpack_path_.empty()) |
| 266 base::DeleteFile(unpack_path_, true); | 268 base::DeleteFile(unpack_path_, true); |
| 267 callback_.Run(error_, extended_error_); | 269 callback_.Run(error_, extended_error_); |
| 268 } | 270 } |
| 269 | 271 |
| 270 base::WeakPtr<ComponentUnpacker> ComponentUnpacker::GetWeakPtr() { | |
| 271 return ptr_factory_.GetWeakPtr(); | |
| 272 } | |
| 273 | |
| 274 ComponentUnpacker::~ComponentUnpacker() { | 272 ComponentUnpacker::~ComponentUnpacker() { |
| 275 } | 273 } |
| 276 | 274 |
| 277 } // namespace component_updater | 275 } // namespace component_updater |
| OLD | NEW |