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