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

Unified Diff: chrome/browser/component_updater/component_updater_service.cc

Issue 12054003: Add an API to component_updater that asks to do an update check "now". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Do not use NextCheckDelay for non-running timer case (sideeffects). Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/component_updater_service.cc
diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc
index ed3d0752312512eb0ada958f1f834caa146a2ba9..34214aae3dde4dacbabd4ef5c61363bbb1b2e233 100644
--- a/chrome/browser/component_updater/component_updater_service.cc
+++ b/chrome/browser/component_updater/component_updater_service.cc
@@ -253,6 +253,7 @@ class CrxUpdateService : public ComponentUpdateService {
virtual Status Start() OVERRIDE;
virtual Status Stop() OVERRIDE;
virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE;
+ virtual Status PingUpdateCheck(const CrxComponent& component) OVERRIDE;
// The only purpose of this class is to forward the
// UtilityProcessHostClient callbacks so CrxUpdateService does
@@ -323,6 +324,9 @@ class CrxUpdateService : public ComponentUpdateService {
void ProcessPendingItems();
+ typedef std::vector<CrxUpdateItem*> UpdateItems;
+ bool ProcessWorkItems(const UpdateItems& work_items);
+
void ScheduleNextRun(bool step_delay);
void ParseManifest(const std::string& xml);
@@ -341,7 +345,6 @@ class CrxUpdateService : public ComponentUpdateService {
scoped_ptr<net::URLFetcher> url_fetcher_;
- typedef std::vector<CrxUpdateItem*> UpdateItems;
UpdateItems work_items_;
base::OneShotTimer<CrxUpdateService> timer_;
@@ -503,14 +506,73 @@ bool CrxUpdateService::AddItemToUpdateCheck(CrxUpdateItem* item,
return true;
}
-// Here is where the work gets scheduled. Given that our |work_items_| list
-// is expected to be ten or less items, we simply loop several times.
+// Here is where the work gets scheduled.
void CrxUpdateService::ProcessPendingItems() {
+ if (!ProcessWorkItems(work_items_)) {
+ // No components to update. Next check after the long sleep.
+ ScheduleNextRun(false);
+ }
+}
+
+// Start the process of checking for an update, for a particular component
+// that was previously registered. If the component does not exist return
+// kError, otherwise kOk.
+ComponentUpdateService::Status CrxUpdateService::PingUpdateCheck(
+ const CrxComponent& component) {
+ if (component.pk_hash.empty() ||
+ !component.version.IsValid() ||
+ !component.installer)
+ return kError;
+
+ std::string id =
+ HexStringToID(StringToLowerASCII(base::HexEncode(&component.pk_hash[0],
+ component.pk_hash.size()/2)));
+ CrxUpdateItem* uit;
+ uit = FindUpdateItemById(id);
+ if (!uit)
+ return kError;
+
+ UpdateItems one_item;
+ one_item.push_back(uit);
+
+ // The timer is may already be running when we do this ping.
+ // If the timer is running, cancel the currently scheduled timer,
+ // but remember the remaining time delta so that we can reset the timer
+ // to something comparable if there is nothing to do.
+ base::TimeDelta remaining_delay;
+ bool remaining_delay_set = false;
+ if (timer_.IsRunning()) {
+ remaining_delay = timer_.desired_run_time() - base::TimeTicks::Now();
+ remaining_delay_set = true;
+ timer_.Stop();
+ }
jvoung (off chromium) 2013/01/30 02:20:21 Good point about having fetches or installs in fli
+
+ if (!ProcessWorkItems(one_item)) {
+ // If there is work to do, the timer is re-scheduled by a work step.
+ // However, if there is nothing to actually do, we must schedule the
+ // timer here.
+ bool use_step_delay;
+ if (remaining_delay_set) {
+ use_step_delay =
+ remaining_delay < base::TimeDelta::FromSeconds(config_->StepDelay());
+ } else {
+ // Guess that it is not a step_delay.
+ use_step_delay = false;
+ }
+ ScheduleNextRun(use_step_delay);
+ }
+ return kOk;
+}
+
+// Here is where the work gets scheduled. Given that our |work_items| list
+// is expected to be ten or less items, we simply loop several times.
+// Returns |true| if there is work to be done.
+bool CrxUpdateService::ProcessWorkItems(const UpdateItems& work_items) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// First check for ready upgrades and do one. The first
// step is to fetch the crx package.
- for (UpdateItems::const_iterator it = work_items_.begin();
- it != work_items_.end(); ++it) {
+ for (UpdateItems::const_iterator it = work_items.begin();
+ it != work_items.end(); ++it) {
CrxUpdateItem* item = *it;
if (item->status != CrxUpdateItem::kCanUpdate)
continue;
@@ -524,7 +586,7 @@ void CrxUpdateService::ProcessPendingItems() {
0, item->crx_url, net::URLFetcher::GET,
MakeContextDelegate(this, context)));
StartFetch(url_fetcher_.get(), config_->RequestContext(), true);
- return;
+ return true;
}
for (size_t ix = 0; ix != arraysize(kManifestSources); ++ix) {
@@ -533,8 +595,8 @@ void CrxUpdateService::ProcessPendingItems() {
std::string query;
// If no pending upgrades, we check if there are new components we have not
// checked against the server. We can batch some in a single url request.
- for (UpdateItems::const_iterator it = work_items_.begin();
- it != work_items_.end(); ++it) {
+ for (UpdateItems::const_iterator it = work_items.begin();
+ it != work_items.end(); ++it) {
CrxUpdateItem* item = *it;
if (item->status != CrxUpdateItem::kNew)
continue;
@@ -550,8 +612,8 @@ void CrxUpdateService::ProcessPendingItems() {
const base::TimeDelta min_delta_time =
base::TimeDelta::FromSeconds(config_->MinimumReCheckWait());
- for (UpdateItems::const_iterator it = work_items_.begin();
- it != work_items_.end(); ++it) {
+ for (UpdateItems::const_iterator it = work_items.begin();
+ it != work_items.end(); ++it) {
CrxUpdateItem* item = *it;
if ((item->status != CrxUpdateItem::kNoUpdate) &&
(item->status != CrxUpdateItem::kUpToDate))
@@ -567,8 +629,8 @@ void CrxUpdateService::ProcessPendingItems() {
// Finally, we check components that we already updated as long as
// we have not checked them recently.
- for (UpdateItems::const_iterator it = work_items_.begin();
- it != work_items_.end(); ++it) {
+ for (UpdateItems::const_iterator it = work_items.begin();
+ it != work_items.end(); ++it) {
CrxUpdateItem* item = *it;
if (item->status != CrxUpdateItem::kUpdated)
continue;
@@ -595,14 +657,13 @@ void CrxUpdateService::ProcessPendingItems() {
0, GURL(full_query), net::URLFetcher::GET,
MakeContextDelegate(this, new UpdateContext())));
StartFetch(url_fetcher_.get(), config_->RequestContext(), false);
- return;
+ return true;
}
- // No components to update. Next check after the long sleep.
- ScheduleNextRun(false);
+ return false;
}
-// Caled when we got a response from the update server. It consists of an xml
+// Called when we got a response from the update server. It consists of an xml
// document following the omaha update scheme.
void CrxUpdateService::OnURLFetchComplete(const net::URLFetcher* source,
UpdateContext* context) {

Powered by Google App Engine
This is Rietveld 408576698