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

Unified Diff: update_attempter.cc

Issue 3167039: AU: Simplify the automatic update check code a little. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Rename to avoid confusion. Created 10 years, 4 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
« no previous file with comments | « update_attempter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: update_attempter.cc
diff --git a/update_attempter.cc b/update_attempter.cc
index 7873166551ec5bf7d2961ed391f03aa9c9336ee4..b0c470bc4872d1eb2ad419e9584f5ee573488af3 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -35,6 +35,21 @@ using std::vector;
namespace chromeos_update_engine {
+namespace {
+
+const int kTimeoutOnce = 7 * 60; // at 7 minutes
+const int kTimeoutPeriodic = 45 * 60; // every 45 minutes
+const int kTimeoutFuzz = 10 * 60; // +/- 5 minutes
+
+gboolean CheckForUpdatePeriodically(void* arg) {
+ UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg);
+ update_attempter->Update("", "");
+ update_attempter->SchedulePeriodicUpdateCheck(kTimeoutPeriodic);
+ return FALSE; // Don't run again.
+}
+
+} // namespace {}
+
const char* kUpdateCompletedMarker = "/tmp/update_engine_autoupdate_completed";
const char* UpdateStatusToString(UpdateStatus status) {
@@ -411,6 +426,27 @@ bool UpdateAttempter::ScheduleErrorEventAction() {
return true;
}
+void UpdateAttempter::InitiatePeriodicUpdateChecks() {
+ if (!utils::IsOfficialBuild()) {
+ LOG(WARNING) << "Non-official build: periodic update checks disabled.";
+ return;
+ }
+ if (utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice()))) {
+ LOG(WARNING) << "Removable device boot: periodic update checks disabled.";
+ return;
+ }
+ // Kick off periodic update checks. The first check is scheduled
+ // |kTimeoutOnce| seconds from now. Subsequent checks are scheduled
+ // at |kTimeoutPeriodic|-second intervals.
+ SchedulePeriodicUpdateCheck(kTimeoutOnce);
+}
+
+void UpdateAttempter::SchedulePeriodicUpdateCheck(int seconds) {
+ seconds = utils::FuzzInt(seconds, kTimeoutFuzz);
+ g_timeout_add_seconds(seconds, CheckForUpdatePeriodically, this);
+ LOG(INFO) << "Next update check in " << seconds << " seconds.";
+}
+
void UpdateAttempter::SetPriority(utils::ProcessPriority priority) {
if (priority_ == priority) {
return;
« no previous file with comments | « update_attempter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698