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

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

Issue 25883006: Support asynchronous patching operations in the component updater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tests
Patch Set: Threading model changes. Created 7 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
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_updater_service.h" 5 #include "chrome/browser/component_updater/component_updater_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 void AddUpdateCheckItems(std::string* query); 406 void AddUpdateCheckItems(std::string* query);
407 407
408 void DoUpdateCheck(const std::string& query); 408 void DoUpdateCheck(const std::string& query);
409 409
410 void ScheduleNextRun(StepDelayInterval step_delay); 410 void ScheduleNextRun(StepDelayInterval step_delay);
411 411
412 void ParseManifest(const std::string& xml); 412 void ParseManifest(const std::string& xml);
413 413
414 void Install(const CRXContext* context, const base::FilePath& crx_path); 414 void Install(const CRXContext* context, const base::FilePath& crx_path);
415 415
416 void DoneUnpacking(const std::string& component_id,
417 const base::FilePath& crx_path,
418 component_updater::Error error,
419 int extended_error);
420
416 void DoneInstalling(const std::string& component_id, 421 void DoneInstalling(const std::string& component_id,
417 ComponentUnpacker::Error error, 422 component_updater::Error error,
418 int extended_error); 423 int extended_error);
419 424
420 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); 425 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to);
421 426
422 size_t ChangeItemStatus(CrxUpdateItem::Status from, 427 size_t ChangeItemStatus(CrxUpdateItem::Status from,
423 CrxUpdateItem::Status to); 428 CrxUpdateItem::Status to);
424 429
425 CrxUpdateItem* FindUpdateItemById(const std::string& id); 430 CrxUpdateItem* FindUpdateItemById(const std::string& id);
426 431
427 void NotifyComponentObservers(ComponentObserver::Events event, 432 void NotifyComponentObservers(ComponentObserver::Events event,
428 int extra) const; 433 int extra) const;
429 434
430 bool HasOnDemandItems() const; 435 bool HasOnDemandItems() const;
431 436
432 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, 437 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt,
433 const std::string& crx_id); 438 const std::string& crx_id);
434 439
435 scoped_ptr<ComponentUpdateService::Configurator> config_; 440 scoped_ptr<ComponentUpdateService::Configurator> config_;
436 441
437 scoped_ptr<ComponentPatcher> component_patcher_; 442 scoped_ptr<ComponentPatcher> component_patcher_;
438 443
439 scoped_ptr<net::URLFetcher> url_fetcher_; 444 scoped_ptr<net::URLFetcher> url_fetcher_;
440 445
441 scoped_ptr<component_updater::PingManager> ping_manager_; 446 scoped_ptr<component_updater::PingManager> ping_manager_;
442 447
448 scoped_ptr<component_updater::ComponentUnpacker> unpacker_;
449
443 // A collection of every work item. 450 // A collection of every work item.
444 typedef std::vector<CrxUpdateItem*> UpdateItems; 451 typedef std::vector<CrxUpdateItem*> UpdateItems;
445 UpdateItems work_items_; 452 UpdateItems work_items_;
446 453
447 base::OneShotTimer<CrxUpdateService> timer_; 454 base::OneShotTimer<CrxUpdateService> timer_;
448 455
449 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 456 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
450 457
451 const Version chrome_version_; 458 const Version chrome_version_;
452 459
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 base::Bind(&CrxUpdateService::Install, 1061 base::Bind(&CrxUpdateService::Install,
1055 base::Unretained(this), 1062 base::Unretained(this),
1056 crx_context.release(), 1063 crx_context.release(),
1057 temp_crx_path), 1064 temp_crx_path),
1058 base::TimeDelta::FromMilliseconds(config_->StepDelay())); 1065 base::TimeDelta::FromMilliseconds(config_->StepDelay()));
1059 } 1066 }
1060 } 1067 }
1061 1068
1062 // Install consists of digital signature verification, unpacking and then 1069 // Install consists of digital signature verification, unpacking and then
1063 // calling the component specific installer. All that is handled by the 1070 // calling the component specific installer. All that is handled by the
1064 // |unpacker|. If there is an error this function is in charge of deleting 1071 // |unpacker_|. If there is an error this function is in charge of deleting
1065 // the files created. 1072 // the files created.
1066 void CrxUpdateService::Install(const CRXContext* context, 1073 void CrxUpdateService::Install(const CRXContext* context,
1067 const base::FilePath& crx_path) { 1074 const base::FilePath& crx_path) {
1068 // This function owns the file at |crx_path| and the |context| object. 1075 // This function owns the file at |crx_path| and the |context| object.
1069 ComponentUnpacker unpacker(context->pk_hash, 1076 unpacker_.reset(new component_updater::ComponentUnpacker(
1070 crx_path, 1077 context->pk_hash,
1071 context->fingerprint, 1078 crx_path,
1072 component_patcher_.get(), 1079 context->fingerprint,
1073 context->installer); 1080 component_patcher_.get(),
1081 context->installer,
1082 blocking_task_runner_));
1083 unpacker_->Unpack(base::Bind(&CrxUpdateService::DoneUnpacking,
1084 base::Unretained(this),
1085 context->id,
1086 crx_path));
1087 delete context;
1088 }
1089
1090 // Do some cleanup before we skip back to the UI thread.
1091 void CrxUpdateService::DoneUnpacking(const std::string& component_id,
1092 const base::FilePath& crx_path,
1093 component_updater::Error error,
1094 int extended_error) {
1074 if (!base::DeleteFile(crx_path, false)) 1095 if (!base::DeleteFile(crx_path, false))
1075 NOTREACHED() << crx_path.value(); 1096 NOTREACHED() << crx_path.value();
1076 // Why unretained? See comment at top of file.
1077 BrowserThread::PostDelayedTask( 1097 BrowserThread::PostDelayedTask(
1078 BrowserThread::UI, 1098 BrowserThread::UI,
1079 FROM_HERE, 1099 FROM_HERE,
1080 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), 1100 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this),
1081 context->id, unpacker.error(), unpacker.extended_error()), 1101 component_id, error, extended_error),
1082 base::TimeDelta::FromMilliseconds(config_->StepDelay())); 1102 base::TimeDelta::FromMilliseconds(config_->StepDelay()));
1083 delete context;
1084 } 1103 }
1085 1104
1086 // Installation has been completed. Adjust the component status and 1105 // Installation has been completed. Adjust the component status and
1087 // schedule the next check. Schedule a short delay before trying the full 1106 // schedule the next check. Schedule a short delay before trying the full
1088 // update when the differential update failed. 1107 // update when the differential update failed.
1089 void CrxUpdateService::DoneInstalling(const std::string& component_id, 1108 void CrxUpdateService::DoneInstalling(const std::string& component_id,
1090 ComponentUnpacker::Error error, 1109 component_updater::Error error,
1091 int extra_code) { 1110 int extra_code) {
1092 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1093 1112
1094 ErrorCategory error_category = kErrorNone; 1113 ErrorCategory error_category = kErrorNone;
1095 switch (error) { 1114 switch (error) {
1096 case ComponentUnpacker::kNone: 1115 case component_updater::kNone:
1097 break; 1116 break;
1098 case ComponentUnpacker::kInstallerError: 1117 case component_updater::kInstallerError:
1099 error_category = kInstallError; 1118 error_category = kInstallError;
1100 break; 1119 break;
1101 default: 1120 default:
1102 error_category = kUnpackError; 1121 error_category = kUnpackError;
1103 break; 1122 break;
1104 } 1123 }
1105 1124
1106 const bool is_success = error == ComponentUnpacker::kNone; 1125 const bool is_success = error == component_updater::kNone;
1107 1126
1108 CrxUpdateItem* item = FindUpdateItemById(component_id); 1127 CrxUpdateItem* item = FindUpdateItemById(component_id);
1109 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { 1128 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) {
1110 item->diff_error_category = error_category; 1129 item->diff_error_category = error_category;
1111 item->diff_error_code = error; 1130 item->diff_error_code = error;
1112 item->diff_extra_code1 = extra_code; 1131 item->diff_extra_code1 = extra_code;
1113 item->diff_update_failed = true; 1132 item->diff_update_failed = true;
1114 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, 1133 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff,
1115 CrxUpdateItem::kCanUpdate); 1134 CrxUpdateItem::kCanUpdate);
1116 DCHECK_EQ(count, 1ul); 1135 DCHECK_EQ(count, 1ul);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 state_ = UNBLOCKED; 1224 state_ = UNBLOCKED;
1206 } 1225 }
1207 1226
1208 // The component update factory. Using the component updater as a singleton 1227 // The component update factory. Using the component updater as a singleton
1209 // is the job of the browser process. 1228 // is the job of the browser process.
1210 ComponentUpdateService* ComponentUpdateServiceFactory( 1229 ComponentUpdateService* ComponentUpdateServiceFactory(
1211 ComponentUpdateService::Configurator* config) { 1230 ComponentUpdateService::Configurator* config) {
1212 DCHECK(config); 1231 DCHECK(config);
1213 return new CrxUpdateService(config); 1232 return new CrxUpdateService(config);
1214 } 1233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698