Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |
| 7 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 8 | #include <time.h> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 9 | #include <tr1/memory> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | #include <glib.h> |
| 13 | #include "update_engine/action_processor.h" |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 14 | #include "update_engine/download_action.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 15 | #include "update_engine/omaha_response_handler_action.h" |
| 16 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 17 | struct UpdateEngineService; |
| 18 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 19 | namespace chromeos_update_engine { |
| 20 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 21 | enum UpdateStatus { |
| 22 | UPDATE_STATUS_IDLE = 0, |
| 23 | UPDATE_STATUS_CHECKING_FOR_UPDATE, |
| 24 | UPDATE_STATUS_UPDATE_AVAILABLE, |
| 25 | UPDATE_STATUS_DOWNLOADING, |
| 26 | UPDATE_STATUS_VERIFYING, |
| 27 | UPDATE_STATUS_FINALIZING, |
| 28 | UPDATE_STATUS_UPDATED_NEED_REBOOT |
| 29 | }; |
| 30 | |
| 31 | const char* UpdateStatusToString(UpdateStatus status); |
| 32 | |
| 33 | class UpdateAttempter : public ActionProcessorDelegate, |
| 34 | public DownloadActionDelegate { |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 35 | public: |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 36 | UpdateAttempter() : full_update_(false), |
| 37 | dbus_service_(NULL), |
| 38 | status_(UPDATE_STATUS_IDLE), |
| 39 | download_progress_(0.0), |
| 40 | last_checked_time_(0), |
| 41 | new_version_("0.0.0.0"), |
| 42 | new_size_(0) { |
| 43 | last_notify_time_.tv_sec = 0; |
| 44 | last_notify_time_.tv_nsec = 0; |
| 45 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 46 | void Update(bool force_full_update); |
| 47 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 48 | // ActionProcessorDelegate methods: |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 49 | void ProcessingDone(const ActionProcessor* processor, bool success); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 50 | void ProcessingStopped(const ActionProcessor* processor); |
| 51 | void ActionCompleted(ActionProcessor* processor, |
| 52 | AbstractAction* action, |
| 53 | bool success); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 54 | |
| 55 | // Stop updating. An attempt will be made to record status to the disk |
| 56 | // so that updates can be resumed later. |
| 57 | void Terminate(); |
| 58 | |
| 59 | // Try to resume from a previously Terminate()d update. |
| 60 | void ResumeUpdating(); |
| 61 | |
| 62 | // Returns the current status in the out params. Returns true on success. |
| 63 | bool GetStatus(int64_t* last_checked_time, |
| 64 | double* progress, |
| 65 | std::string* current_operation, |
| 66 | std::string* new_version, |
| 67 | int64_t* new_size); |
| 68 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 69 | void set_dbus_service(struct UpdateEngineService* dbus_service) { |
| 70 | dbus_service_ = dbus_service; |
| 71 | } |
| 72 | |
| 73 | void CheckForUpdate(); |
| 74 | |
| 75 | // DownloadActionDelegate method |
| 76 | void BytesReceived(uint64_t bytes_received, uint64_t total); |
| 77 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 78 | private: |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 79 | // Sets the status to the given status and notifies a status update |
| 80 | // over dbus. |
| 81 | void SetStatusAndNotify(UpdateStatus status); |
| 82 | |
| 83 | struct timespec last_notify_time_; |
| 84 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 85 | bool full_update_; |
| 86 | std::vector<std::tr1::shared_ptr<AbstractAction> > actions_; |
| 87 | ActionProcessor processor_; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 88 | |
| 89 | // If non-null, this UpdateAttempter will send status updates over this |
| 90 | // dbus service. |
| 91 | UpdateEngineService* dbus_service_; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 92 | |
| 93 | // pointer to the OmahaResponseHandlerAction in the actions_ vector; |
| 94 | std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 95 | |
| 96 | // For status: |
| 97 | UpdateStatus status_; |
| 98 | double download_progress_; |
| 99 | int64_t last_checked_time_; |
| 100 | std::string new_version_; |
| 101 | int64_t new_size_; |
| 102 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); |
| 104 | }; |
| 105 | |
| 106 | } // namespace chromeos_update_engine |
| 107 | |
| 108 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |