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 <time.h> |
| 9 |
9 #include <tr1/memory> | 10 #include <tr1/memory> |
10 #include <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
| 13 |
12 #include <glib.h> | 14 #include <glib.h> |
| 15 |
13 #include "update_engine/action_processor.h" | 16 #include "update_engine/action_processor.h" |
14 #include "update_engine/download_action.h" | 17 #include "update_engine/download_action.h" |
15 #include "update_engine/omaha_request_params.h" | 18 #include "update_engine/omaha_request_params.h" |
16 #include "update_engine/omaha_response_handler_action.h" | 19 #include "update_engine/omaha_response_handler_action.h" |
17 | 20 |
18 class MetricsLibraryInterface; | 21 class MetricsLibraryInterface; |
19 struct UpdateEngineService; | 22 struct UpdateEngineService; |
20 | 23 |
21 namespace chromeos_update_engine { | 24 namespace chromeos_update_engine { |
22 | 25 |
| 26 namespace utils { |
| 27 enum ProcessPriority; |
| 28 }; |
| 29 |
23 extern const char* kUpdateCompletedMarker; | 30 extern const char* kUpdateCompletedMarker; |
24 | 31 |
25 enum UpdateStatus { | 32 enum UpdateStatus { |
26 UPDATE_STATUS_IDLE = 0, | 33 UPDATE_STATUS_IDLE = 0, |
27 UPDATE_STATUS_CHECKING_FOR_UPDATE, | 34 UPDATE_STATUS_CHECKING_FOR_UPDATE, |
28 UPDATE_STATUS_UPDATE_AVAILABLE, | 35 UPDATE_STATUS_UPDATE_AVAILABLE, |
29 UPDATE_STATUS_DOWNLOADING, | 36 UPDATE_STATUS_DOWNLOADING, |
30 UPDATE_STATUS_VERIFYING, | 37 UPDATE_STATUS_VERIFYING, |
31 UPDATE_STATUS_FINALIZING, | 38 UPDATE_STATUS_FINALIZING, |
32 UPDATE_STATUS_UPDATED_NEED_REBOOT, | 39 UPDATE_STATUS_UPDATED_NEED_REBOOT, |
33 UPDATE_STATUS_REPORTING_ERROR_EVENT, | 40 UPDATE_STATUS_REPORTING_ERROR_EVENT, |
34 }; | 41 }; |
35 | 42 |
36 const char* UpdateStatusToString(UpdateStatus status); | 43 const char* UpdateStatusToString(UpdateStatus status); |
37 | 44 |
38 class UpdateAttempter : public ActionProcessorDelegate, | 45 class UpdateAttempter : public ActionProcessorDelegate, |
39 public DownloadActionDelegate { | 46 public DownloadActionDelegate { |
40 public: | 47 public: |
41 UpdateAttempter(PrefsInterface* prefs, MetricsLibraryInterface* metrics_lib) | 48 UpdateAttempter(PrefsInterface* prefs, MetricsLibraryInterface* metrics_lib); |
42 : dbus_service_(NULL), | 49 ~UpdateAttempter(); |
43 prefs_(prefs), | 50 |
44 metrics_lib_(metrics_lib), | |
45 status_(UPDATE_STATUS_IDLE), | |
46 download_progress_(0.0), | |
47 last_checked_time_(0), | |
48 new_version_("0.0.0.0"), | |
49 new_size_(0) { | |
50 last_notify_time_.tv_sec = 0; | |
51 last_notify_time_.tv_nsec = 0; | |
52 if (utils::FileExists(kUpdateCompletedMarker)) | |
53 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; | |
54 } | |
55 // Checks for update and, if a newer version is available, attempts | 51 // Checks for update and, if a newer version is available, attempts |
56 // to update the system. Non-empty |in_app_version| or | 52 // to update the system. Non-empty |in_app_version| or |
57 // |in_update_url| prevents automatic detection of the parameter. | 53 // |in_update_url| prevents automatic detection of the parameter. |
58 void Update(const std::string& app_version, const std::string& omaha_url); | 54 void Update(const std::string& app_version, const std::string& omaha_url); |
59 | 55 |
60 // ActionProcessorDelegate methods: | 56 // ActionProcessorDelegate methods: |
61 void ProcessingDone(const ActionProcessor* processor, ActionExitCode code); | 57 void ProcessingDone(const ActionProcessor* processor, ActionExitCode code); |
62 void ProcessingStopped(const ActionProcessor* processor); | 58 void ProcessingStopped(const ActionProcessor* processor); |
63 void ActionCompleted(ActionProcessor* processor, | 59 void ActionCompleted(ActionProcessor* processor, |
64 AbstractAction* action, | 60 AbstractAction* action, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Creates an error event object in |error_event_| to be included in | 98 // Creates an error event object in |error_event_| to be included in |
103 // an OmahaRequestAction once the current action processor is done. | 99 // an OmahaRequestAction once the current action processor is done. |
104 void CreatePendingErrorEvent(AbstractAction* action, ActionExitCode code); | 100 void CreatePendingErrorEvent(AbstractAction* action, ActionExitCode code); |
105 | 101 |
106 // If there's a pending error event allocated in |error_event_|, | 102 // If there's a pending error event allocated in |error_event_|, |
107 // schedules an OmahaRequestAction with that event in the current | 103 // schedules an OmahaRequestAction with that event in the current |
108 // processor, clears the pending event, updates the status and | 104 // processor, clears the pending event, updates the status and |
109 // returns true. Returns false otherwise. | 105 // returns true. Returns false otherwise. |
110 bool ScheduleErrorEventAction(); | 106 bool ScheduleErrorEventAction(); |
111 | 107 |
| 108 // Sets the process priority to |priority| and updates |priority_| |
| 109 // if the new |priority| is different than the current |priority_|, |
| 110 // otherwise simply returns. |
| 111 void SetPriority(utils::ProcessPriority priority); |
| 112 |
| 113 // Set the process priority to low and sets up timeout events to |
| 114 // increase the priority gradually to high. |
| 115 void SetupPriorityManagement(); |
| 116 |
| 117 // Resets the process priority to normal and destroys any scheduled |
| 118 // timeout sources. |
| 119 void CleanupPriorityManagement(); |
| 120 |
| 121 // The process priority timeout source callback increases the |
| 122 // current priority by one step (low goes to normal, normal goes to |
| 123 // high). Returns true if the callback must be invoked again after a |
| 124 // timeout, or false if GLib can destroy this timeout source. |
| 125 static gboolean StaticManagePriorityCallback(gpointer data); |
| 126 bool ManagePriorityCallback(); |
| 127 |
112 struct timespec last_notify_time_; | 128 struct timespec last_notify_time_; |
113 | 129 |
114 std::vector<std::tr1::shared_ptr<AbstractAction> > actions_; | 130 std::vector<std::tr1::shared_ptr<AbstractAction> > actions_; |
115 ActionProcessor processor_; | 131 ActionProcessor processor_; |
116 | 132 |
117 // If non-null, this UpdateAttempter will send status updates over this | 133 // If non-null, this UpdateAttempter will send status updates over this |
118 // dbus service. | 134 // dbus service. |
119 UpdateEngineService* dbus_service_; | 135 UpdateEngineService* dbus_service_; |
120 | 136 |
121 // pointer to the OmahaResponseHandlerAction in the actions_ vector; | 137 // pointer to the OmahaResponseHandlerAction in the actions_ vector; |
122 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_; | 138 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_; |
123 | 139 |
124 // Pointer to the preferences store interface. | 140 // Pointer to the preferences store interface. |
125 PrefsInterface* prefs_; | 141 PrefsInterface* prefs_; |
126 | 142 |
127 // Pointer to the UMA metrics collection library. | 143 // Pointer to the UMA metrics collection library. |
128 MetricsLibraryInterface* metrics_lib_; | 144 MetricsLibraryInterface* metrics_lib_; |
129 | 145 |
130 // Pending error event, if any. | 146 // Pending error event, if any. |
131 scoped_ptr<OmahaEvent> error_event_; | 147 scoped_ptr<OmahaEvent> error_event_; |
132 | 148 |
| 149 // Current process priority. |
| 150 utils::ProcessPriority priority_; |
| 151 |
| 152 // The process priority management timeout source. |
| 153 GSource* manage_priority_source_; |
| 154 |
133 // For status: | 155 // For status: |
134 UpdateStatus status_; | 156 UpdateStatus status_; |
135 double download_progress_; | 157 double download_progress_; |
136 int64_t last_checked_time_; | 158 int64_t last_checked_time_; |
137 std::string new_version_; | 159 std::string new_version_; |
138 int64_t new_size_; | 160 int64_t new_size_; |
139 | 161 |
140 // Device paramaters common to all Omaha requests. | 162 // Device paramaters common to all Omaha requests. |
141 OmahaRequestDeviceParams omaha_request_params_; | 163 OmahaRequestDeviceParams omaha_request_params_; |
142 | 164 |
143 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); | 165 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); |
144 }; | 166 }; |
145 | 167 |
146 } // namespace chromeos_update_engine | 168 } // namespace chromeos_update_engine |
147 | 169 |
148 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ | 170 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ |
OLD | NEW |