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

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

Issue 101043010: Added support for multiple urls in the component updater. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 Del* delegate_; 98 Del* delegate_;
99 Ctx* context_; 99 Ctx* context_;
100 }; 100 };
101 // This function creates the right DelegateWithContext using template inference. 101 // This function creates the right DelegateWithContext using template inference.
102 template <typename Del, typename Ctx> 102 template <typename Del, typename Ctx>
103 net::URLFetcherDelegate* MakeContextDelegate(Del* delegate, Ctx* context) { 103 net::URLFetcherDelegate* MakeContextDelegate(Del* delegate, Ctx* context) {
104 return new DelegateWithContext<Del, Ctx>(delegate, context); 104 return new DelegateWithContext<Del, Ctx>(delegate, context);
105 } 105 }
106 106
107 // Returns true if a differential update is available for the update item.
108 bool IsDiffUpdateAvailable(const CrxUpdateItem* update_item) {
109 return update_item->diff_crx_url.is_valid();
110 }
111
112 // Returns true if a differential update is available, it has not failed yet, 107 // Returns true if a differential update is available, it has not failed yet,
113 // and the configuration allows it. 108 // and the configuration allows it.
114 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, 109 bool CanTryDiffUpdate(const CrxUpdateItem* update_item,
115 const ComponentUpdateService::Configurator& config) { 110 const ComponentUpdateService::Configurator& config) {
116 return IsDiffUpdateAvailable(update_item) && 111 return component_updater::HasDiffUpdate(update_item) &&
117 !update_item->diff_update_failed && 112 !update_item->diff_update_failed &&
118 config.DeltasEnabled(); 113 config.DeltasEnabled();
119 } 114 }
120 115
121 void AppendDownloadMetrics( 116 void AppendDownloadMetrics(
122 const std::vector<CrxDownloader::DownloadMetrics>& source, 117 const std::vector<CrxDownloader::DownloadMetrics>& source,
123 std::vector<CrxDownloader::DownloadMetrics>* destination) { 118 std::vector<CrxDownloader::DownloadMetrics>* destination) {
124 destination->insert(destination->end(), source.begin(), source.end()); 119 destination->insert(destination->end(), source.begin(), source.end());
125 } 120 }
126 121
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 return *it; 662 return *it;
668 return NULL; 663 return NULL;
669 } 664 }
670 665
671 void CrxUpdateService::UpdateComponent(CrxUpdateItem* workitem) { 666 void CrxUpdateService::UpdateComponent(CrxUpdateItem* workitem) {
672 scoped_ptr<CRXContext> crx_context(new CRXContext); 667 scoped_ptr<CRXContext> crx_context(new CRXContext);
673 crx_context->pk_hash = workitem->component.pk_hash; 668 crx_context->pk_hash = workitem->component.pk_hash;
674 crx_context->id = workitem->id; 669 crx_context->id = workitem->id;
675 crx_context->installer = workitem->component.installer; 670 crx_context->installer = workitem->component.installer;
676 crx_context->fingerprint = workitem->next_fp; 671 crx_context->fingerprint = workitem->next_fp;
677 GURL package_url; 672 const std::vector<GURL>* urls = NULL;
678 if (CanTryDiffUpdate(workitem, *config_)) { 673 if (CanTryDiffUpdate(workitem, *config_)) {
679 package_url = workitem->diff_crx_url; 674 urls = &workitem->crx_diffurls;
680 ChangeItemState(workitem, CrxUpdateItem::kDownloadingDiff); 675 ChangeItemState(workitem, CrxUpdateItem::kDownloadingDiff);
681 } else { 676 } else {
682 package_url = workitem->crx_url; 677 urls = &workitem->crx_urls;
683 ChangeItemState(workitem, CrxUpdateItem::kDownloading); 678 ChangeItemState(workitem, CrxUpdateItem::kDownloading);
684 } 679 }
685 680
686 // On demand component updates are always downloaded in foreground. 681 // On demand component updates are always downloaded in foreground.
687 const bool is_background_download = !workitem->on_demand && 682 const bool is_background_download = !workitem->on_demand &&
688 config_->UseBackgroundDownloader(); 683 config_->UseBackgroundDownloader();
689 684
690 crx_downloader_.reset(CrxDownloader::Create( 685 crx_downloader_.reset(CrxDownloader::Create(
691 is_background_download, 686 is_background_download,
692 config_->RequestContext(), 687 config_->RequestContext(),
693 blocking_task_runner_, 688 blocking_task_runner_,
694 base::Bind(&CrxUpdateService::DownloadComplete, 689 base::Bind(&CrxUpdateService::DownloadComplete,
695 base::Unretained(this), 690 base::Unretained(this),
696 base::Passed(&crx_context)))); 691 base::Passed(&crx_context))));
697 crx_downloader_->StartDownloadFromUrl(package_url); 692 crx_downloader_->StartDownload(*urls);
698 } 693 }
699 694
700 // Sets the state of the component to be checked for updates. After the 695 // Sets the state of the component to be checked for updates. After the
701 // function is called, the <app> element corresponding to the |item| parameter 696 // function is called, the <app> element corresponding to the |item| parameter
702 // is appended to the |update_check_items|. 697 // is appended to the |update_check_items|.
703 void CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item, 698 void CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item,
704 std::string* update_check_items) { 699 std::string* update_check_items) {
705 // The app element corresponding to an update items looks like this: 700 // The app element corresponding to an update items looks like this:
706 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 701 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
707 // version="0.1.2.3" installsource="ondemand"> 702 // version="0.1.2.3" installsource="ondemand">
(...skipping 25 matching lines...) Expand all
733 "<package fp=\"%s\"/>" 728 "<package fp=\"%s\"/>"
734 "</packages>" 729 "</packages>"
735 "</app>", 730 "</app>",
736 app_attributes.c_str(), 731 app_attributes.c_str(),
737 item->component.fingerprint.c_str()); 732 item->component.fingerprint.c_str());
738 733
739 update_check_items->append(app); 734 update_check_items->append(app);
740 735
741 ChangeItemState(item, CrxUpdateItem::kChecking); 736 ChangeItemState(item, CrxUpdateItem::kChecking);
742 item->last_check = base::Time::Now(); 737 item->last_check = base::Time::Now();
743 item->crx_url = GURL(); 738 item->crx_urls.clear();
744 item->diff_crx_url = GURL(); 739 item->crx_diffurls.clear();
745 item->previous_version = item->component.version; 740 item->previous_version = item->component.version;
746 item->next_version = Version(); 741 item->next_version = Version();
747 item->previous_fp = item->component.fingerprint; 742 item->previous_fp = item->component.fingerprint;
748 item->next_fp.clear(); 743 item->next_fp.clear();
749 item->diff_update_failed = false; 744 item->diff_update_failed = false;
750 item->error_category = 0; 745 item->error_category = 0;
751 item->error_code = 0; 746 item->error_code = 0;
752 item->extra_code1 = 0; 747 item->extra_code1 = 0;
753 item->diff_error_category = 0; 748 item->diff_error_category = 0;
754 item->diff_error_code = 0; 749 item->diff_error_code = 0;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 } 849 }
855 850
856 // Parse the members of the result and queue an upgrade for this component. 851 // Parse the members of the result and queue an upgrade for this component.
857 crx->next_version = Version(it->manifest.version); 852 crx->next_version = Version(it->manifest.version);
858 853
859 typedef component_updater:: 854 typedef component_updater::
860 UpdateResponse::Result::Manifest::Package Package; 855 UpdateResponse::Result::Manifest::Package Package;
861 const Package& package(it->manifest.packages[0]); 856 const Package& package(it->manifest.packages[0]);
862 crx->next_fp = package.fingerprint; 857 crx->next_fp = package.fingerprint;
863 858
864 // Select the first url from the list of urls until support for 859 // Resolve the urls by combining the base urls with the package names.
865 // fall back urls is implemented. 860 for (size_t i = 0; i != it->crx_urls.size(); ++i) {
866 if (!it->crx_urls.empty()) 861 const GURL url(it->crx_urls[i].Resolve(package.name));
867 crx->crx_url = it->crx_urls[0].Resolve(package.name); 862 if (url.is_valid())
868 if (!it->crx_diffurls.empty()) 863 crx->crx_urls.push_back(url);
869 crx->diff_crx_url = it->crx_diffurls[0].Resolve(package.namediff); 864 }
865 for (size_t i = 0; i != it->crx_diffurls.size(); ++i) {
866 const GURL url(it->crx_diffurls[i].Resolve(package.namediff));
867 if (url.is_valid())
868 crx->crx_diffurls.push_back(url);
869 }
870 870
871 ChangeItemState(crx, CrxUpdateItem::kCanUpdate); 871 ChangeItemState(crx, CrxUpdateItem::kCanUpdate);
872 ++num_updates_pending; 872 ++num_updates_pending;
873 } 873 }
874 874
875 // All components that are not included in the update response are 875 // All components that are not included in the update response are
876 // considered up to date. 876 // considered up to date.
877 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); 877 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate);
878 878
879 // If there are updates pending we do a short wait, otherwise we take 879 // If there are updates pending we do a short wait, otherwise we take
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1105 }
1106 1106
1107 // The component update factory. Using the component updater as a singleton 1107 // The component update factory. Using the component updater as a singleton
1108 // is the job of the browser process. 1108 // is the job of the browser process.
1109 ComponentUpdateService* ComponentUpdateServiceFactory( 1109 ComponentUpdateService* ComponentUpdateServiceFactory(
1110 ComponentUpdateService::Configurator* config) { 1110 ComponentUpdateService::Configurator* config) {
1111 DCHECK(config); 1111 DCHECK(config);
1112 return new CrxUpdateService(config); 1112 return new CrxUpdateService(config);
1113 } 1113 }
1114 1114
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698