OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/update_check_scheduler.h" | 5 #include "update_engine/update_check_scheduler.h" |
6 | 6 |
7 #include "update_engine/utils.h" | 7 #include "update_engine/utils.h" |
8 | 8 |
9 namespace chromeos_update_engine { | 9 namespace chromeos_update_engine { |
10 | 10 |
11 const int UpdateCheckScheduler::kTimeoutOnce = 7 * 60; // at 7 minutes | 11 const int UpdateCheckScheduler::kTimeoutOnce = 7 * 60; // at 7 minutes |
12 const int UpdateCheckScheduler::kTimeoutPeriodic = 45 * 60; // every 45 minutes | 12 const int UpdateCheckScheduler::kTimeoutPeriodic = 45 * 60; // every 45 minutes |
13 const int UpdateCheckScheduler::kTimeoutRegularFuzz = 10 * 60; // +/- 5 minutes | 13 const int UpdateCheckScheduler::kTimeoutRegularFuzz = 10 * 60; // +/- 5 minutes |
14 const int UpdateCheckScheduler::kTimeoutMaxBackoff = 4 * 60 * 60; // 4 hours | 14 const int UpdateCheckScheduler::kTimeoutMaxBackoff = 4 * 60 * 60; // 4 hours |
15 | 15 |
16 UpdateCheckScheduler::UpdateCheckScheduler(UpdateAttempter* update_attempter) | 16 UpdateCheckScheduler::UpdateCheckScheduler(UpdateAttempter* update_attempter) |
17 : update_attempter_(update_attempter), | 17 : update_attempter_(update_attempter), |
18 enabled_(false), | 18 enabled_(false), |
19 scheduled_(false), | 19 scheduled_(false), |
20 last_interval_(0) {} | 20 last_interval_(0), |
| 21 poll_interval_(0) {} |
21 | 22 |
22 UpdateCheckScheduler::~UpdateCheckScheduler() {} | 23 UpdateCheckScheduler::~UpdateCheckScheduler() {} |
23 | 24 |
24 void UpdateCheckScheduler::Run() { | 25 void UpdateCheckScheduler::Run() { |
25 enabled_ = false; | 26 enabled_ = false; |
26 update_attempter_->set_update_check_scheduler(NULL); | 27 update_attempter_->set_update_check_scheduler(NULL); |
27 | 28 |
28 if (!IsOfficialBuild()) { | 29 if (!IsOfficialBuild()) { |
29 LOG(WARNING) << "Non-official build: periodic update checks disabled."; | 30 LOG(WARNING) << "Non-official build: periodic update checks disabled."; |
30 return; | 31 return; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // seems better to crash in such cases and restart the update_engine daemon | 84 // seems better to crash in such cases and restart the update_engine daemon |
84 // into, hopefully, a known good state. | 85 // into, hopefully, a known good state. |
85 CHECK(me->update_attempter_->status() != UPDATE_STATUS_IDLE || | 86 CHECK(me->update_attempter_->status() != UPDATE_STATUS_IDLE || |
86 !me->CanSchedule()); | 87 !me->CanSchedule()); |
87 return FALSE; // Don't run again. | 88 return FALSE; // Don't run again. |
88 } | 89 } |
89 | 90 |
90 void UpdateCheckScheduler::ComputeNextIntervalAndFuzz(int* next_interval, | 91 void UpdateCheckScheduler::ComputeNextIntervalAndFuzz(int* next_interval, |
91 int* next_fuzz) { | 92 int* next_fuzz) { |
92 int interval = 0; | 93 int interval = 0; |
93 int fuzz = 0; | 94 if (poll_interval_ > 0) { |
94 // Implements exponential back off on 500 (Internal Server Error) and 503 | 95 // Server-dictated poll interval. |
95 // (Service Unavailable) HTTP response codes. | 96 interval = poll_interval_; |
96 if (update_attempter_->http_response_code() == 500 || | 97 LOG(WARNING) << "Using server-dictated poll interval: " << interval; |
97 update_attempter_->http_response_code() == 503) { | 98 } else if (update_attempter_->http_response_code() == 500 || |
| 99 update_attempter_->http_response_code() == 503) { |
| 100 // Implements exponential back off on 500 (Internal Server Error) and 503 |
| 101 // (Service Unavailable) HTTP response codes. |
98 interval = 2 * last_interval_; | 102 interval = 2 * last_interval_; |
99 if (interval > kTimeoutMaxBackoff) { | 103 LOG(WARNING) << "Exponential back off due to 500/503 HTTP response code."; |
100 interval = kTimeoutMaxBackoff; | |
101 } | |
102 // Exponential back off is fuzzed by +/- |interval|/2. | |
103 fuzz = interval; | |
104 } | 104 } |
| 105 if (interval > kTimeoutMaxBackoff) { |
| 106 interval = kTimeoutMaxBackoff; |
| 107 } |
| 108 // Back off and server-dictated poll intervals are fuzzed by +/- |interval|/2. |
| 109 int fuzz = interval; |
| 110 |
105 // Ensures that under normal conditions the regular update check interval and | 111 // Ensures that under normal conditions the regular update check interval and |
106 // fuzz are used. Also covers the case where back off is required based on the | 112 // fuzz are used. Also covers the case where back off is required based on the |
107 // initial update check. | 113 // initial update check. |
108 if (interval < kTimeoutPeriodic) { | 114 if (interval < kTimeoutPeriodic) { |
109 interval = kTimeoutPeriodic; | 115 interval = kTimeoutPeriodic; |
110 fuzz = kTimeoutRegularFuzz; | 116 fuzz = kTimeoutRegularFuzz; |
111 } | 117 } |
112 *next_interval = interval; | 118 *next_interval = interval; |
113 *next_fuzz = fuzz; | 119 *next_fuzz = fuzz; |
114 } | 120 } |
115 | 121 |
116 void UpdateCheckScheduler::ScheduleNextCheck() { | 122 void UpdateCheckScheduler::ScheduleNextCheck() { |
117 int interval, fuzz; | 123 int interval, fuzz; |
118 ComputeNextIntervalAndFuzz(&interval, &fuzz); | 124 ComputeNextIntervalAndFuzz(&interval, &fuzz); |
119 ScheduleCheck(interval, fuzz); | 125 ScheduleCheck(interval, fuzz); |
120 } | 126 } |
121 | 127 |
122 void UpdateCheckScheduler::SetUpdateStatus(UpdateStatus status) { | 128 void UpdateCheckScheduler::SetUpdateStatus(UpdateStatus status) { |
123 if (status == UPDATE_STATUS_IDLE) { | 129 if (status == UPDATE_STATUS_IDLE) { |
124 ScheduleNextCheck(); | 130 ScheduleNextCheck(); |
125 } | 131 } |
126 } | 132 } |
127 | 133 |
128 } // namespace chromeos_update_engine | 134 } // namespace chromeos_update_engine |
OLD | NEW |