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

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

Issue 105853002: Implement a background downloader using BITS in Windows Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trybots and Josh's feedback. Created 7 years 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 | Annotate | Revision Log
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 enum StepDelayInterval { 255 enum StepDelayInterval {
256 kStepDelayShort = 0, 256 kStepDelayShort = 0,
257 kStepDelayMedium, 257 kStepDelayMedium,
258 kStepDelayLong, 258 kStepDelayLong,
259 }; 259 };
260 260
261 void OnParseUpdateResponseSucceeded( 261 void OnParseUpdateResponseSucceeded(
262 const component_updater::UpdateResponse::Results& results); 262 const component_updater::UpdateResponse::Results& results);
263 void OnParseUpdateResponseFailed(const std::string& error_message); 263 void OnParseUpdateResponseFailed(const std::string& error_message);
264 264
265 void DownloadComplete(scoped_ptr<CRXContext> crx_context, 265 void DownloadComplete(
266 int error, 266 scoped_ptr<CRXContext> crx_context,
267 const base::FilePath& response); 267 const component_updater::CrxDownloader::Result& download_result);
268 268
269 Status OnDemandUpdateInternal(CrxUpdateItem* item); 269 Status OnDemandUpdateInternal(CrxUpdateItem* item);
270 270
271 void ProcessPendingItems(); 271 void ProcessPendingItems();
272 272
273 CrxUpdateItem* FindReadyComponent(); 273 CrxUpdateItem* FindReadyComponent();
274 274
275 void UpdateComponent(CrxUpdateItem* workitem); 275 void UpdateComponent(CrxUpdateItem* workitem);
276 276
277 void AddItemToUpdateCheck(CrxUpdateItem* item, 277 void AddItemToUpdateCheck(CrxUpdateItem* item,
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 crx_context->installer = workitem->component.installer; 665 crx_context->installer = workitem->component.installer;
666 crx_context->fingerprint = workitem->next_fp; 666 crx_context->fingerprint = workitem->next_fp;
667 GURL package_url; 667 GURL package_url;
668 if (CanTryDiffUpdate(workitem, *config_)) { 668 if (CanTryDiffUpdate(workitem, *config_)) {
669 package_url = workitem->diff_crx_url; 669 package_url = workitem->diff_crx_url;
670 ChangeItemState(workitem, CrxUpdateItem::kDownloadingDiff); 670 ChangeItemState(workitem, CrxUpdateItem::kDownloadingDiff);
671 } else { 671 } else {
672 package_url = workitem->crx_url; 672 package_url = workitem->crx_url;
673 ChangeItemState(workitem, CrxUpdateItem::kDownloading); 673 ChangeItemState(workitem, CrxUpdateItem::kDownloading);
674 } 674 }
675
676 // On demand component updates are always downloaded in foreground.
677 const bool is_background_download = !workitem->on_demand &&
678 config_->UseBackgroundDownloader();
679
675 crx_downloader_.reset(component_updater::CrxDownloader::Create( 680 crx_downloader_.reset(component_updater::CrxDownloader::Create(
681 is_background_download,
676 config_->RequestContext(), 682 config_->RequestContext(),
677 blocking_task_runner_, 683 blocking_task_runner_,
678 base::Bind(&CrxUpdateService::DownloadComplete, 684 base::Bind(&CrxUpdateService::DownloadComplete,
679 base::Unretained(this), 685 base::Unretained(this),
680 base::Passed(&crx_context)))); 686 base::Passed(&crx_context))));
681 crx_downloader_->StartDownloadFromUrl(package_url); 687 crx_downloader_->StartDownloadFromUrl(package_url);
682 } 688 }
683 689
684 // Sets the state of the component to be checked for updates. After the 690 // Sets the state of the component to be checked for updates. After the
685 // function is called, the <app> element corresponding to the |item| parameter 691 // function is called, the <app> element corresponding to the |item| parameter
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
900 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking, 906 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking,
901 CrxUpdateItem::kNoUpdate); 907 CrxUpdateItem::kNoUpdate);
902 DCHECK_GT(count, 0ul); 908 DCHECK_GT(count, 0ul);
903 ScheduleNextRun(kStepDelayLong); 909 ScheduleNextRun(kStepDelayLong);
904 } 910 }
905 911
906 // Called when the CRX package has been downloaded to a temporary location. 912 // Called when the CRX package has been downloaded to a temporary location.
907 // Here we fire the notifications and schedule the component-specific installer 913 // Here we fire the notifications and schedule the component-specific installer
908 // to be called in the file thread. 914 // to be called in the file thread.
909 void CrxUpdateService::DownloadComplete(scoped_ptr<CRXContext> crx_context, 915 void CrxUpdateService::DownloadComplete(
910 int error, 916 scoped_ptr<CRXContext> crx_context,
911 const base::FilePath& temp_crx_path) { 917 const component_updater::CrxDownloader::Result& download_result) {
912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
913 919
914 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id); 920 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id);
915 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff || 921 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff ||
916 crx->status == CrxUpdateItem::kDownloading); 922 crx->status == CrxUpdateItem::kDownloading);
917 923
918 if (error) { 924 if (download_result.error) {
919 if (crx->status == CrxUpdateItem::kDownloadingDiff) { 925 if (crx->status == CrxUpdateItem::kDownloadingDiff) {
920 crx->diff_error_category = kNetworkError; 926 crx->diff_error_category = kNetworkError;
921 crx->diff_error_code = error; 927 crx->diff_error_code = download_result.error;
922 crx->diff_update_failed = true; 928 crx->diff_update_failed = true;
923 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, 929 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff,
924 CrxUpdateItem::kCanUpdate); 930 CrxUpdateItem::kCanUpdate);
925 DCHECK_EQ(count, 1ul); 931 DCHECK_EQ(count, 1ul);
926 crx_downloader_.reset(); 932 crx_downloader_.reset();
927 933
928 ScheduleNextRun(kStepDelayShort); 934 ScheduleNextRun(kStepDelayShort);
929 return; 935 return;
930 } 936 }
931 crx->error_category = kNetworkError; 937 crx->error_category = kNetworkError;
932 crx->error_code = error; 938 crx->error_code = download_result.error;
933 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, 939 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading,
934 CrxUpdateItem::kNoUpdate); 940 CrxUpdateItem::kNoUpdate);
935 DCHECK_EQ(count, 1ul); 941 DCHECK_EQ(count, 1ul);
936 crx_downloader_.reset(); 942 crx_downloader_.reset();
937 943
938 // At this point, since both the differential and the full downloads failed, 944 // At this point, since both the differential and the full downloads failed,
939 // the update for this component has finished with an error. 945 // the update for this component has finished with an error.
940 ping_manager_->OnUpdateComplete(crx); 946 ping_manager_->OnUpdateComplete(crx);
941 947
942 // Move on to the next update, if there is one available. 948 // Move on to the next update, if there is one available.
(...skipping 10 matching lines...) Expand all
953 DCHECK_EQ(count, 1ul); 959 DCHECK_EQ(count, 1ul);
954 960
955 crx_downloader_.reset(); 961 crx_downloader_.reset();
956 962
957 // Why unretained? See comment at top of file. 963 // Why unretained? See comment at top of file.
958 blocking_task_runner_->PostDelayedTask( 964 blocking_task_runner_->PostDelayedTask(
959 FROM_HERE, 965 FROM_HERE,
960 base::Bind(&CrxUpdateService::Install, 966 base::Bind(&CrxUpdateService::Install,
961 base::Unretained(this), 967 base::Unretained(this),
962 base::Passed(&crx_context), 968 base::Passed(&crx_context),
963 temp_crx_path), 969 download_result.response),
964 base::TimeDelta::FromMilliseconds(config_->StepDelay())); 970 base::TimeDelta::FromMilliseconds(config_->StepDelay()));
965 } 971 }
966 } 972 }
967 973
968 // Install consists of digital signature verification, unpacking and then 974 // Install consists of digital signature verification, unpacking and then
969 // calling the component specific installer. All that is handled by the 975 // calling the component specific installer. All that is handled by the
970 // |unpacker|. If there is an error this function is in charge of deleting 976 // |unpacker|. If there is an error this function is in charge of deleting
971 // the files created. 977 // the files created.
972 void CrxUpdateService::Install(scoped_ptr<CRXContext> context, 978 void CrxUpdateService::Install(scoped_ptr<CRXContext> context,
973 const base::FilePath& crx_path) { 979 const base::FilePath& crx_path) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 } 1117 }
1112 1118
1113 // The component update factory. Using the component updater as a singleton 1119 // The component update factory. Using the component updater as a singleton
1114 // is the job of the browser process. 1120 // is the job of the browser process.
1115 ComponentUpdateService* ComponentUpdateServiceFactory( 1121 ComponentUpdateService* ComponentUpdateServiceFactory(
1116 ComponentUpdateService::Configurator* config) { 1122 ComponentUpdateService::Configurator* config) {
1117 DCHECK(config); 1123 DCHECK(config);
1118 return new CrxUpdateService(config); 1124 return new CrxUpdateService(config);
1119 } 1125 }
1120 1126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698