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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Kicks off periodic update checks. The first check is scheduled | 43 // Kicks off periodic update checks. The first check is scheduled |
44 // |kTimeoutOnce| seconds from now. Subsequent checks are scheduled by | 44 // |kTimeoutOnce| seconds from now. Subsequent checks are scheduled by |
45 // ScheduleNextCheck, normally at |kTimeoutPeriodic|-second intervals. | 45 // ScheduleNextCheck, normally at |kTimeoutPeriodic|-second intervals. |
46 ScheduleCheck(kTimeoutOnce, kTimeoutRegularFuzz); | 46 ScheduleCheck(kTimeoutOnce, kTimeoutRegularFuzz); |
47 } | 47 } |
48 | 48 |
49 bool UpdateCheckScheduler::IsBootDeviceRemovable() { | 49 bool UpdateCheckScheduler::IsBootDeviceRemovable() { |
50 return utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice())); | 50 return utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice())); |
51 } | 51 } |
52 | 52 |
| 53 bool UpdateCheckScheduler::IsOOBEComplete() { |
| 54 return utils::IsOOBEComplete(); |
| 55 } |
| 56 |
53 bool UpdateCheckScheduler::IsOfficialBuild() { | 57 bool UpdateCheckScheduler::IsOfficialBuild() { |
54 return utils::IsOfficialBuild(); | 58 return utils::IsOfficialBuild(); |
55 } | 59 } |
56 | 60 |
57 guint UpdateCheckScheduler::GTimeoutAddSeconds(guint interval, | 61 guint UpdateCheckScheduler::GTimeoutAddSeconds(guint interval, |
58 GSourceFunc function) { | 62 GSourceFunc function) { |
59 return g_timeout_add_seconds(interval, function, this); | 63 return g_timeout_add_seconds(interval, function, this); |
60 } | 64 } |
61 | 65 |
62 void UpdateCheckScheduler::ScheduleCheck(int interval, int fuzz) { | 66 void UpdateCheckScheduler::ScheduleCheck(int interval, int fuzz) { |
63 if (!CanSchedule()) { | 67 if (!CanSchedule()) { |
64 return; | 68 return; |
65 } | 69 } |
66 last_interval_ = interval; | 70 last_interval_ = interval; |
67 interval = utils::FuzzInt(interval, fuzz); | 71 interval = utils::FuzzInt(interval, fuzz); |
68 if (interval < 0) { | 72 if (interval < 0) { |
69 interval = 0; | 73 interval = 0; |
70 } | 74 } |
71 GTimeoutAddSeconds(interval, StaticCheck); | 75 GTimeoutAddSeconds(interval, StaticCheck); |
72 scheduled_ = true; | 76 scheduled_ = true; |
73 LOG(INFO) << "Next update check in " << interval << " seconds."; | 77 LOG(INFO) << "Next update check in " << interval << " seconds."; |
74 } | 78 } |
75 | 79 |
76 gboolean UpdateCheckScheduler::StaticCheck(void* scheduler) { | 80 gboolean UpdateCheckScheduler::StaticCheck(void* scheduler) { |
77 UpdateCheckScheduler* me = reinterpret_cast<UpdateCheckScheduler*>(scheduler); | 81 UpdateCheckScheduler* me = reinterpret_cast<UpdateCheckScheduler*>(scheduler); |
78 CHECK(me->scheduled_); | 82 CHECK(me->scheduled_); |
79 me->scheduled_ = false; | 83 me->scheduled_ = false; |
80 me->update_attempter_->Update("", ""); | 84 if (me->IsOOBEComplete()) { |
| 85 me->update_attempter_->Update("", ""); |
| 86 } else { |
| 87 // Skips all automatic update checks if the OOBE process is not complete and |
| 88 // schedules a new check as if it is the first one. |
| 89 LOG(WARNING) << "Skipping update check because OOBE is not complete."; |
| 90 me->ScheduleCheck(kTimeoutOnce, kTimeoutRegularFuzz); |
| 91 } |
81 // This check ensures that future update checks will be or are already | 92 // This check ensures that future update checks will be or are already |
82 // scheduled. The check should never fail. A check failure means that there's | 93 // scheduled. The check should never fail. A check failure means that there's |
83 // a bug that will most likely prevent further automatic update checks. It | 94 // a bug that will most likely prevent further automatic update checks. It |
84 // seems better to crash in such cases and restart the update_engine daemon | 95 // seems better to crash in such cases and restart the update_engine daemon |
85 // into, hopefully, a known good state. | 96 // into, hopefully, a known good state. |
86 CHECK(me->update_attempter_->status() != UPDATE_STATUS_IDLE || | 97 CHECK(me->update_attempter_->status() != UPDATE_STATUS_IDLE || |
87 !me->CanSchedule()); | 98 !me->CanSchedule()); |
88 return FALSE; // Don't run again. | 99 return FALSE; // Don't run again. |
89 } | 100 } |
90 | 101 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 ScheduleCheck(interval, fuzz); | 136 ScheduleCheck(interval, fuzz); |
126 } | 137 } |
127 | 138 |
128 void UpdateCheckScheduler::SetUpdateStatus(UpdateStatus status) { | 139 void UpdateCheckScheduler::SetUpdateStatus(UpdateStatus status) { |
129 if (status == UPDATE_STATUS_IDLE) { | 140 if (status == UPDATE_STATUS_IDLE) { |
130 ScheduleNextCheck(); | 141 ScheduleNextCheck(); |
131 } | 142 } |
132 } | 143 } |
133 | 144 |
134 } // namespace chromeos_update_engine | 145 } // namespace chromeos_update_engine |
OLD | NEW |