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

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

Issue 169033004: Consider the last_check time when doing update checks for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand); 588 work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand);
589 if (it != work_items_.end()) 589 if (it != work_items_.end())
590 return *it; 590 return *it;
591 it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady); 591 it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady);
592 if (it != work_items_.end()) 592 if (it != work_items_.end())
593 return *it; 593 return *it;
594 return NULL; 594 return NULL;
595 } 595 }
596 596
597 // Prepares the components for an update check and initiates the request. 597 // Prepares the components for an update check and initiates the request.
598 // On demand components are always included in the update check request.
599 // Otherwise, only include components that have not been checked recently.
598 bool CrxUpdateService::CheckForUpdates() { 600 bool CrxUpdateService::CheckForUpdates() {
599 // All components are selected for the update check, regardless of when they 601 const base::TimeDelta minimum_recheck_wait_time =
600 // were last checked. More selective algorithms could be implemented in the 602 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait());
601 // future. 603 const base::Time now(base::Time::Now());
604
602 std::vector<CrxUpdateItem*> items_to_check; 605 std::vector<CrxUpdateItem*> items_to_check;
603 for (size_t i = 0; i != work_items_.size(); ++i) { 606 for (size_t i = 0; i != work_items_.size(); ++i) {
604 CrxUpdateItem* item = work_items_[i]; 607 CrxUpdateItem* item = work_items_[i];
605 DCHECK(item->status == CrxUpdateItem::kNew || 608 DCHECK(item->status == CrxUpdateItem::kNew ||
606 item->status == CrxUpdateItem::kNoUpdate || 609 item->status == CrxUpdateItem::kNoUpdate ||
607 item->status == CrxUpdateItem::kUpToDate || 610 item->status == CrxUpdateItem::kUpToDate ||
608 item->status == CrxUpdateItem::kUpdated); 611 item->status == CrxUpdateItem::kUpdated);
609 612
613 const base::TimeDelta time_since_last_checked(now - item->last_check);
614
615 if (!item->on_demand &&
616 time_since_last_checked < minimum_recheck_wait_time) {
617 continue;
618 }
619
610 ChangeItemState(item, CrxUpdateItem::kChecking); 620 ChangeItemState(item, CrxUpdateItem::kChecking);
611 621
612 item->last_check = base::Time::Now(); 622 item->last_check = now;
613 item->crx_urls.clear(); 623 item->crx_urls.clear();
614 item->crx_diffurls.clear(); 624 item->crx_diffurls.clear();
615 item->previous_version = item->component.version; 625 item->previous_version = item->component.version;
616 item->next_version = Version(); 626 item->next_version = Version();
617 item->previous_fp = item->component.fingerprint; 627 item->previous_fp = item->component.fingerprint;
618 item->next_fp.clear(); 628 item->next_fp.clear();
619 item->diff_update_failed = false; 629 item->diff_update_failed = false;
620 item->error_category = 0; 630 item->error_category = 0;
621 item->error_code = 0; 631 item->error_code = 0;
622 item->extra_code1 = 0; 632 item->extra_code1 = 0;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 ChangeItemState(crx, CrxUpdateItem::kCanUpdate); 764 ChangeItemState(crx, CrxUpdateItem::kCanUpdate);
755 ++num_updates_pending; 765 ++num_updates_pending;
756 } 766 }
757 767
758 // All components that are not included in the update response are 768 // All components that are not included in the update response are
759 // considered up to date. 769 // considered up to date.
760 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); 770 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate);
761 771
762 // If there are updates pending we do a short wait, otherwise we take 772 // If there are updates pending we do a short wait, otherwise we take
763 // a longer delay until we check the components again. 773 // a longer delay until we check the components again.
764 ScheduleNextRun(num_updates_pending > 0 ? kStepDelayShort : kStepDelayMedium); 774 ScheduleNextRun(num_updates_pending > 0 ? kStepDelayShort : kStepDelayLong);
765 } 775 }
766 776
767 // TODO: record UMA stats. 777 // TODO: record UMA stats.
768 void CrxUpdateService::OnUpdateCheckFailed(int error, 778 void CrxUpdateService::OnUpdateCheckFailed(int error,
769 const std::string& error_message) { 779 const std::string& error_message) {
770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
771 DCHECK(error); 781 DCHECK(error);
772 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking, 782 size_t count = ChangeItemStatus(CrxUpdateItem::kChecking,
773 CrxUpdateItem::kNoUpdate); 783 CrxUpdateItem::kNoUpdate);
774 DCHECK_GT(count, 0ul); 784 DCHECK_GT(count, 0ul);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 // The component update factory. Using the component updater as a singleton 1011 // The component update factory. Using the component updater as a singleton
1002 // is the job of the browser process. 1012 // is the job of the browser process.
1003 ComponentUpdateService* ComponentUpdateServiceFactory( 1013 ComponentUpdateService* ComponentUpdateServiceFactory(
1004 ComponentUpdateService::Configurator* config) { 1014 ComponentUpdateService::Configurator* config) {
1005 DCHECK(config); 1015 DCHECK(config);
1006 return new CrxUpdateService(config); 1016 return new CrxUpdateService(config);
1007 } 1017 }
1008 1018
1009 } // namespace component_updater 1019 } // namespace component_updater
1010 1020
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698