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