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.h b/system_state.h
index 7d7ac09..04ad382 100644
--- a/system_state.h
+++ b/system_state.h
@@ -10,11 +10,14 @@
 #include <policy/libpolicy.h>
 
 #include <update_engine/connection_manager.h>
+#include <update_engine/payload_state.h>
+#include <update_engine/prefs.h>
 
 namespace chromeos_update_engine {
 
 // An interface to global system context, including platform resources,
-// the current state of the system, high-level objects, system interfaces, etc.
+// the current state of the system, high-level objects whose lifetime is same
+// as main, system interfaces, etc.
 // Carved out separately so it can be mocked for unit tests.
 // Currently it has only one method, but we should start migrating other
 // methods to use this as and when needed to unit test them.
@@ -29,15 +32,20 @@
   virtual bool IsOOBEComplete() = 0;
 
   // Sets or gets the latest device policy.
-  virtual void SetDevicePolicy(const policy::DevicePolicy* device_policy) = 0;
-  virtual const policy::DevicePolicy* GetDevicePolicy() const = 0;
+  virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
+  virtual const policy::DevicePolicy* device_policy() const = 0;
 
   // Gets the connection manager object.
-  virtual ConnectionManager* GetConnectionManager() = 0;
+  virtual ConnectionManager* connection_manager() = 0;
 
-  // Sets or gets the Metrics Library interface for reporting UMA stats.
-  virtual void set_metrics_lib(MetricsLibraryInterface* metrics_lib) = 0;
+  // Gets the Metrics Library interface for reporting UMA stats.
   virtual MetricsLibraryInterface* metrics_lib() = 0;
+
+  // Gets the interface object for persisted store.
+  virtual PrefsInterface* prefs() = 0;
+
+  // Gets the URL State object.
+  virtual PayloadState* payload_state() = 0;
 };
 
 // A real implementation of the SystemStateInterface which is
@@ -50,14 +58,21 @@
 
   virtual bool IsOOBEComplete();
 
-  virtual void SetDevicePolicy(const policy::DevicePolicy* device_policy);
-  virtual const policy::DevicePolicy* GetDevicePolicy() const;
+  virtual void set_device_policy(const policy::DevicePolicy* device_policy);
+  virtual const policy::DevicePolicy* device_policy() const;
 
-  virtual ConnectionManager* GetConnectionManager();
+  virtual ConnectionManager* connection_manager();
 
-  virtual void set_metrics_lib(MetricsLibraryInterface* metrics_lib);
   virtual MetricsLibraryInterface* metrics_lib();
 
+  virtual PrefsInterface* prefs();
+
+  virtual PayloadState* payload_state();
+
+  // Initializs this concrete object. Other methods should be invoked only
+  // if the object has been initialized successfully.
+  bool Initialize();
+
 private:
   // The latest device policy object from the policy provider.
   const policy::DevicePolicy* device_policy_;
@@ -67,7 +82,14 @@
   ConnectionManager connection_manager_;
 
   // The Metrics Library interface for reporting UMA stats.
-  MetricsLibraryInterface* metrics_lib_;
+  MetricsLibrary metrics_lib_;
+
+  // Interface for persisted store.
+  Prefs prefs_;
+
+  // All state pertaining to payload state such as
+  // response, URL, back-off states.
+  PayloadState payload_state_;
 };
 
 }  // namespace chromeos_update_engine