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

Side by Side Diff: components/update_client/action_update.cc

Issue 2479633003: Makes the component installers return a Result instead of a bool. (Closed)
Patch Set: rebase Created 4 years, 1 month 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
« no previous file with comments | « components/update_client/action_update.h ('k') | components/update_client/test_installer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/update_client/action_update.h" 5 #include "components/update_client/action_update.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 17 matching lines...) Expand all
28 namespace update_client { 28 namespace update_client {
29 29
30 namespace { 30 namespace {
31 31
32 void AppendDownloadMetrics( 32 void AppendDownloadMetrics(
33 const std::vector<CrxDownloader::DownloadMetrics>& source, 33 const std::vector<CrxDownloader::DownloadMetrics>& source,
34 std::vector<CrxDownloader::DownloadMetrics>* destination) { 34 std::vector<CrxDownloader::DownloadMetrics>* destination) {
35 destination->insert(destination->end(), source.begin(), source.end()); 35 destination->insert(destination->end(), source.begin(), source.end());
36 } 36 }
37 37
38 ErrorCategory UnpackerErrorToErrorCategory(UnpackerError error) {
39 ErrorCategory error_category = ErrorCategory::kErrorNone;
40 switch (error) {
41 case UnpackerError::kNone:
42 break;
43 case UnpackerError::kInstallerError:
44 error_category = ErrorCategory::kInstallError;
45 break;
46 default:
47 error_category = ErrorCategory::kUnpackError;
48 break;
49 }
50 return error_category;
51 }
52
53 } // namespace 38 } // namespace
54 39
55 ActionUpdate::ActionUpdate() { 40 ActionUpdate::ActionUpdate() {
56 } 41 }
57 42
58 ActionUpdate::~ActionUpdate() { 43 ActionUpdate::~ActionUpdate() {
59 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
60 } 45 }
61 46
62 void ActionUpdate::Run(UpdateContext* update_context, Callback callback) { 47 void ActionUpdate::Run(UpdateContext* update_context, Callback callback) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 147
163 if (result.error == UnpackerError::kNone) { 148 if (result.error == UnpackerError::kNone) {
164 update_context_->blocking_task_runner->PostTask( 149 update_context_->blocking_task_runner->PostTask(
165 FROM_HERE, 150 FROM_HERE,
166 base::Bind(&ActionUpdate::StartInstallOnBlockingTaskRunner, 151 base::Bind(&ActionUpdate::StartInstallOnBlockingTaskRunner,
167 base::Unretained(this), item, crx_path, result.unpack_path)); 152 base::Unretained(this), item, crx_path, result.unpack_path));
168 } else { 153 } else {
169 update_context_->blocking_task_runner->PostTask( 154 update_context_->blocking_task_runner->PostTask(
170 FROM_HERE, 155 FROM_HERE,
171 base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner, 156 base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner,
172 base::Unretained(this), item, crx_path, result.error, 157 base::Unretained(this), item, crx_path,
158 ErrorCategory::kUnpackError, static_cast<int>(result.error),
173 result.extended_error)); 159 result.extended_error));
174 } 160 }
175 } 161 }
176 162
177 void ActionUpdate::StartInstallOnBlockingTaskRunner( 163 void ActionUpdate::StartInstallOnBlockingTaskRunner(
178 CrxUpdateItem* item, 164 CrxUpdateItem* item,
179 const base::FilePath& crx_path, 165 const base::FilePath& crx_path,
180 const base::FilePath& unpack_path) { 166 const base::FilePath& unpack_path) {
181 DCHECK(update_context_->blocking_task_runner->RunsTasksOnCurrentThread()); 167 DCHECK(update_context_->blocking_task_runner->RunsTasksOnCurrentThread());
182 DCHECK(!unpack_path.empty()); 168 DCHECK(!unpack_path.empty());
183 169
184 const auto error = DoInstall(item, crx_path, unpack_path); 170 const auto result = DoInstall(item, crx_path, unpack_path);
171 const ErrorCategory error_category =
172 result.error ? ErrorCategory::kInstallError : ErrorCategory::kErrorNone;
185 update_context_->blocking_task_runner->PostTask( 173 update_context_->blocking_task_runner->PostTask(
186 FROM_HERE, base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner, 174 FROM_HERE,
187 base::Unretained(this), item, crx_path, error, 0)); 175 base::Bind(&ActionUpdate::InstallCompleteOnBlockingTaskRunner,
176 base::Unretained(this), item, crx_path, error_category,
177 result.error, result.extended_error));
188 } 178 }
189 179
190 void ActionUpdate::InstallCompleteOnBlockingTaskRunner( 180 void ActionUpdate::InstallCompleteOnBlockingTaskRunner(
191 CrxUpdateItem* item, 181 CrxUpdateItem* item,
192 const base::FilePath& crx_path, 182 const base::FilePath& crx_path,
193 UnpackerError error, 183 ErrorCategory error_category,
184 int error,
194 int extended_error) { 185 int extended_error) {
195 update_client::DeleteFileAndEmptyParentDirectory(crx_path); 186 update_client::DeleteFileAndEmptyParentDirectory(crx_path);
196 update_context_->main_task_runner->PostDelayedTask( 187 update_context_->main_task_runner->PostDelayedTask(
197 FROM_HERE, 188 FROM_HERE,
198 base::Bind(&ActionUpdate::InstallComplete, base::Unretained(this), 189 base::Bind(&ActionUpdate::InstallComplete, base::Unretained(this),
199 item->id, error, extended_error), 190 item->id, error_category, error, extended_error),
200 base::TimeDelta::FromMilliseconds(update_context_->config->StepDelay())); 191 base::TimeDelta::FromMilliseconds(update_context_->config->StepDelay()));
201 } 192 }
202 193
203 UnpackerError ActionUpdate::DoInstall(CrxUpdateItem* item, 194 CrxInstaller::Result ActionUpdate::DoInstall(
204 const base::FilePath& crx_path, 195 CrxUpdateItem* item,
205 const base::FilePath& unpack_path) { 196 const base::FilePath& crx_path,
197 const base::FilePath& unpack_path) {
206 const auto& fingerprint = item->next_fp; 198 const auto& fingerprint = item->next_fp;
207 if (static_cast<int>(fingerprint.size()) != 199 if (static_cast<int>(fingerprint.size()) !=
208 base::WriteFile( 200 base::WriteFile(
209 unpack_path.Append(FILE_PATH_LITERAL("manifest.fingerprint")), 201 unpack_path.Append(FILE_PATH_LITERAL("manifest.fingerprint")),
210 fingerprint.c_str(), base::checked_cast<int>(fingerprint.size()))) { 202 fingerprint.c_str(), base::checked_cast<int>(fingerprint.size()))) {
211 return UnpackerError::kFingerprintWriteFailed; 203 return CrxInstaller::Result(InstallError::FINGERPRINT_WRITE_FAILED);
212 } 204 }
213 205
214 std::unique_ptr<base::DictionaryValue> manifest = ReadManifest(unpack_path); 206 std::unique_ptr<base::DictionaryValue> manifest = ReadManifest(unpack_path);
215 if (!manifest.get()) 207 if (!manifest.get())
216 return UnpackerError::kBadManifest; 208 return CrxInstaller::Result(InstallError::BAD_MANIFEST);
217 209
218 return item->component.installer->Install(*manifest, unpack_path) 210 return item->component.installer->Install(*manifest, unpack_path);
219 ? UnpackerError::kNone
220 : UnpackerError::kInstallerError;
221 } 211 }
222 212
223 void ActionUpdate::InstallComplete(const std::string& id, 213 void ActionUpdate::InstallComplete(const std::string& id,
224 UnpackerError error, 214 ErrorCategory error_category,
215 int error,
225 int extended_error) { 216 int extended_error) {
226 DCHECK(thread_checker_.CalledOnValidThread()); 217 DCHECK(thread_checker_.CalledOnValidThread());
227 DCHECK(id == update_context_->queue.front()); 218 DCHECK(id == update_context_->queue.front());
228 219
229 CrxUpdateItem* item = FindUpdateItemById(id); 220 CrxUpdateItem* item = FindUpdateItemById(id);
230 DCHECK(item); 221 DCHECK(item);
231 222
232 if (error == UnpackerError::kNone) 223 if (error == 0) {
224 DCHECK_EQ(ErrorCategory::kErrorNone, error_category);
225 DCHECK_EQ(0, extended_error);
233 OnInstallSuccess(item); 226 OnInstallSuccess(item);
234 else 227 } else {
235 OnInstallError(item, error, extended_error); 228 OnInstallError(item, error_category, error, extended_error);
229 }
236 } 230 }
237 231
238 ActionUpdateDiff::ActionUpdateDiff() { 232 ActionUpdateDiff::ActionUpdateDiff() {
239 } 233 }
240 234
241 ActionUpdateDiff::~ActionUpdateDiff() { 235 ActionUpdateDiff::~ActionUpdateDiff() {
242 DCHECK(thread_checker_.CalledOnValidThread()); 236 DCHECK(thread_checker_.CalledOnValidThread());
243 } 237 }
244 238
245 std::unique_ptr<Action> ActionUpdateDiff::Create() { 239 std::unique_ptr<Action> ActionUpdateDiff::Create() {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 DCHECK(item->state == CrxUpdateItem::State::kUpdatingDiff); 308 DCHECK(item->state == CrxUpdateItem::State::kUpdatingDiff);
315 309
316 item->component.version = item->next_version; 310 item->component.version = item->next_version;
317 item->component.fingerprint = item->next_fp; 311 item->component.fingerprint = item->next_fp;
318 ChangeItemState(item, CrxUpdateItem::State::kUpdated); 312 ChangeItemState(item, CrxUpdateItem::State::kUpdated);
319 313
320 UpdateCrxComplete(item); 314 UpdateCrxComplete(item);
321 } 315 }
322 316
323 void ActionUpdateDiff::OnInstallError(CrxUpdateItem* item, 317 void ActionUpdateDiff::OnInstallError(CrxUpdateItem* item,
324 UnpackerError error, 318 ErrorCategory error_category,
319 int error,
325 int extended_error) { 320 int extended_error) {
326 DCHECK(thread_checker_.CalledOnValidThread()); 321 DCHECK(thread_checker_.CalledOnValidThread());
327 322
328 item->diff_error_category = 323 item->diff_error_category = static_cast<int>(error_category);
329 static_cast<int>(UnpackerErrorToErrorCategory(error)); 324 item->diff_error_code = error;
330 item->diff_error_code = static_cast<int>(error);
331 item->diff_extra_code1 = extended_error; 325 item->diff_extra_code1 = extended_error;
332 item->diff_update_failed = true; 326 item->diff_update_failed = true;
333 327
334 base::ThreadTaskRunnerHandle::Get()->PostTask( 328 base::ThreadTaskRunnerHandle::Get()->PostTask(
335 FROM_HERE, 329 FROM_HERE,
336 base::Bind(&ActionUpdateDiff::TryUpdateFull, base::Unretained(this))); 330 base::Bind(&ActionUpdateDiff::TryUpdateFull, base::Unretained(this)));
337 } 331 }
338 332
339 ActionUpdateFull::ActionUpdateFull() { 333 ActionUpdateFull::ActionUpdateFull() {
340 } 334 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 DCHECK(item->state == CrxUpdateItem::State::kUpdating); 401 DCHECK(item->state == CrxUpdateItem::State::kUpdating);
408 402
409 item->component.version = item->next_version; 403 item->component.version = item->next_version;
410 item->component.fingerprint = item->next_fp; 404 item->component.fingerprint = item->next_fp;
411 ChangeItemState(item, CrxUpdateItem::State::kUpdated); 405 ChangeItemState(item, CrxUpdateItem::State::kUpdated);
412 406
413 UpdateCrxComplete(item); 407 UpdateCrxComplete(item);
414 } 408 }
415 409
416 void ActionUpdateFull::OnInstallError(CrxUpdateItem* item, 410 void ActionUpdateFull::OnInstallError(CrxUpdateItem* item,
417 UnpackerError error, 411 ErrorCategory error_category,
412 int error,
418 int extended_error) { 413 int extended_error) {
419 DCHECK(thread_checker_.CalledOnValidThread()); 414 DCHECK(thread_checker_.CalledOnValidThread());
420 DCHECK(item->state == CrxUpdateItem::State::kUpdating); 415 DCHECK(item->state == CrxUpdateItem::State::kUpdating);
421 416
422 item->error_category = static_cast<int>(UnpackerErrorToErrorCategory(error)); 417 item->error_category = static_cast<int>(error_category);
423 item->error_code = static_cast<int>(error); 418 item->error_code = error;
424 item->extra_code1 = extended_error; 419 item->extra_code1 = extended_error;
425 ChangeItemState(item, CrxUpdateItem::State::kNoUpdate); 420 ChangeItemState(item, CrxUpdateItem::State::kNoUpdate);
426 421
427 UpdateCrxComplete(item); 422 UpdateCrxComplete(item);
428 } 423 }
429 424
430 } // namespace update_client 425 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/action_update.h ('k') | components/update_client/test_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698