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/system_state.cc b/system_state.cc
index 0053fed..d13e18c 100644
--- a/system_state.cc
+++ b/system_state.cc
@@ -9,35 +9,54 @@
 namespace chromeos_update_engine {
 
 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed";
+static const char kPrefsDirectory[] = "/var/lib/update_engine/prefs";
 
 RealSystemState::RealSystemState()
     : device_policy_(NULL),
-      connection_manager_(this),
-      metrics_lib_(NULL) {}
+      connection_manager_(this) {}
+
+bool RealSystemState::Initialize() {
+  metrics_lib_.Init();
+
+  if (!prefs_.Init(FilePath(kPrefsDirectory))) {
+    LOG(ERROR) << "Failed to initialize preferences.";
+    return false;
+  }
+
+  if (!payload_state_.Initialize(&prefs_))
+    return false;
+
+  // All is well. Initialization successful.
+  return true;
+}
 
 bool RealSystemState::IsOOBEComplete() {
   return file_util::PathExists(FilePath(kOOBECompletedMarker));
 }
 
-void RealSystemState::SetDevicePolicy(
+void RealSystemState::set_device_policy(
     const policy::DevicePolicy* device_policy) {
   device_policy_ = device_policy;
 }
 
-const policy::DevicePolicy* RealSystemState::GetDevicePolicy() const {
+const policy::DevicePolicy* RealSystemState::device_policy() const {
   return device_policy_;
 }
 
-ConnectionManager* RealSystemState::GetConnectionManager() {
+ConnectionManager* RealSystemState::connection_manager() {
   return &connection_manager_;
 }
 
-void RealSystemState::set_metrics_lib(MetricsLibraryInterface* metrics_lib) {
-  metrics_lib_ = metrics_lib;
+MetricsLibraryInterface* RealSystemState::metrics_lib() {
+  return &metrics_lib_;
 }
 
-MetricsLibraryInterface* RealSystemState::metrics_lib() {
-  return metrics_lib_;
+PrefsInterface* RealSystemState::prefs() {
+  return &prefs_;
+}
+
+PayloadState* RealSystemState::payload_state() {
+  return &payload_state_;
 }
 
 }  // namespace chromeos_update_engine