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 #include "update_engine/update_attempter.h" | 5 #include "update_engine/update_attempter.h" |
6 | 6 |
7 // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L | 7 // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L |
8 #ifndef _POSIX_C_SOURCE | 8 #ifndef _POSIX_C_SOURCE |
9 #define _POSIX_C_SOURCE 199309L | 9 #define _POSIX_C_SOURCE 199309L |
10 #endif // _POSIX_C_SOURCE | 10 #endif // _POSIX_C_SOURCE |
11 #include <time.h> | 11 #include <time.h> |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <tr1/memory> | 14 #include <tr1/memory> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include <base/rand_util.h> | |
17 #include <glib.h> | 18 #include <glib.h> |
18 #include <metrics/metrics_library.h> | 19 #include <metrics/metrics_library.h> |
19 | 20 |
20 #include "update_engine/dbus_service.h" | 21 #include "update_engine/dbus_service.h" |
21 #include "update_engine/download_action.h" | 22 #include "update_engine/download_action.h" |
22 #include "update_engine/filesystem_copier_action.h" | 23 #include "update_engine/filesystem_copier_action.h" |
23 #include "update_engine/libcurl_http_fetcher.h" | 24 #include "update_engine/libcurl_http_fetcher.h" |
24 #include "update_engine/multi_http_fetcher.h" | 25 #include "update_engine/multi_http_fetcher.h" |
25 #include "update_engine/omaha_request_action.h" | 26 #include "update_engine/omaha_request_action.h" |
26 #include "update_engine/omaha_request_params.h" | 27 #include "update_engine/omaha_request_params.h" |
27 #include "update_engine/omaha_response_handler_action.h" | 28 #include "update_engine/omaha_response_handler_action.h" |
28 #include "update_engine/postinstall_runner_action.h" | 29 #include "update_engine/postinstall_runner_action.h" |
29 #include "update_engine/prefs_interface.h" | 30 #include "update_engine/prefs_interface.h" |
30 #include "update_engine/update_check_scheduler.h" | 31 #include "update_engine/update_check_scheduler.h" |
31 | 32 |
32 using base::TimeDelta; | 33 using base::TimeDelta; |
33 using base::TimeTicks; | 34 using base::TimeTicks; |
34 using std::make_pair; | 35 using std::make_pair; |
35 using std::tr1::shared_ptr; | 36 using std::tr1::shared_ptr; |
36 using std::string; | 37 using std::string; |
37 using std::vector; | 38 using std::vector; |
38 | 39 |
39 namespace chromeos_update_engine { | 40 namespace chromeos_update_engine { |
40 | 41 |
41 const int UpdateAttempter::kMaxDeltaUpdateFailures = 3; | 42 const int UpdateAttempter::kMaxDeltaUpdateFailures = 3; |
42 | 43 |
43 const char* kUpdateCompletedMarker = | 44 const char* kUpdateCompletedMarker = |
44 "/var/run/update_engine_autoupdate_completed"; | 45 "/var/run/update_engine_autoupdate_completed"; |
45 | 46 |
47 namespace { | |
48 const int kMaxConsecutiveObeyProxyRequests = 20; | |
49 } // namespace {} | |
50 | |
46 const char* UpdateStatusToString(UpdateStatus status) { | 51 const char* UpdateStatusToString(UpdateStatus status) { |
47 switch (status) { | 52 switch (status) { |
48 case UPDATE_STATUS_IDLE: | 53 case UPDATE_STATUS_IDLE: |
49 return "UPDATE_STATUS_IDLE"; | 54 return "UPDATE_STATUS_IDLE"; |
50 case UPDATE_STATUS_CHECKING_FOR_UPDATE: | 55 case UPDATE_STATUS_CHECKING_FOR_UPDATE: |
51 return "UPDATE_STATUS_CHECKING_FOR_UPDATE"; | 56 return "UPDATE_STATUS_CHECKING_FOR_UPDATE"; |
52 case UPDATE_STATUS_UPDATE_AVAILABLE: | 57 case UPDATE_STATUS_UPDATE_AVAILABLE: |
53 return "UPDATE_STATUS_UPDATE_AVAILABLE"; | 58 return "UPDATE_STATUS_UPDATE_AVAILABLE"; |
54 case UPDATE_STATUS_DOWNLOADING: | 59 case UPDATE_STATUS_DOWNLOADING: |
55 return "UPDATE_STATUS_DOWNLOADING"; | 60 return "UPDATE_STATUS_DOWNLOADING"; |
(...skipping 26 matching lines...) Expand all Loading... | |
82 return kActionCodeOmahaResponseHandlerError; | 87 return kActionCodeOmahaResponseHandlerError; |
83 if (type == FilesystemCopierAction::StaticType()) | 88 if (type == FilesystemCopierAction::StaticType()) |
84 return kActionCodeFilesystemCopierError; | 89 return kActionCodeFilesystemCopierError; |
85 if (type == PostinstallRunnerAction::StaticType()) | 90 if (type == PostinstallRunnerAction::StaticType()) |
86 return kActionCodePostinstallRunnerError; | 91 return kActionCodePostinstallRunnerError; |
87 | 92 |
88 return code; | 93 return code; |
89 } | 94 } |
90 | 95 |
91 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, | 96 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, |
92 MetricsLibraryInterface* metrics_lib) | 97 MetricsLibraryInterface* metrics_lib, |
98 DbusGlibInterface* dbus_iface) | |
93 : processor_(new ActionProcessor()), | 99 : processor_(new ActionProcessor()), |
94 dbus_service_(NULL), | 100 dbus_service_(NULL), |
95 prefs_(prefs), | 101 prefs_(prefs), |
96 metrics_lib_(metrics_lib), | 102 metrics_lib_(metrics_lib), |
97 update_check_scheduler_(NULL), | 103 update_check_scheduler_(NULL), |
98 http_response_code_(0), | 104 http_response_code_(0), |
99 priority_(utils::kProcessPriorityNormal), | 105 priority_(utils::kProcessPriorityNormal), |
100 manage_priority_source_(NULL), | 106 manage_priority_source_(NULL), |
101 download_active_(false), | 107 download_active_(false), |
102 status_(UPDATE_STATUS_IDLE), | 108 status_(UPDATE_STATUS_IDLE), |
103 download_progress_(0.0), | 109 download_progress_(0.0), |
104 last_checked_time_(0), | 110 last_checked_time_(0), |
105 new_version_("0.0.0.0"), | 111 new_version_("0.0.0.0"), |
106 new_size_(0), | 112 new_size_(0), |
107 is_full_update_(false) { | 113 is_full_update_(false), |
114 proxy_manual_checks_(0), | |
115 obeying_proxies_(true), | |
116 chrome_proxy_resolver_(dbus_iface) { | |
108 if (utils::FileExists(kUpdateCompletedMarker)) | 117 if (utils::FileExists(kUpdateCompletedMarker)) |
109 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; | 118 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; |
110 } | 119 } |
111 | 120 |
112 UpdateAttempter::~UpdateAttempter() { | 121 UpdateAttempter::~UpdateAttempter() { |
113 CleanupPriorityManagement(); | 122 CleanupPriorityManagement(); |
114 } | 123 } |
115 | 124 |
116 void UpdateAttempter::Update(const std::string& app_version, | 125 void UpdateAttempter::Update(const std::string& app_version, |
117 const std::string& omaha_url) { | 126 const std::string& omaha_url, |
127 bool force_obey_proxies) { | |
118 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 128 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
119 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " | 129 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " |
120 << "reboot"; | 130 << "reboot"; |
121 return; | 131 return; |
122 } | 132 } |
123 if (status_ != UPDATE_STATUS_IDLE) { | 133 if (status_ != UPDATE_STATUS_IDLE) { |
124 // Update in progress. Do nothing | 134 // Update in progress. Do nothing |
125 return; | 135 return; |
126 } | 136 } |
127 http_response_code_ = 0; | 137 http_response_code_ = 0; |
128 if (!omaha_request_params_.Init(app_version, omaha_url)) { | 138 if (!omaha_request_params_.Init(app_version, omaha_url)) { |
129 LOG(ERROR) << "Unable to initialize Omaha request device params."; | 139 LOG(ERROR) << "Unable to initialize Omaha request device params."; |
130 return; | 140 return; |
131 } | 141 } |
142 | |
143 obeying_proxies_ = true; | |
144 static const char message[] = "To help ensure updates work, this update " | |
petkov
2010/11/19 05:37:15
Can you do one LOG_IF(INFO, obeying_proxies_) afte
adlr
2010/11/20 02:52:29
Done.
| |
145 "check we are ignoring the proxy settings and using " | |
146 "direct connections."; | |
147 if (force_obey_proxies) { | |
petkov
2010/11/19 05:37:15
does it make sense to always obey proxies on the f
adlr
2010/11/20 02:52:29
seems fine. added
| |
148 LOG(INFO) << "forced to obey proxies"; | |
149 // If forced to obey proxies, every 20th request will not use proxies | |
150 proxy_manual_checks_++; | |
151 LOG(INFO) << "proxy manual checks: " << proxy_manual_checks_; | |
152 if (proxy_manual_checks_ >= kMaxConsecutiveObeyProxyRequests) { | |
153 proxy_manual_checks_ = 0; | |
154 force_obey_proxies = false; | |
petkov
2010/11/19 05:37:15
no need?
adlr
2010/11/20 02:52:29
good call. removed
| |
155 obeying_proxies_ = true; | |
petkov
2010/11/19 05:37:15
do you mean obeying_proxies_ = false?
adlr
2010/11/20 02:52:29
Done.
| |
156 LOG(INFO) << message; | |
157 } | |
158 } else { | |
159 if (base::RandInt(0, 4) == 0) { | |
160 LOG(INFO) << message; | |
161 obeying_proxies_ = false; | |
162 } else { | |
163 LOG(INFO) << "using proxies"; | |
164 } | |
165 } | |
166 | |
132 DisableDeltaUpdateIfNeeded(); | 167 DisableDeltaUpdateIfNeeded(); |
133 CHECK(!processor_->IsRunning()); | 168 CHECK(!processor_->IsRunning()); |
134 processor_->set_delegate(this); | 169 processor_->set_delegate(this); |
135 | 170 |
136 // Actions: | 171 // Actions: |
137 shared_ptr<OmahaRequestAction> update_check_action( | 172 shared_ptr<OmahaRequestAction> update_check_action( |
138 new OmahaRequestAction(prefs_, | 173 new OmahaRequestAction(prefs_, |
139 omaha_request_params_, | 174 omaha_request_params_, |
140 NULL, | 175 NULL, |
141 new LibcurlHttpFetcher)); | 176 new LibcurlHttpFetcher(GetProxyResolver()))); |
142 shared_ptr<OmahaResponseHandlerAction> response_handler_action( | 177 shared_ptr<OmahaResponseHandlerAction> response_handler_action( |
143 new OmahaResponseHandlerAction(prefs_)); | 178 new OmahaResponseHandlerAction(prefs_)); |
144 shared_ptr<FilesystemCopierAction> filesystem_copier_action( | 179 shared_ptr<FilesystemCopierAction> filesystem_copier_action( |
145 new FilesystemCopierAction(false)); | 180 new FilesystemCopierAction(false)); |
146 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( | 181 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( |
147 new FilesystemCopierAction(true)); | 182 new FilesystemCopierAction(true)); |
148 shared_ptr<OmahaRequestAction> download_started_action( | 183 shared_ptr<OmahaRequestAction> download_started_action( |
149 new OmahaRequestAction(prefs_, | 184 new OmahaRequestAction(prefs_, |
150 omaha_request_params_, | 185 omaha_request_params_, |
151 new OmahaEvent( | 186 new OmahaEvent( |
152 OmahaEvent::kTypeUpdateDownloadStarted), | 187 OmahaEvent::kTypeUpdateDownloadStarted), |
153 new LibcurlHttpFetcher)); | 188 new LibcurlHttpFetcher(GetProxyResolver()))); |
petkov
2010/11/19 05:37:15
You should probably always obey proxies for event
adlr
2010/11/20 02:52:29
The idea was we would be consistent for a given up
petkov
2010/11/22 17:49:00
Yes, makes sense. I missed the fact that the whole
| |
154 shared_ptr<DownloadAction> download_action( | 189 shared_ptr<DownloadAction> download_action( |
155 new DownloadAction(prefs_, new MultiHttpFetcher<LibcurlHttpFetcher>)); | 190 new DownloadAction(prefs_, new MultiHttpFetcher<LibcurlHttpFetcher>( |
191 GetProxyResolver()))); | |
156 shared_ptr<OmahaRequestAction> download_finished_action( | 192 shared_ptr<OmahaRequestAction> download_finished_action( |
157 new OmahaRequestAction(prefs_, | 193 new OmahaRequestAction(prefs_, |
158 omaha_request_params_, | 194 omaha_request_params_, |
159 new OmahaEvent( | 195 new OmahaEvent( |
160 OmahaEvent::kTypeUpdateDownloadFinished), | 196 OmahaEvent::kTypeUpdateDownloadFinished), |
161 new LibcurlHttpFetcher)); | 197 new LibcurlHttpFetcher(GetProxyResolver()))); |
162 shared_ptr<PostinstallRunnerAction> postinstall_runner_action( | 198 shared_ptr<PostinstallRunnerAction> postinstall_runner_action( |
163 new PostinstallRunnerAction); | 199 new PostinstallRunnerAction); |
164 shared_ptr<OmahaRequestAction> update_complete_action( | 200 shared_ptr<OmahaRequestAction> update_complete_action( |
165 new OmahaRequestAction(prefs_, | 201 new OmahaRequestAction(prefs_, |
166 omaha_request_params_, | 202 omaha_request_params_, |
167 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), | 203 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
168 new LibcurlHttpFetcher)); | 204 new LibcurlHttpFetcher(GetProxyResolver()))); |
169 | 205 |
170 download_action->set_delegate(this); | 206 download_action->set_delegate(this); |
171 response_handler_action_ = response_handler_action; | 207 response_handler_action_ = response_handler_action; |
172 download_action_ = download_action; | 208 download_action_ = download_action; |
173 | 209 |
174 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); | 210 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); |
175 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); | 211 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); |
176 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); | 212 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); |
177 actions_.push_back(shared_ptr<AbstractAction>( | 213 actions_.push_back(shared_ptr<AbstractAction>( |
178 kernel_filesystem_copier_action)); | 214 kernel_filesystem_copier_action)); |
(...skipping 26 matching lines...) Expand all Loading... | |
205 processor_->StartProcessing(); | 241 processor_->StartProcessing(); |
206 } | 242 } |
207 | 243 |
208 void UpdateAttempter::CheckForUpdate(const std::string& app_version, | 244 void UpdateAttempter::CheckForUpdate(const std::string& app_version, |
209 const std::string& omaha_url) { | 245 const std::string& omaha_url) { |
210 if (status_ != UPDATE_STATUS_IDLE) { | 246 if (status_ != UPDATE_STATUS_IDLE) { |
211 LOG(INFO) << "Check for update requested, but status is " | 247 LOG(INFO) << "Check for update requested, but status is " |
212 << UpdateStatusToString(status_) << ", so not checking."; | 248 << UpdateStatusToString(status_) << ", so not checking."; |
213 return; | 249 return; |
214 } | 250 } |
215 Update(app_version, omaha_url); | 251 Update(app_version, omaha_url, true); |
216 } | 252 } |
217 | 253 |
218 bool UpdateAttempter::RebootIfNeeded() { | 254 bool UpdateAttempter::RebootIfNeeded() { |
219 if (status_ != UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 255 if (status_ != UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
220 LOG(INFO) << "Reboot requested, but status is " | 256 LOG(INFO) << "Reboot requested, but status is " |
221 << UpdateStatusToString(status_) << ", so not rebooting."; | 257 << UpdateStatusToString(status_) << ", so not rebooting."; |
222 return false; | 258 return false; |
223 } | 259 } |
224 TEST_AND_RETURN_FALSE(utils::Reboot()); | 260 TEST_AND_RETURN_FALSE(utils::Reboot()); |
225 return true; | 261 return true; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 | 464 |
429 bool UpdateAttempter::ScheduleErrorEventAction() { | 465 bool UpdateAttempter::ScheduleErrorEventAction() { |
430 if (error_event_.get() == NULL) | 466 if (error_event_.get() == NULL) |
431 return false; | 467 return false; |
432 | 468 |
433 LOG(INFO) << "Update failed -- reporting the error event."; | 469 LOG(INFO) << "Update failed -- reporting the error event."; |
434 shared_ptr<OmahaRequestAction> error_event_action( | 470 shared_ptr<OmahaRequestAction> error_event_action( |
435 new OmahaRequestAction(prefs_, | 471 new OmahaRequestAction(prefs_, |
436 omaha_request_params_, | 472 omaha_request_params_, |
437 error_event_.release(), // Pass ownership. | 473 error_event_.release(), // Pass ownership. |
438 new LibcurlHttpFetcher)); | 474 new LibcurlHttpFetcher(GetProxyResolver()))); |
439 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); | 475 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); |
440 processor_->EnqueueAction(error_event_action.get()); | 476 processor_->EnqueueAction(error_event_action.get()); |
441 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); | 477 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); |
442 processor_->StartProcessing(); | 478 processor_->StartProcessing(); |
443 return true; | 479 return true; |
444 } | 480 } |
445 | 481 |
446 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { | 482 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { |
447 if (priority_ == priority) { | 483 if (priority_ == priority) { |
448 return; | 484 return; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 if (resume_offset < response_handler_action_->install_plan().size) { | 563 if (resume_offset < response_handler_action_->install_plan().size) { |
528 ranges.push_back(make_pair(resume_offset, -1)); | 564 ranges.push_back(make_pair(resume_offset, -1)); |
529 } | 565 } |
530 } else { | 566 } else { |
531 ranges.push_back(make_pair(0, -1)); | 567 ranges.push_back(make_pair(0, -1)); |
532 } | 568 } |
533 fetcher->set_ranges(ranges); | 569 fetcher->set_ranges(ranges); |
534 } | 570 } |
535 | 571 |
536 } // namespace chromeos_update_engine | 572 } // namespace chromeos_update_engine |
OLD | NEW |