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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |
7 | 7 |
| 8 #include <time.h> |
8 #include <tr1/memory> | 9 #include <tr1/memory> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 #include <glib.h> | 12 #include <glib.h> |
12 #include "update_engine/action_processor.h" | 13 #include "update_engine/action_processor.h" |
| 14 #include "update_engine/download_action.h" |
13 #include "update_engine/omaha_response_handler_action.h" | 15 #include "update_engine/omaha_response_handler_action.h" |
14 | 16 |
| 17 struct UpdateEngineService; |
| 18 |
15 namespace chromeos_update_engine { | 19 namespace chromeos_update_engine { |
16 | 20 |
17 class UpdateAttempter : public ActionProcessorDelegate { | 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 { |
18 public: | 35 public: |
19 explicit UpdateAttempter(GMainLoop *loop) | 36 UpdateAttempter() : full_update_(false), |
20 : full_update_(false), | 37 dbus_service_(NULL), |
21 loop_(loop) {} | 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 } |
22 void Update(bool force_full_update); | 46 void Update(bool force_full_update); |
23 | 47 |
24 // Delegate method: | 48 // ActionProcessorDelegate methods: |
25 void ProcessingDone(const ActionProcessor* processor, bool success); | 49 void ProcessingDone(const ActionProcessor* processor, bool success); |
| 50 void ProcessingStopped(const ActionProcessor* processor); |
| 51 void ActionCompleted(ActionProcessor* processor, |
| 52 AbstractAction* action, |
| 53 bool success); |
26 | 54 |
27 // Stop updating. An attempt will be made to record status to the disk | 55 // Stop updating. An attempt will be made to record status to the disk |
28 // so that updates can be resumed later. | 56 // so that updates can be resumed later. |
29 void Terminate(); | 57 void Terminate(); |
30 | 58 |
31 // Try to resume from a previously Terminate()d update. | 59 // Try to resume from a previously Terminate()d update. |
32 void ResumeUpdating(); | 60 void ResumeUpdating(); |
33 | 61 |
34 // Returns the current status in the out params. Returns true on success. | 62 // Returns the current status in the out params. Returns true on success. |
35 bool GetStatus(int64_t* last_checked_time, | 63 bool GetStatus(int64_t* last_checked_time, |
36 double* progress, | 64 double* progress, |
37 std::string* current_operation, | 65 std::string* current_operation, |
38 std::string* new_version, | 66 std::string* new_version, |
39 int64_t* new_size); | 67 int64_t* new_size); |
40 | 68 |
| 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 |
41 private: | 78 private: |
| 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 |
42 bool full_update_; | 85 bool full_update_; |
43 std::vector<std::tr1::shared_ptr<AbstractAction> > actions_; | 86 std::vector<std::tr1::shared_ptr<AbstractAction> > actions_; |
44 ActionProcessor processor_; | 87 ActionProcessor processor_; |
45 GMainLoop *loop_; | 88 |
| 89 // If non-null, this UpdateAttempter will send status updates over this |
| 90 // dbus service. |
| 91 UpdateEngineService* dbus_service_; |
46 | 92 |
47 // pointer to the OmahaResponseHandlerAction in the actions_ vector; | 93 // pointer to the OmahaResponseHandlerAction in the actions_ vector; |
48 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_; | 94 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_; |
| 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 |
49 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); | 103 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); |
50 }; | 104 }; |
51 | 105 |
52 } // namespace chromeos_update_engine | 106 } // namespace chromeos_update_engine |
53 | 107 |
54 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ | 108 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |
OLD | NEW |