Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: update_attempter.h

Issue 3215006: AU: Implement exponential back off for 500 and 503 HTTP response codes. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: elaborate on the CHECK Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « omaha_request_action.h ('k') | update_attempter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
10 #include <tr1/memory> 10 #include <tr1/memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include <glib.h> 14 #include <glib.h>
15 15
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "update_engine/action_processor.h" 17 #include "update_engine/action_processor.h"
18 #include "update_engine/download_action.h" 18 #include "update_engine/download_action.h"
19 #include "update_engine/omaha_request_params.h" 19 #include "update_engine/omaha_request_params.h"
20 #include "update_engine/omaha_response_handler_action.h" 20 #include "update_engine/omaha_response_handler_action.h"
21 21
22 class MetricsLibraryInterface; 22 class MetricsLibraryInterface;
23 struct UpdateEngineService; 23 struct UpdateEngineService;
24 24
25 namespace chromeos_update_engine { 25 namespace chromeos_update_engine {
26 26
27 namespace utils { 27 class UpdateCheckScheduler;
28 enum ProcessPriority;
29 };
30 28
31 extern const char* kUpdateCompletedMarker; 29 extern const char* kUpdateCompletedMarker;
32 30
33 enum UpdateStatus { 31 enum UpdateStatus {
34 UPDATE_STATUS_IDLE = 0, 32 UPDATE_STATUS_IDLE = 0,
35 UPDATE_STATUS_CHECKING_FOR_UPDATE, 33 UPDATE_STATUS_CHECKING_FOR_UPDATE,
36 UPDATE_STATUS_UPDATE_AVAILABLE, 34 UPDATE_STATUS_UPDATE_AVAILABLE,
37 UPDATE_STATUS_DOWNLOADING, 35 UPDATE_STATUS_DOWNLOADING,
38 UPDATE_STATUS_VERIFYING, 36 UPDATE_STATUS_VERIFYING,
39 UPDATE_STATUS_FINALIZING, 37 UPDATE_STATUS_FINALIZING,
40 UPDATE_STATUS_UPDATED_NEED_REBOOT, 38 UPDATE_STATUS_UPDATED_NEED_REBOOT,
41 UPDATE_STATUS_REPORTING_ERROR_EVENT, 39 UPDATE_STATUS_REPORTING_ERROR_EVENT,
42 }; 40 };
43 41
44 const char* UpdateStatusToString(UpdateStatus status); 42 const char* UpdateStatusToString(UpdateStatus status);
45 43
46 class UpdateAttempter : public ActionProcessorDelegate, 44 class UpdateAttempter : public ActionProcessorDelegate,
47 public DownloadActionDelegate { 45 public DownloadActionDelegate {
48 public: 46 public:
49 UpdateAttempter(PrefsInterface* prefs, MetricsLibraryInterface* metrics_lib); 47 UpdateAttempter(PrefsInterface* prefs, MetricsLibraryInterface* metrics_lib);
50 ~UpdateAttempter(); 48 virtual ~UpdateAttempter();
51 49
52 // Checks for update and, if a newer version is available, attempts 50 // Checks for update and, if a newer version is available, attempts
53 // to update the system. Non-empty |in_app_version| or 51 // to update the system. Non-empty |in_app_version| or
54 // |in_update_url| prevents automatic detection of the parameter. 52 // |in_update_url| prevents automatic detection of the parameter.
55 void Update(const std::string& app_version, const std::string& omaha_url); 53 virtual void Update(const std::string& app_version,
54 const std::string& omaha_url);
56 55
57 // ActionProcessorDelegate methods: 56 // ActionProcessorDelegate methods:
58 void ProcessingDone(const ActionProcessor* processor, ActionExitCode code); 57 void ProcessingDone(const ActionProcessor* processor, ActionExitCode code);
59 void ProcessingStopped(const ActionProcessor* processor); 58 void ProcessingStopped(const ActionProcessor* processor);
60 void ActionCompleted(ActionProcessor* processor, 59 void ActionCompleted(ActionProcessor* processor,
61 AbstractAction* action, 60 AbstractAction* action,
62 ActionExitCode code); 61 ActionExitCode code);
63 62
64 // Stop updating. An attempt will be made to record status to the disk 63 // Stop updating. An attempt will be made to record status to the disk
65 // so that updates can be resumed later. 64 // so that updates can be resumed later.
66 void Terminate(); 65 void Terminate();
67 66
68 // Try to resume from a previously Terminate()d update. 67 // Try to resume from a previously Terminate()d update.
69 void ResumeUpdating(); 68 void ResumeUpdating();
70 69
71 // Returns the current status in the out params. Returns true on success. 70 // Returns the current status in the out params. Returns true on success.
72 bool GetStatus(int64_t* last_checked_time, 71 bool GetStatus(int64_t* last_checked_time,
73 double* progress, 72 double* progress,
74 std::string* current_operation, 73 std::string* current_operation,
75 std::string* new_version, 74 std::string* new_version,
76 int64_t* new_size); 75 int64_t* new_size);
77 76
77 UpdateStatus status() const { return status_; }
78
79 int http_response_code() const { return http_response_code_; }
80 void set_http_response_code(int code) { http_response_code_ = code; }
81
78 void set_dbus_service(struct UpdateEngineService* dbus_service) { 82 void set_dbus_service(struct UpdateEngineService* dbus_service) {
79 dbus_service_ = dbus_service; 83 dbus_service_ = dbus_service;
80 } 84 }
81 85
86 UpdateCheckScheduler* update_check_scheduler() const {
87 return update_check_scheduler_;
88 }
89 void set_update_check_scheduler(UpdateCheckScheduler* scheduler) {
90 update_check_scheduler_ = scheduler;
91 }
92
82 // This is the D-Bus service entry point for going through an 93 // This is the D-Bus service entry point for going through an
83 // update. If the current status is idle invokes Update. 94 // update. If the current status is idle invokes Update.
84 void CheckForUpdate(const std::string& app_version, 95 void CheckForUpdate(const std::string& app_version,
85 const std::string& omaha_url); 96 const std::string& omaha_url);
86 97
87 // Initiates a reboot if the current state is 98 // Initiates a reboot if the current state is
88 // UPDATED_NEED_REBOOT. Returns true on sucess, false otherwise. 99 // UPDATED_NEED_REBOOT. Returns true on sucess, false otherwise.
89 bool RebootIfNeeded(); 100 bool RebootIfNeeded();
90 101
91 // Kicks off the periodic update checks, if necessary.
92 void InitiatePeriodicUpdateChecks();
93
94 // Schedules the next periodic update check |seconds| from now. Note
95 // that the actual timeout will be fuzzed.
96 void SchedulePeriodicUpdateCheck(int seconds);
97
98 // DownloadActionDelegate methods 102 // DownloadActionDelegate methods
99 void SetDownloadStatus(bool active); 103 void SetDownloadStatus(bool active);
100 void BytesReceived(uint64_t bytes_received, uint64_t total); 104 void BytesReceived(uint64_t bytes_received, uint64_t total);
101 105
102 private: 106 private:
103 // Sets the status to the given status and notifies a status update 107 // Sets the status to the given status and notifies a status update
104 // over dbus. 108 // over dbus.
105 void SetStatusAndNotify(UpdateStatus status); 109 void SetStatusAndNotify(UpdateStatus status);
106 110
107 // Creates an error event object in |error_event_| to be included in 111 // Creates an error event object in |error_event_| to be included in
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 152
149 // pointer to the OmahaResponseHandlerAction in the actions_ vector; 153 // pointer to the OmahaResponseHandlerAction in the actions_ vector;
150 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_; 154 std::tr1::shared_ptr<OmahaResponseHandlerAction> response_handler_action_;
151 155
152 // Pointer to the preferences store interface. 156 // Pointer to the preferences store interface.
153 PrefsInterface* prefs_; 157 PrefsInterface* prefs_;
154 158
155 // Pointer to the UMA metrics collection library. 159 // Pointer to the UMA metrics collection library.
156 MetricsLibraryInterface* metrics_lib_; 160 MetricsLibraryInterface* metrics_lib_;
157 161
162 // The current UpdateCheckScheduler to notify of state transitions.
163 UpdateCheckScheduler* update_check_scheduler_;
164
158 // Pending error event, if any. 165 // Pending error event, if any.
159 scoped_ptr<OmahaEvent> error_event_; 166 scoped_ptr<OmahaEvent> error_event_;
160 167
168 int http_response_code_;
169
161 // Current process priority. 170 // Current process priority.
162 utils::ProcessPriority priority_; 171 utils::ProcessPriority priority_;
163 172
164 // The process priority management timeout source. 173 // The process priority management timeout source.
165 GSource* manage_priority_source_; 174 GSource* manage_priority_source_;
166 175
167 // Set to true if an update download is active (and BytesReceived 176 // Set to true if an update download is active (and BytesReceived
168 // will be called), set to false otherwise. 177 // will be called), set to false otherwise.
169 bool download_active_; 178 bool download_active_;
170 179
171 // For status: 180 // For status:
172 UpdateStatus status_; 181 UpdateStatus status_;
173 double download_progress_; 182 double download_progress_;
174 int64_t last_checked_time_; 183 int64_t last_checked_time_;
175 std::string new_version_; 184 std::string new_version_;
176 int64_t new_size_; 185 int64_t new_size_;
177 186
178 // Device paramaters common to all Omaha requests. 187 // Device paramaters common to all Omaha requests.
179 OmahaRequestDeviceParams omaha_request_params_; 188 OmahaRequestDeviceParams omaha_request_params_;
180 189
181 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter); 190 DISALLOW_COPY_AND_ASSIGN(UpdateAttempter);
182 }; 191 };
183 192
184 } // namespace chromeos_update_engine 193 } // namespace chromeos_update_engine
185 194
186 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__ 195 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_ATTEMPTER_H__
OLDNEW
« no previous file with comments | « omaha_request_action.h ('k') | update_attempter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698