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

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

Issue 313373004: Eliminate the cooldown for direct calls to on-demand updates in CUS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); 194 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results);
195 void OnUpdateCheckFailed(int error, const std::string& error_message); 195 void OnUpdateCheckFailed(int error, const std::string& error_message);
196 196
197 void DownloadProgress(const std::string& component_id, 197 void DownloadProgress(const std::string& component_id,
198 const CrxDownloader::Result& download_result); 198 const CrxDownloader::Result& download_result);
199 199
200 void DownloadComplete(scoped_ptr<CRXContext> crx_context, 200 void DownloadComplete(scoped_ptr<CRXContext> crx_context,
201 const CrxDownloader::Result& download_result); 201 const CrxDownloader::Result& download_result);
202 202
203 Status OnDemandUpdateInternal(CrxUpdateItem* item); 203 Status OnDemandUpdateInternal(CrxUpdateItem* item);
204 Status OnDemandUpdateWithCooldown(CrxUpdateItem* item);
204 205
205 void ProcessPendingItems(); 206 void ProcessPendingItems();
206 207
207 // Find a component that is ready to update. 208 // Find a component that is ready to update.
208 CrxUpdateItem* FindReadyComponent() const; 209 CrxUpdateItem* FindReadyComponent() const;
209 210
210 // Prepares the components for an update check and initiates the request. 211 // Prepares the components for an update check and initiates the request.
211 // Returns true if an update check request has been made. Returns false if 212 // Returns true if an update check request has been made. Returns false if
212 // no update check was needed or an error occured. 213 // no update check was needed or an error occured.
213 bool CheckForUpdates(); 214 bool CheckForUpdates();
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 crx_id)); 950 crx_id));
950 return rt; 951 return rt;
951 } 952 }
952 953
953 void CrxUpdateService::OnNewResourceThrottle( 954 void CrxUpdateService::OnNewResourceThrottle(
954 base::WeakPtr<CUResourceThrottle> rt, 955 base::WeakPtr<CUResourceThrottle> rt,
955 const std::string& crx_id) { 956 const std::string& crx_id) {
956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
957 // Check if we can on-demand update, else unblock the request anyway. 958 // Check if we can on-demand update, else unblock the request anyway.
958 CrxUpdateItem* item = FindUpdateItemById(crx_id); 959 CrxUpdateItem* item = FindUpdateItemById(crx_id);
959 Status status = OnDemandUpdateInternal(item); 960 Status status = OnDemandUpdateWithCooldown(item);
960 if (status == kOk || status == kInProgress) { 961 if (status == kOk || status == kInProgress) {
961 item->throttles.push_back(rt); 962 item->throttles.push_back(rt);
962 return; 963 return;
963 } 964 }
964 UnblockResourceThrottle(rt); 965 UnblockResourceThrottle(rt);
965 } 966 }
966 967
967 // Start the process of checking for an update, for a particular component 968 // Start the process of checking for an update, for a particular component
968 // that was previously registered. 969 // that was previously registered.
969 // |component_id| is a value returned from GetCrxComponentID(). 970 // |component_id| is a value returned from GetCrxComponentID().
970 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdate( 971 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdate(
971 const std::string& component_id) { 972 const std::string& component_id) {
972 return OnDemandUpdateInternal(FindUpdateItemById(component_id)); 973 return OnDemandUpdateInternal(FindUpdateItemById(component_id));
973 } 974 }
974 975
975 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( 976 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateWithCooldown(
976 CrxUpdateItem* uit) { 977 CrxUpdateItem* uit) {
977 if (!uit) 978 if (!uit)
978 return kError; 979 return kError;
979 980
980 // Check if the request is too soon. 981 // Check if the request is too soon.
981 base::TimeDelta delta = base::Time::Now() - uit->last_check; 982 base::TimeDelta delta = base::Time::Now() - uit->last_check;
982 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) 983 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay()))
983 return kError; 984 return kError;
984 985
986 return OnDemandUpdateInternal(uit);
987 }
988
989 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal(
990 CrxUpdateItem* uit) {
991 if (!uit)
992 return kError;
993
985 Status service_status = GetServiceStatus(uit->status); 994 Status service_status = GetServiceStatus(uit->status);
986 // If the item is already in the process of being updated, there is 995 // If the item is already in the process of being updated, there is
987 // no point in this call, so return kInProgress. 996 // no point in this call, so return kInProgress.
988 if (service_status == kInProgress) 997 if (service_status == kInProgress)
989 return service_status; 998 return service_status;
990 999
991 // Otherwise the item was already checked a while back (or it is new), 1000 // Otherwise the item was already checked a while back (or it is new),
992 // set its status to kNew to give it a slightly higher priority. 1001 // set its status to kNew to give it a slightly higher priority.
993 ChangeItemState(uit, CrxUpdateItem::kNew); 1002 ChangeItemState(uit, CrxUpdateItem::kNew);
994 uit->on_demand = true; 1003 uit->on_demand = true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1073
1065 // The component update factory. Using the component updater as a singleton 1074 // The component update factory. Using the component updater as a singleton
1066 // is the job of the browser process. 1075 // is the job of the browser process.
1067 ComponentUpdateService* ComponentUpdateServiceFactory( 1076 ComponentUpdateService* ComponentUpdateServiceFactory(
1068 ComponentUpdateService::Configurator* config) { 1077 ComponentUpdateService::Configurator* config) {
1069 DCHECK(config); 1078 DCHECK(config);
1070 return new CrxUpdateService(config); 1079 return new CrxUpdateService(config);
1071 } 1080 }
1072 1081
1073 } // namespace component_updater 1082 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698