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_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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return code; | 114 return code; |
115 } | 115 } |
116 | 116 |
117 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, | 117 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, |
118 MetricsLibraryInterface* metrics_lib) | 118 MetricsLibraryInterface* metrics_lib) |
119 : dbus_service_(NULL), | 119 : dbus_service_(NULL), |
120 prefs_(prefs), | 120 prefs_(prefs), |
121 metrics_lib_(metrics_lib), | 121 metrics_lib_(metrics_lib), |
122 priority_(utils::kProcessPriorityNormal), | 122 priority_(utils::kProcessPriorityNormal), |
123 manage_priority_source_(NULL), | 123 manage_priority_source_(NULL), |
| 124 download_active_(false), |
124 status_(UPDATE_STATUS_IDLE), | 125 status_(UPDATE_STATUS_IDLE), |
125 download_progress_(0.0), | 126 download_progress_(0.0), |
126 last_checked_time_(0), | 127 last_checked_time_(0), |
127 new_version_("0.0.0.0"), | 128 new_version_("0.0.0.0"), |
128 new_size_(0) { | 129 new_size_(0) { |
129 last_notify_time_.tv_sec = 0; | 130 last_notify_time_.tv_sec = 0; |
130 last_notify_time_.tv_nsec = 0; | 131 last_notify_time_.tv_nsec = 0; |
131 if (utils::FileExists(kUpdateCompletedMarker)) | 132 if (utils::FileExists(kUpdateCompletedMarker)) |
132 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; | 133 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; |
133 } | 134 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 const string type = action->Type(); | 313 const string type = action->Type(); |
313 if (type == DownloadAction::StaticType()) | 314 if (type == DownloadAction::StaticType()) |
314 download_progress_ = 0.0; | 315 download_progress_ = 0.0; |
315 if (code != kActionCodeSuccess) { | 316 if (code != kActionCodeSuccess) { |
316 // On failure, schedule an error event to be sent to Omaha. | 317 // On failure, schedule an error event to be sent to Omaha. |
317 CreatePendingErrorEvent(action, code); | 318 CreatePendingErrorEvent(action, code); |
318 return; | 319 return; |
319 } | 320 } |
320 // Find out which action completed. | 321 // Find out which action completed. |
321 if (type == OmahaResponseHandlerAction::StaticType()) { | 322 if (type == OmahaResponseHandlerAction::StaticType()) { |
322 SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING); | 323 // Note that the status will be updated to DOWNLOADING when some |
| 324 // bytes get actually downloaded from the server and the |
| 325 // BytesReceived callback is invoked. This avoids notifying the |
| 326 // user that a download has started in cases when the server and |
| 327 // the client are unable to initiate the download. |
323 OmahaResponseHandlerAction* omaha_response_handler_action = | 328 OmahaResponseHandlerAction* omaha_response_handler_action = |
324 dynamic_cast<OmahaResponseHandlerAction*>(action); | 329 dynamic_cast<OmahaResponseHandlerAction*>(action); |
325 CHECK(omaha_response_handler_action); | 330 CHECK(omaha_response_handler_action); |
326 const InstallPlan& plan = omaha_response_handler_action->install_plan(); | 331 const InstallPlan& plan = omaha_response_handler_action->install_plan(); |
327 last_checked_time_ = time(NULL); | 332 last_checked_time_ = time(NULL); |
328 // TODO(adlr): put version in InstallPlan | 333 // TODO(adlr): put version in InstallPlan |
329 new_version_ = "0.0.0.0"; | 334 new_version_ = "0.0.0.0"; |
330 new_size_ = plan.size; | 335 new_size_ = plan.size; |
331 SetupPriorityManagement(); | 336 SetupPriorityManagement(); |
332 } else if (type == DownloadAction::StaticType()) { | 337 } else if (type == DownloadAction::StaticType()) { |
333 SetStatusAndNotify(UPDATE_STATUS_FINALIZING); | 338 SetStatusAndNotify(UPDATE_STATUS_FINALIZING); |
334 } | 339 } |
335 } | 340 } |
336 | 341 |
337 // Stop updating. An attempt will be made to record status to the disk | 342 // Stop updating. An attempt will be made to record status to the disk |
338 // so that updates can be resumed later. | 343 // so that updates can be resumed later. |
339 void UpdateAttempter::Terminate() { | 344 void UpdateAttempter::Terminate() { |
340 // TODO(adlr): implement this method. | 345 // TODO(adlr): implement this method. |
341 NOTIMPLEMENTED(); | 346 NOTIMPLEMENTED(); |
342 } | 347 } |
343 | 348 |
344 // Try to resume from a previously Terminate()d update. | 349 // Try to resume from a previously Terminate()d update. |
345 void UpdateAttempter::ResumeUpdating() { | 350 void UpdateAttempter::ResumeUpdating() { |
346 // TODO(adlr): implement this method. | 351 // TODO(adlr): implement this method. |
347 NOTIMPLEMENTED(); | 352 NOTIMPLEMENTED(); |
348 } | 353 } |
349 | 354 |
| 355 void UpdateAttempter::SetDownloadStatus(bool active) { |
| 356 download_active_ = active; |
| 357 LOG(INFO) << "Download status: " << (active ? "active" : "inactive"); |
| 358 } |
| 359 |
350 void UpdateAttempter::BytesReceived(uint64_t bytes_received, uint64_t total) { | 360 void UpdateAttempter::BytesReceived(uint64_t bytes_received, uint64_t total) { |
351 if (status_ != UPDATE_STATUS_DOWNLOADING) { | 361 if (!download_active_) { |
352 LOG(ERROR) << "BytesReceived called while not downloading."; | 362 LOG(ERROR) << "BytesReceived called while not downloading."; |
353 return; | 363 return; |
354 } | 364 } |
355 download_progress_ = static_cast<double>(bytes_received) / | 365 download_progress_ = static_cast<double>(bytes_received) / |
356 static_cast<double>(total); | 366 static_cast<double>(total); |
357 // We self throttle here | 367 // We self throttle here |
358 timespec now; | 368 timespec now; |
359 now.tv_sec = 0; | 369 now.tv_sec = 0; |
360 now.tv_nsec = 0; | 370 now.tv_nsec = 0; |
361 if (GetCPUClockTime(&now) && | 371 if (GetCPUClockTime(&now) && |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 SetPriority(utils::kProcessPriorityNormal); | 486 SetPriority(utils::kProcessPriorityNormal); |
477 return true; | 487 return true; |
478 } | 488 } |
479 // Set the priority to high and let GLib destroy the timeout source. | 489 // Set the priority to high and let GLib destroy the timeout source. |
480 SetPriority(utils::kProcessPriorityHigh); | 490 SetPriority(utils::kProcessPriorityHigh); |
481 manage_priority_source_ = NULL; | 491 manage_priority_source_ = NULL; |
482 return false; | 492 return false; |
483 } | 493 } |
484 | 494 |
485 } // namespace chromeos_update_engine | 495 } // namespace chromeos_update_engine |
OLD | NEW |