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

Side by Side Diff: src/platform/update_engine/update_attempter.cc

Issue 2055008: Init: Start Update Engine at startup (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: Created 10 years, 7 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
OLDNEW
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_attempter.h" 5 #include "update_engine/update_attempter.h"
6 6
7 // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L 7 // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L
8 #ifndef _POSIX_C_SOURCE 8 #ifndef _POSIX_C_SOURCE
9 #define _POSIX_C_SOURCE 199309L 9 #define _POSIX_C_SOURCE 199309L
10 #endif // _POSIX_C_SOURCE 10 #endif // _POSIX_C_SOURCE
(...skipping 12 matching lines...) Expand all
23 #include "update_engine/postinstall_runner_action.h" 23 #include "update_engine/postinstall_runner_action.h"
24 #include "update_engine/set_bootable_flag_action.h" 24 #include "update_engine/set_bootable_flag_action.h"
25 #include "update_engine/update_check_action.h" 25 #include "update_engine/update_check_action.h"
26 26
27 using std::tr1::shared_ptr; 27 using std::tr1::shared_ptr;
28 using std::string; 28 using std::string;
29 using std::vector; 29 using std::vector;
30 30
31 namespace chromeos_update_engine { 31 namespace chromeos_update_engine {
32 32
33 const char* kUpdateCompletedMarker = "/tmp/update_engine_autoupdate_completed";
34
33 namespace { 35 namespace {
34 // Returns true on success. 36 // Returns true on success.
35 bool GetCPUClockTime(struct timespec* out) { 37 bool GetCPUClockTime(struct timespec* out) {
36 return clock_gettime(CLOCK_REALTIME, out) == 0; 38 return clock_gettime(CLOCK_REALTIME, out) == 0;
37 } 39 }
38 // Returns stop - start. 40 // Returns stop - start.
39 struct timespec CPUClockTimeElapsed(const struct timespec& start, 41 struct timespec CPUClockTimeElapsed(const struct timespec& start,
40 const struct timespec& stop) { 42 const struct timespec& stop) {
41 CHECK(start.tv_sec >= 0); 43 CHECK(start.tv_sec >= 0);
42 CHECK(stop.tv_sec >= 0); 44 CHECK(stop.tv_sec >= 0);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 case UPDATE_STATUS_FINALIZING: 79 case UPDATE_STATUS_FINALIZING:
78 return "UPDATE_STATUS_FINALIZING"; 80 return "UPDATE_STATUS_FINALIZING";
79 case UPDATE_STATUS_UPDATED_NEED_REBOOT: 81 case UPDATE_STATUS_UPDATED_NEED_REBOOT:
80 return "UPDATE_STATUS_UPDATED_NEED_REBOOT"; 82 return "UPDATE_STATUS_UPDATED_NEED_REBOOT";
81 default: 83 default:
82 return "unknown status"; 84 return "unknown status";
83 } 85 }
84 } 86 }
85 87
86 void UpdateAttempter::Update(bool force_full_update) { 88 void UpdateAttempter::Update(bool force_full_update) {
89 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
90 LOG(INFO) << "Not updating b/c we already updated and we're waiting for "
91 << "reboot";
92 return;
93 }
94 if (status_ != UPDATE_STATUS_IDLE) {
95 // Update in progress. Do nothing
96 return;
97 }
87 full_update_ = force_full_update; 98 full_update_ = force_full_update;
88 CHECK(!processor_.IsRunning()); 99 CHECK(!processor_.IsRunning());
89 processor_.set_delegate(this); 100 processor_.set_delegate(this);
90 101
91 // Actions: 102 // Actions:
92 shared_ptr<OmahaRequestPrepAction> request_prep_action( 103 shared_ptr<OmahaRequestPrepAction> request_prep_action(
93 new OmahaRequestPrepAction(force_full_update)); 104 new OmahaRequestPrepAction(force_full_update));
94 shared_ptr<UpdateCheckAction> update_check_action( 105 shared_ptr<UpdateCheckAction> update_check_action(
95 new UpdateCheckAction(new LibcurlHttpFetcher)); 106 new UpdateCheckAction(new LibcurlHttpFetcher));
96 shared_ptr<OmahaResponseHandlerAction> response_handler_action( 107 shared_ptr<OmahaResponseHandlerAction> response_handler_action(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return; 171 return;
161 } 172 }
162 Update(false); 173 Update(false);
163 } 174 }
164 175
165 // Delegate methods: 176 // Delegate methods:
166 void UpdateAttempter::ProcessingDone(const ActionProcessor* processor, 177 void UpdateAttempter::ProcessingDone(const ActionProcessor* processor,
167 bool success) { 178 bool success) {
168 CHECK(response_handler_action_); 179 CHECK(response_handler_action_);
169 LOG(INFO) << "Processing Done."; 180 LOG(INFO) << "Processing Done.";
181 actions_.clear();
170 if (success) { 182 if (success) {
171 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); 183 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT);
184 utils::WriteFile(kUpdateCompletedMarker, "", 0);
172 } else { 185 } else {
173 LOG(INFO) << "Update failed."; 186 LOG(INFO) << "Update failed.";
174 SetStatusAndNotify(UPDATE_STATUS_IDLE); 187 SetStatusAndNotify(UPDATE_STATUS_IDLE);
175 } 188 }
176 } 189 }
177 190
178 void UpdateAttempter::ProcessingStopped(const ActionProcessor* processor) { 191 void UpdateAttempter::ProcessingStopped(const ActionProcessor* processor) {
179 download_progress_ = 0.0; 192 download_progress_ = 0.0;
180 SetStatusAndNotify(UPDATE_STATUS_IDLE); 193 SetStatusAndNotify(UPDATE_STATUS_IDLE);
194 actions_.clear();
181 } 195 }
182 196
183 // Called whenever an action has finished processing, either successfully 197 // Called whenever an action has finished processing, either successfully
184 // or otherwise. 198 // or otherwise.
185 void UpdateAttempter::ActionCompleted(ActionProcessor* processor, 199 void UpdateAttempter::ActionCompleted(ActionProcessor* processor,
186 AbstractAction* action, 200 AbstractAction* action,
187 bool success) { 201 bool success) {
188 // Reset download progress regardless of whether or not the download action 202 // Reset download progress regardless of whether or not the download action
189 // succeeded. 203 // succeeded.
190 const string type = action->Type(); 204 const string type = action->Type();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 update_engine_service_emit_status_update( 274 update_engine_service_emit_status_update(
261 dbus_service_, 275 dbus_service_,
262 last_checked_time_, 276 last_checked_time_,
263 download_progress_, 277 download_progress_,
264 UpdateStatusToString(status_), 278 UpdateStatusToString(status_),
265 new_version_.c_str(), 279 new_version_.c_str(),
266 new_size_); 280 new_size_);
267 } 281 }
268 282
269 } // namespace chromeos_update_engine 283 } // namespace chromeos_update_engine
OLDNEW
« src/platform/update_engine/main.cc ('K') | « src/platform/update_engine/update_attempter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698