Support for processing multiple URLs in update_engine.
Main changes:
1. Added a new PayloadState class which encapsulates all the persisted
state we use for multiple URLs, back-off (TBD), etc.
2. Added support for handling multiple URLs stored in the OmahaResponse in
OmahaRequestAction and OmahaResponseHandlerAction code.
3. Added support for picking the right URL in OmahaResponseHandlerAction
and putting it in the install_plan. This way, the rest of the code that
uses the install_plan is oblivious to the presence of multiple URLs :-)
4. Added support for advancing to next URL when an update fails. The full
error classification is a new work item (chromium-os:37206). Right now,
it's a basic round-robin on every error.
5. Updated the conditions for determining when hash checks are mandatory.
Previously since there was only one URL, if it was HTTPS, the checks were
waived. Now, even if there's one HTTP URL, we make hash checks mandatory
even if other HTTPS URLs are present.
6. Added new unit tests for PayloadState and the new logic added to other
places.
Noisy changes:
1. Instead of passing PrefsInterface to OmahaRequestAction and
OmahaResponseHandlerAction, we're now passing SystemState which will now
contain PrefsInterface and the newly added PayloadState object that these
actions need to do their work.
2. Renamed a bunch of setters/getters to set_x() and x() instead of SetX()
and GetX() methods - this was pending from Gilad's old CR. As I'm
adding new methods in the correct style, I went ahead and fixed it to
avoid the confusing styles.
3. Updated all existing unit tests to reflect these changes.
BUG=chromium-os:36807
TEST=All Single/Multiple URL scenarios work fine on my ZGB as expected.
TEST=Old and new unit tests run fine.
Change-Id: Id31f9ccb220471f3ec3a475f624dc03c16119144
Reviewed-on: https://gerrit.chromium.org/gerrit/39638
Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/update_attempter.cc b/update_attempter.cc
index 3e0249b..d799c33 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -107,13 +107,12 @@
return code;
}
-UpdateAttempter::UpdateAttempter(PrefsInterface* prefs,
+UpdateAttempter::UpdateAttempter(SystemState* system_state,
DbusGlibInterface* dbus_iface,
- GpioHandler* gpio_handler,
- SystemState* system_state)
+ GpioHandler* gpio_handler)
: processor_(new ActionProcessor()),
+ system_state_(system_state),
dbus_service_(NULL),
- prefs_(prefs),
update_check_scheduler_(NULL),
fake_update_success_(false),
http_response_code_(0),
@@ -135,8 +134,8 @@
is_using_test_url_(false),
is_test_mode_(false),
is_test_update_attempted_(false),
- gpio_handler_(gpio_handler),
- system_state_(system_state) {
+ gpio_handler_(gpio_handler) {
+ prefs_ = system_state->prefs();
if (utils::FileExists(kUpdateCompletedMarker))
status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT;
}
@@ -151,6 +150,7 @@
bool interactive,
bool is_test_mode,
bool is_user_initiated) {
+ LOG(INFO) << "Update called";
chrome_proxy_resolver_.Init();
fake_update_success_ = false;
if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
@@ -184,6 +184,7 @@
// before any update processing starts.
start_action_processor_ = true;
UpdateBootFlags();
+ LOG(INFO) << "Update finished";
}
bool UpdateAttempter::CalculateUpdateParams(const string& app_version,
@@ -215,7 +216,7 @@
device_policy.GetTargetVersionPrefix(
&omaha_request_params_.target_version_prefix);
- system_state_->SetDevicePolicy(&device_policy);
+ system_state_->set_device_policy(&device_policy);
set<string> allowed_types;
string allowed_types_str;
@@ -229,7 +230,7 @@
<< (allowed_types_str.empty() ? "all" : allowed_types_str);
} else {
LOG(INFO) << "No device policies present.";
- system_state_->SetDevicePolicy(NULL);
+ system_state_->set_device_policy(NULL);
}
CalculateScatteringParams(is_user_initiated);
@@ -287,7 +288,7 @@
// Take a copy of the old scatter value before we update it, as
// we need to update the waiting period if this value changes.
TimeDelta old_scatter_factor = scatter_factor_;
- const policy::DevicePolicy* device_policy = system_state_->GetDevicePolicy();
+ const policy::DevicePolicy* device_policy = system_state_->device_policy();
if (device_policy) {
int64 new_scatter_factor_in_secs = 0;
device_policy->GetScatterFactorInSeconds(&new_scatter_factor_in_secs);
@@ -414,19 +415,19 @@
update_check_fetcher->set_no_network_max_retries(interactive ? 1 : 3);
update_check_fetcher->set_check_certificate(CertificateChecker::kUpdate);
shared_ptr<OmahaRequestAction> update_check_action(
- new OmahaRequestAction(prefs_,
+ new OmahaRequestAction(system_state_,
&omaha_request_params_,
NULL,
update_check_fetcher, // passes ownership
false));
shared_ptr<OmahaResponseHandlerAction> response_handler_action(
- new OmahaResponseHandlerAction(prefs_));
+ new OmahaResponseHandlerAction(system_state_));
shared_ptr<FilesystemCopierAction> filesystem_copier_action(
new FilesystemCopierAction(false, false));
shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action(
new FilesystemCopierAction(true, false));
shared_ptr<OmahaRequestAction> download_started_action(
- new OmahaRequestAction(prefs_,
+ new OmahaRequestAction(system_state_,
&omaha_request_params_,
new OmahaEvent(
OmahaEvent::kTypeUpdateDownloadStarted),
@@ -443,7 +444,7 @@
new MultiRangeHttpFetcher(
download_fetcher))); // passes ownership
shared_ptr<OmahaRequestAction> download_finished_action(
- new OmahaRequestAction(prefs_,
+ new OmahaRequestAction(system_state_,
&omaha_request_params_,
new OmahaEvent(
OmahaEvent::kTypeUpdateDownloadFinished),
@@ -458,7 +459,7 @@
shared_ptr<PostinstallRunnerAction> postinstall_runner_action(
new PostinstallRunnerAction);
shared_ptr<OmahaRequestAction> update_complete_action(
- new OmahaRequestAction(prefs_,
+ new OmahaRequestAction(system_state_,
&omaha_request_params_,
new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
new LibcurlHttpFetcher(GetProxyResolver(),
@@ -878,11 +879,14 @@
if (error_event_.get() == NULL)
return false;
- LOG(INFO) << "Update failed -- reporting the error event.";
+ LOG(ERROR) << "Update failed.";
+ system_state_->payload_state()->UpdateFailed(error_event_->error_code);
+
+ LOG(INFO) << "Reporting the error event";
utils::SendErrorCodeToUma(system_state_->metrics_lib(),
error_event_->error_code);
shared_ptr<OmahaRequestAction> error_event_action(
- new OmahaRequestAction(prefs_,
+ new OmahaRequestAction(system_state_,
&omaha_request_params_,
error_event_.release(), // Pass ownership.
new LibcurlHttpFetcher(GetProxyResolver(),
@@ -998,7 +1002,7 @@
void UpdateAttempter::PingOmaha() {
if (!processor_->IsRunning()) {
shared_ptr<OmahaRequestAction> ping_action(
- new OmahaRequestAction(prefs_,
+ new OmahaRequestAction(system_state_,
&omaha_request_params_,
NULL,
new LibcurlHttpFetcher(GetProxyResolver(),