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 17 matching lines...) Expand all Loading... |
28 #include "update_engine/set_bootable_flag_action.h" | 28 #include "update_engine/set_bootable_flag_action.h" |
29 | 29 |
30 using base::TimeDelta; | 30 using base::TimeDelta; |
31 using base::TimeTicks; | 31 using base::TimeTicks; |
32 using std::tr1::shared_ptr; | 32 using std::tr1::shared_ptr; |
33 using std::string; | 33 using std::string; |
34 using std::vector; | 34 using std::vector; |
35 | 35 |
36 namespace chromeos_update_engine { | 36 namespace chromeos_update_engine { |
37 | 37 |
| 38 namespace { |
| 39 |
| 40 const int kTimeoutOnce = 7 * 60; // at 7 minutes |
| 41 const int kTimeoutPeriodic = 45 * 60; // every 45 minutes |
| 42 const int kTimeoutFuzz = 10 * 60; // +/- 5 minutes |
| 43 |
| 44 gboolean CheckForUpdatePeriodically(void* arg) { |
| 45 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); |
| 46 update_attempter->Update("", ""); |
| 47 update_attempter->SchedulePeriodicUpdateCheck(kTimeoutPeriodic); |
| 48 return FALSE; // Don't run again. |
| 49 } |
| 50 |
| 51 } // namespace {} |
| 52 |
38 const char* kUpdateCompletedMarker = "/tmp/update_engine_autoupdate_completed"; | 53 const char* kUpdateCompletedMarker = "/tmp/update_engine_autoupdate_completed"; |
39 | 54 |
40 const char* UpdateStatusToString(UpdateStatus status) { | 55 const char* UpdateStatusToString(UpdateStatus status) { |
41 switch (status) { | 56 switch (status) { |
42 case UPDATE_STATUS_IDLE: | 57 case UPDATE_STATUS_IDLE: |
43 return "UPDATE_STATUS_IDLE"; | 58 return "UPDATE_STATUS_IDLE"; |
44 case UPDATE_STATUS_CHECKING_FOR_UPDATE: | 59 case UPDATE_STATUS_CHECKING_FOR_UPDATE: |
45 return "UPDATE_STATUS_CHECKING_FOR_UPDATE"; | 60 return "UPDATE_STATUS_CHECKING_FOR_UPDATE"; |
46 case UPDATE_STATUS_UPDATE_AVAILABLE: | 61 case UPDATE_STATUS_UPDATE_AVAILABLE: |
47 return "UPDATE_STATUS_UPDATE_AVAILABLE"; | 62 return "UPDATE_STATUS_UPDATE_AVAILABLE"; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 omaha_request_params_, | 419 omaha_request_params_, |
405 error_event_.release(), // Pass ownership. | 420 error_event_.release(), // Pass ownership. |
406 new LibcurlHttpFetcher)); | 421 new LibcurlHttpFetcher)); |
407 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); | 422 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); |
408 processor_.EnqueueAction(error_event_action.get()); | 423 processor_.EnqueueAction(error_event_action.get()); |
409 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); | 424 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); |
410 processor_.StartProcessing(); | 425 processor_.StartProcessing(); |
411 return true; | 426 return true; |
412 } | 427 } |
413 | 428 |
| 429 void UpdateAttempter::InitiatePeriodicUpdateChecks() { |
| 430 if (!utils::IsOfficialBuild()) { |
| 431 LOG(WARNING) << "Non-official build: periodic update checks disabled."; |
| 432 return; |
| 433 } |
| 434 if (utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice()))) { |
| 435 LOG(WARNING) << "Removable device boot: periodic update checks disabled."; |
| 436 return; |
| 437 } |
| 438 // Kick off periodic update checks. The first check is scheduled |
| 439 // |kTimeoutOnce| seconds from now. Subsequent checks are scheduled |
| 440 // at |kTimeoutPeriodic|-second intervals. |
| 441 SchedulePeriodicUpdateCheck(kTimeoutOnce); |
| 442 } |
| 443 |
| 444 void UpdateAttempter::SchedulePeriodicUpdateCheck(int seconds) { |
| 445 seconds = utils::FuzzInt(seconds, kTimeoutFuzz); |
| 446 g_timeout_add_seconds(seconds, CheckForUpdatePeriodically, this); |
| 447 LOG(INFO) << "Next update check in " << seconds << " seconds."; |
| 448 } |
| 449 |
414 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { | 450 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { |
415 if (priority_ == priority) { | 451 if (priority_ == priority) { |
416 return; | 452 return; |
417 } | 453 } |
418 if (utils::SetProcessPriority(priority)) { | 454 if (utils::SetProcessPriority(priority)) { |
419 priority_ = priority; | 455 priority_ = priority; |
420 LOG(INFO) << "Process priority = " << priority_; | 456 LOG(INFO) << "Process priority = " << priority_; |
421 } | 457 } |
422 } | 458 } |
423 | 459 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 SetPriority(utils::kProcessPriorityNormal); | 491 SetPriority(utils::kProcessPriorityNormal); |
456 return true; | 492 return true; |
457 } | 493 } |
458 // Set the priority to high and let GLib destroy the timeout source. | 494 // Set the priority to high and let GLib destroy the timeout source. |
459 SetPriority(utils::kProcessPriorityHigh); | 495 SetPriority(utils::kProcessPriorityHigh); |
460 manage_priority_source_ = NULL; | 496 manage_priority_source_ = NULL; |
461 return false; | 497 return false; |
462 } | 498 } |
463 | 499 |
464 } // namespace chromeos_update_engine | 500 } // namespace chromeos_update_engine |
OLD | NEW |