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

Side by Side Diff: update_attempter.cc

Issue 2819059: Narrow down to one generic error per action. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Rename SwitchToActionSpecificCode to GetErrorCodeForAction. 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
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: 86 case UPDATE_STATUS_REPORTING_ERROR_EVENT:
87 return "UPDATE_STATUS_REPORTING_ERROR_EVENT"; 87 return "UPDATE_STATUS_REPORTING_ERROR_EVENT";
88 default: 88 default:
89 return "unknown status"; 89 return "unknown status";
90 } 90 }
91 } 91 }
92 92
93 // Turns a generic kActionCodeError to a generic error code specific
94 // to |action| (e.g., kActionCodeFilesystemCopierError). If |code| is
95 // not kActionCodeError, or the action is not matched, returns |code|
96 // unchanged.
97 ActionExitCode GetErrorCodeForAction(AbstractAction* action,
98 ActionExitCode code) {
99 if (code != kActionCodeError)
100 return code;
101
102 const string type = action->Type();
103 if (type == OmahaRequestAction::StaticType())
104 return kActionCodeOmahaRequestError;
105 if (type == OmahaResponseHandlerAction::StaticType())
106 return kActionCodeOmahaResponseHandlerError;
107 if (type == FilesystemCopierAction::StaticType())
108 return kActionCodeFilesystemCopierError;
109 if (type == PostinstallRunnerAction::StaticType())
110 return kActionCodePostinstallRunnerError;
111 if (type == SetBootableFlagAction::StaticType())
112 return kActionCodeSetBootableFlagError;
113
114 return code;
115 }
116
93 void UpdateAttempter::Update() { 117 void UpdateAttempter::Update() {
94 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { 118 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
95 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " 119 LOG(INFO) << "Not updating b/c we already updated and we're waiting for "
96 << "reboot"; 120 << "reboot";
97 return; 121 return;
98 } 122 }
99 if (status_ != UPDATE_STATUS_IDLE) { 123 if (status_ != UPDATE_STATUS_IDLE) {
100 // Update in progress. Do nothing 124 // Update in progress. Do nothing
101 return; 125 return;
102 } 126 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // or otherwise. 263 // or otherwise.
240 void UpdateAttempter::ActionCompleted(ActionProcessor* processor, 264 void UpdateAttempter::ActionCompleted(ActionProcessor* processor,
241 AbstractAction* action, 265 AbstractAction* action,
242 ActionExitCode code) { 266 ActionExitCode code) {
243 // Reset download progress regardless of whether or not the download action 267 // Reset download progress regardless of whether or not the download action
244 // succeeded. 268 // succeeded.
245 const string type = action->Type(); 269 const string type = action->Type();
246 if (type == DownloadAction::StaticType()) 270 if (type == DownloadAction::StaticType())
247 download_progress_ = 0.0; 271 download_progress_ = 0.0;
248 if (code != kActionCodeSuccess) { 272 if (code != kActionCodeSuccess) {
249 // On failure, schedule an error event to be sent to Omaha. For 273 // On failure, schedule an error event to be sent to Omaha.
250 // now assume that Omaha response action failure means that 274 CreatePendingErrorEvent(action, code);
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 }
259 return; 275 return;
260 } 276 }
261 // Find out which action completed. 277 // Find out which action completed.
262 if (type == OmahaResponseHandlerAction::StaticType()) { 278 if (type == OmahaResponseHandlerAction::StaticType()) {
263 SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING); 279 SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING);
264 OmahaResponseHandlerAction* omaha_response_handler_action = 280 OmahaResponseHandlerAction* omaha_response_handler_action =
265 dynamic_cast<OmahaResponseHandlerAction*>(action); 281 dynamic_cast<OmahaResponseHandlerAction*>(action);
266 CHECK(omaha_response_handler_action); 282 CHECK(omaha_response_handler_action);
267 const InstallPlan& plan = omaha_response_handler_action->install_plan(); 283 const InstallPlan& plan = omaha_response_handler_action->install_plan();
268 last_checked_time_ = time(NULL); 284 last_checked_time_ = time(NULL);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 GetCPUClockTime(&last_notify_time_); 341 GetCPUClockTime(&last_notify_time_);
326 update_engine_service_emit_status_update( 342 update_engine_service_emit_status_update(
327 dbus_service_, 343 dbus_service_,
328 last_checked_time_, 344 last_checked_time_,
329 download_progress_, 345 download_progress_,
330 UpdateStatusToString(status_), 346 UpdateStatusToString(status_),
331 new_version_.c_str(), 347 new_version_.c_str(),
332 new_size_); 348 new_size_);
333 } 349 }
334 350
335 void UpdateAttempter::CreatePendingErrorEvent(ActionExitCode code) { 351 void UpdateAttempter::CreatePendingErrorEvent(AbstractAction* action,
352 ActionExitCode code) {
336 if (error_event_.get()) { 353 if (error_event_.get()) {
337 // This shouldn't really happen. 354 // This shouldn't really happen.
338 LOG(WARNING) << "There's already an existing pending error event."; 355 LOG(WARNING) << "There's already an existing pending error event.";
339 return; 356 return;
340 } 357 }
358
359 // For now assume that Omaha response action failure means that
360 // there's no update so don't send an event. Also, double check that
361 // the failure has not occurred while sending an error event -- in
362 // which case don't schedule another. This shouldn't really happen
363 // but just in case...
364 if (action->Type() == OmahaResponseHandlerAction::StaticType() ||
365 status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
366 return;
367 }
368
369 code = GetErrorCodeForAction(action, code);
341 error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, 370 error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete,
342 OmahaEvent::kResultError, 371 OmahaEvent::kResultError,
343 code)); 372 code));
344 } 373 }
345 374
346 bool UpdateAttempter::ScheduleErrorEventAction() { 375 bool UpdateAttempter::ScheduleErrorEventAction() {
347 if (error_event_.get() == NULL) 376 if (error_event_.get() == NULL)
348 return false; 377 return false;
349 378
350 shared_ptr<OmahaRequestAction> error_event_action( 379 shared_ptr<OmahaRequestAction> error_event_action(
351 new OmahaRequestAction(omaha_request_params_, 380 new OmahaRequestAction(omaha_request_params_,
352 error_event_.release(), // Pass ownership. 381 error_event_.release(), // Pass ownership.
353 new LibcurlHttpFetcher)); 382 new LibcurlHttpFetcher));
354 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); 383 actions_.push_back(shared_ptr<AbstractAction>(error_event_action));
355 processor_.EnqueueAction(error_event_action.get()); 384 processor_.EnqueueAction(error_event_action.get());
356 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); 385 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT);
357 processor_.StartProcessing(); 386 processor_.StartProcessing();
358 return true; 387 return true;
359 } 388 }
360 389
361 } // namespace chromeos_update_engine 390 } // 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