Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/component_updater/component_unpacker.cc

Issue 213923002: Revert of Use UtilityProcessHost to patch files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nonblocking
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
101 ComponentInstaller* installer, 102 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),
108 installer_(installer), 109 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 task_runner_(task_runner) { 113 task_runner_(task_runner) {
113 } 114 }
114 115
115 // 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
116 // extension unpacker will reject, so that a component cannot be installed 117 // extension unpacker will reject, so that a component cannot be installed
117 // as an extension. 118 // as an extension.
118 scoped_ptr<base::DictionaryValue> ReadManifest( 119 scoped_ptr<base::DictionaryValue> ReadManifest(
119 const base::FilePath& unpack_path) { 120 const base::FilePath& unpack_path) {
120 base::FilePath manifest = 121 base::FilePath manifest =
121 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); 122 unpack_path.Append(FILE_PATH_LITERAL("manifest.json"));
122 if (!base::PathExists(manifest)) 123 if (!base::PathExists(manifest))
123 return scoped_ptr<base::DictionaryValue>(); 124 return scoped_ptr<base::DictionaryValue>();
124 JSONFileValueSerializer serializer(manifest); 125 JSONFileValueSerializer serializer(manifest);
125 std::string error; 126 std::string error;
126 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); 127 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error));
127 if (!root.get()) 128 if (!root.get())
128 return scoped_ptr<base::DictionaryValue>(); 129 return scoped_ptr<base::DictionaryValue>();
129 if (!root->IsType(base::Value::TYPE_DICTIONARY)) 130 if (!root->IsType(base::Value::TYPE_DICTIONARY))
130 return scoped_ptr<base::DictionaryValue>(); 131 return scoped_ptr<base::DictionaryValue>();
131 return scoped_ptr<base::DictionaryValue>( 132 return scoped_ptr<base::DictionaryValue>(
132 static_cast<base::DictionaryValue*>(root.release())).Pass(); 133 static_cast<base::DictionaryValue*>(root.release())).Pass();
133 } 134 }
134 135
135 bool ComponentUnpacker::UnpackInternal() { 136 bool ComponentUnpacker::UnpackInternal() {
136 return Verify() && Unzip() && BeginPatching(); 137 return Verify() && Unzip() && BeginPatching();
137 } 138 }
138 139
139 void ComponentUnpacker::Unpack(const Callback& callback) { 140 void ComponentUnpacker::Unpack(
141 const base::Callback<void(Error, int)>& callback) {
140 callback_ = callback; 142 callback_ = callback;
141 if (!UnpackInternal()) 143 if (!UnpackInternal())
142 Finish(); 144 Finish();
143 } 145 }
144 146
145 bool ComponentUnpacker::Verify() { 147 bool ComponentUnpacker::Verify() {
146 if (pk_hash_.empty() || path_.empty()) { 148 if (pk_hash_.empty() || path_.empty()) {
147 error_ = kInvalidParams; 149 error_ = kInvalidParams;
148 return false; 150 return false;
149 } 151 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 195
194 196
195 bool ComponentUnpacker::BeginPatching() { 197 bool ComponentUnpacker::BeginPatching() {
196 if (is_delta_) { // Package is a diff package. 198 if (is_delta_) { // Package is a diff package.
197 // Use a different temp directory for the patch output files. 199 // Use a different temp directory for the patch output files.
198 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), 200 if (!base::CreateNewTempDirectory(base::FilePath::StringType(),
199 &unpack_path_)) { 201 &unpack_path_)) {
200 error_ = kUnzipPathError; 202 error_ = kUnzipPathError;
201 return false; 203 return false;
202 } 204 }
203 patcher_ = new ComponentPatcher(unpack_diff_path_,
204 unpack_path_,
205 installer_,
206 in_process_,
207 task_runner_);
208 task_runner_->PostTask( 205 task_runner_->PostTask(
209 FROM_HERE, 206 FROM_HERE, base::Bind(&DifferentialUpdatePatch,
210 base::Bind(&ComponentPatcher::Start, 207 unpack_diff_path_,
211 patcher_, 208 unpack_path_,
212 base::Bind(&ComponentUnpacker::EndPatching, 209 patcher_,
213 scoped_refptr<ComponentUnpacker>(this)))); 210 installer_,
211 base::Bind(&ComponentUnpacker::EndPatching,
212 GetWeakPtr())));
214 } else { 213 } else {
215 task_runner_->PostTask(FROM_HERE, 214 task_runner_->PostTask(
216 base::Bind(&ComponentUnpacker::EndPatching, 215 FROM_HERE, base::Bind(&ComponentUnpacker::EndPatching,
217 scoped_refptr<ComponentUnpacker>(this), 216 GetWeakPtr(),
218 kNone, 217 kNone,
219 0)); 218 0));
220 } 219 }
221 return true; 220 return true;
222 } 221 }
223 222
224 void ComponentUnpacker::EndPatching(Error error, int extended_error) { 223 void ComponentUnpacker::EndPatching(Error error, int extended_error) {
225 error_ = error; 224 error_ = error;
226 extended_error_ = extended_error; 225 extended_error_ = extended_error;
227 patcher_ = NULL;
228 if (error_ != kNone) { 226 if (error_ != kNone) {
229 Finish(); 227 Finish();
230 return; 228 return;
231 } 229 }
232 // Optimization: clean up patch files early, in case disk space is too low to 230 // Optimization: clean up patch files early, in case disk space is too low to
233 // install otherwise. 231 // install otherwise.
234 if (!unpack_diff_path_.empty()) { 232 if (!unpack_diff_path_.empty()) {
235 base::DeleteFile(unpack_diff_path_, true); 233 base::DeleteFile(unpack_diff_path_, true);
236 unpack_diff_path_.clear(); 234 unpack_diff_path_.clear();
237 } 235 }
(...skipping 24 matching lines...) Expand all
262 } 260 }
263 261
264 void ComponentUnpacker::Finish() { 262 void ComponentUnpacker::Finish() {
265 if (!unpack_diff_path_.empty()) 263 if (!unpack_diff_path_.empty())
266 base::DeleteFile(unpack_diff_path_, true); 264 base::DeleteFile(unpack_diff_path_, true);
267 if (!unpack_path_.empty()) 265 if (!unpack_path_.empty())
268 base::DeleteFile(unpack_path_, true); 266 base::DeleteFile(unpack_path_, true);
269 callback_.Run(error_, extended_error_); 267 callback_.Run(error_, extended_error_);
270 } 268 }
271 269
270 base::WeakPtr<ComponentUnpacker> ComponentUnpacker::GetWeakPtr() {
271 return ptr_factory_.GetWeakPtr();
272 }
273
272 ComponentUnpacker::~ComponentUnpacker() { 274 ComponentUnpacker::~ComponentUnpacker() {
273 } 275 }
274 276
275 } // namespace component_updater 277 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698