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

Side by Side Diff: update_attempter.cc

Issue 3042007: AU: A basic framework for sending error events when update attempt fails. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Change ERROR_EVENT to REPORTING_ERROR_EVENT status. Created 10 years, 5 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 | « update_attempter.h ('k') | 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 (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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 case UPDATE_STATUS_UPDATE_AVAILABLE: 76 case UPDATE_STATUS_UPDATE_AVAILABLE:
77 return "UPDATE_STATUS_UPDATE_AVAILABLE"; 77 return "UPDATE_STATUS_UPDATE_AVAILABLE";
78 case UPDATE_STATUS_DOWNLOADING: 78 case UPDATE_STATUS_DOWNLOADING:
79 return "UPDATE_STATUS_DOWNLOADING"; 79 return "UPDATE_STATUS_DOWNLOADING";
80 case UPDATE_STATUS_VERIFYING: 80 case UPDATE_STATUS_VERIFYING:
81 return "UPDATE_STATUS_VERIFYING"; 81 return "UPDATE_STATUS_VERIFYING";
82 case UPDATE_STATUS_FINALIZING: 82 case UPDATE_STATUS_FINALIZING:
83 return "UPDATE_STATUS_FINALIZING"; 83 return "UPDATE_STATUS_FINALIZING";
84 case UPDATE_STATUS_UPDATED_NEED_REBOOT: 84 case UPDATE_STATUS_UPDATED_NEED_REBOOT:
85 return "UPDATE_STATUS_UPDATED_NEED_REBOOT"; 85 return "UPDATE_STATUS_UPDATED_NEED_REBOOT";
86 case UPDATE_STATUS_REPORTING_ERROR_EVENT:
87 return "UPDATE_STATUS_REPORTING_ERROR_EVENT";
86 default: 88 default:
87 return "unknown status"; 89 return "unknown status";
88 } 90 }
89 } 91 }
90 92
91 void UpdateAttempter::Update() { 93 void UpdateAttempter::Update() {
92 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { 94 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
93 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " 95 LOG(INFO) << "Not updating b/c we already updated and we're waiting for "
94 << "reboot"; 96 << "reboot";
95 return; 97 return;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 194 }
193 Update(); 195 Update();
194 } 196 }
195 197
196 // Delegate methods: 198 // Delegate methods:
197 void UpdateAttempter::ProcessingDone(const ActionProcessor* processor, 199 void UpdateAttempter::ProcessingDone(const ActionProcessor* processor,
198 ActionExitCode code) { 200 ActionExitCode code) {
199 CHECK(response_handler_action_); 201 CHECK(response_handler_action_);
200 LOG(INFO) << "Processing Done."; 202 LOG(INFO) << "Processing Done.";
201 actions_.clear(); 203 actions_.clear();
204
205 if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
206 LOG(INFO) << "Error event sent.";
207 SetStatusAndNotify(UPDATE_STATUS_IDLE);
208 return;
209 }
210
202 if (code == kActionCodeSuccess) { 211 if (code == kActionCodeSuccess) {
203 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); 212 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT);
204 utils::WriteFile(kUpdateCompletedMarker, "", 0); 213 utils::WriteFile(kUpdateCompletedMarker, "", 0);
205 214
206 // Report the time it took to update the system. 215 // Report the time it took to update the system.
207 int64_t update_time = time(NULL) - last_checked_time_; 216 int64_t update_time = time(NULL) - last_checked_time_;
208 metrics_lib_->SendToUMA("Installer.UpdateTime", 217 metrics_lib_->SendToUMA("Installer.UpdateTime",
209 static_cast<int>(update_time), // sample 218 static_cast<int>(update_time), // sample
210 1, // min = 1 second 219 1, // min = 1 second
211 20 * 60, // max = 20 minutes 220 20 * 60, // max = 20 minutes
212 50); // buckets 221 50); // buckets
213 } else { 222 return;
214 LOG(INFO) << "Update failed.";
215 SetStatusAndNotify(UPDATE_STATUS_IDLE);
216 } 223 }
224
225 LOG(INFO) << "Update failed.";
226 if (ScheduleErrorEventAction())
227 return;
228 SetStatusAndNotify(UPDATE_STATUS_IDLE);
217 } 229 }
218 230
219 void UpdateAttempter::ProcessingStopped(const ActionProcessor* processor) { 231 void UpdateAttempter::ProcessingStopped(const ActionProcessor* processor) {
220 download_progress_ = 0.0; 232 download_progress_ = 0.0;
221 SetStatusAndNotify(UPDATE_STATUS_IDLE); 233 SetStatusAndNotify(UPDATE_STATUS_IDLE);
222 actions_.clear(); 234 actions_.clear();
235 error_event_.reset(NULL);
223 } 236 }
224 237
225 // Called whenever an action has finished processing, either successfully 238 // Called whenever an action has finished processing, either successfully
226 // or otherwise. 239 // or otherwise.
227 void UpdateAttempter::ActionCompleted(ActionProcessor* processor, 240 void UpdateAttempter::ActionCompleted(ActionProcessor* processor,
228 AbstractAction* action, 241 AbstractAction* action,
229 ActionExitCode code) { 242 ActionExitCode code) {
230 // Reset download progress regardless of whether or not the download action 243 // Reset download progress regardless of whether or not the download action
231 // succeeded. 244 // succeeded.
232 const string type = action->Type(); 245 const string type = action->Type();
233 if (type == DownloadAction::StaticType()) 246 if (type == DownloadAction::StaticType())
234 download_progress_ = 0.0; 247 download_progress_ = 0.0;
235 if (code != kActionCodeSuccess) 248 if (code != kActionCodeSuccess) {
249 // On failure, schedule an error event to be sent to Omaha. For
250 // now assume that Omaha response action failure means that
251 // there's no update so don't send an event. Also, double check
252 // that the failure has not occurred while sending an error event
253 // -- in which case don't schedule another. This shouldn't really
254 // happen but just in case...
255 if (type != OmahaResponseHandlerAction::StaticType() &&
256 status_ != UPDATE_STATUS_REPORTING_ERROR_EVENT) {
257 CreatePendingErrorEvent(code);
258 }
236 return; 259 return;
260 }
237 // Find out which action completed. 261 // Find out which action completed.
238 if (type == OmahaResponseHandlerAction::StaticType()) { 262 if (type == OmahaResponseHandlerAction::StaticType()) {
239 SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING); 263 SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING);
240 OmahaResponseHandlerAction* omaha_response_handler_action = 264 OmahaResponseHandlerAction* omaha_response_handler_action =
241 dynamic_cast<OmahaResponseHandlerAction*>(action); 265 dynamic_cast<OmahaResponseHandlerAction*>(action);
242 CHECK(omaha_response_handler_action); 266 CHECK(omaha_response_handler_action);
243 const InstallPlan& plan = omaha_response_handler_action->install_plan(); 267 const InstallPlan& plan = omaha_response_handler_action->install_plan();
244 last_checked_time_ = time(NULL); 268 last_checked_time_ = time(NULL);
245 // TODO(adlr): put version in InstallPlan 269 // TODO(adlr): put version in InstallPlan
246 new_version_ = "0.0.0.0"; 270 new_version_ = "0.0.0.0";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 GetCPUClockTime(&last_notify_time_); 325 GetCPUClockTime(&last_notify_time_);
302 update_engine_service_emit_status_update( 326 update_engine_service_emit_status_update(
303 dbus_service_, 327 dbus_service_,
304 last_checked_time_, 328 last_checked_time_,
305 download_progress_, 329 download_progress_,
306 UpdateStatusToString(status_), 330 UpdateStatusToString(status_),
307 new_version_.c_str(), 331 new_version_.c_str(),
308 new_size_); 332 new_size_);
309 } 333 }
310 334
335 void UpdateAttempter::CreatePendingErrorEvent(ActionExitCode code) {
336 if (error_event_.get()) {
337 // This shouldn't really happen.
338 LOG(WARNING) << "There's already an existing pending error event.";
339 return;
340 }
341 error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete,
342 OmahaEvent::kResultError,
343 code));
344 }
345
346 bool UpdateAttempter::ScheduleErrorEventAction() {
347 if (error_event_.get() == NULL)
348 return false;
349
350 shared_ptr<OmahaRequestAction> error_event_action(
351 new OmahaRequestAction(omaha_request_params_,
352 error_event_.release(), // Pass ownership.
353 new LibcurlHttpFetcher));
354 actions_.push_back(shared_ptr<AbstractAction>(error_event_action));
355 processor_.EnqueueAction(error_event_action.get());
356 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT);
357 processor_.StartProcessing();
358 return true;
359 }
360
311 } // namespace chromeos_update_engine 361 } // namespace chromeos_update_engine
OLDNEW
« 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