Upgrade update_engine from Omaha v2 to v3 protocol.

Omaha had released the v3 protocol long back, but update_engine kept
using the v2 protocol as there was no immediate need to move. But now
that we need to support HTTP-based downloads, we need to supply multiple
URLs for each rule, one for HTTP, one for HTTPS fallback. Even for
HTTPs, it is also useful for scenarios such as specifying a Google
storage URL as the primary download point and keeping Lorry as a backup
URL. Multiple URL support is available only on Omaha v3 protocol.

So, this CL is to first upgrade of the client protocol from v2 to v3. It
does not add any new functionality and still supports only one URL. The
subsequent checkins will take advantage of the multiple URL support.

This CL also includes a sample xml file which illustrates how the new
response from the Omaha v3 server would look like, which should greatly
help in understand the changes.

As part of this change, I've also consolidated a few error codes which
had practically zero occurrence into one error code and reused those
error codes for the recently added errors (which haven't been shipped
anywhere yet). Since we're now publishing all the error codes in UMA, we
need to be conservative in defining distinct error codes in order to
reduce the memory usage of Chrome for UMA stats.

BUG=chromium-os:6594
TEST=Tested on ZGB with Omaha v3 server. Updated unit tests and they pass.
Change-Id: I187aa0500e39623684130ba9e3d1d948c0e60627
Reviewed-on: https://gerrit.chromium.org/gerrit/36758
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
Commit-Ready: Chris Sosa <sosa@chromium.org>
diff --git a/omaha_request_action.h b/omaha_request_action.h
index 73641b4..8a5a5d5 100644
--- a/omaha_request_action.h
+++ b/omaha_request_action.h
@@ -35,6 +35,7 @@
         poll_interval(0),
         size(0),
         metadata_size(0),
+        max_days_to_scatter(0),
         needs_admin(false),
         prompt(false) {}
   // True iff there is an update to be downloaded.
@@ -52,6 +53,7 @@
   std::string deadline;
   off_t size;
   off_t metadata_size;
+  int max_days_to_scatter;
   bool needs_admin;
   bool prompt;
 };
@@ -160,8 +162,8 @@
   // Delegate methods (see http_fetcher.h)
   virtual void ReceivedBytes(HttpFetcher *fetcher,
                              const char* bytes, int length);
-  virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
 
+  virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
   // Returns true if this is an Event request, false if it's an UpdateCheck.
   bool IsEvent() const { return event_.get() != NULL; }
 
@@ -177,18 +179,54 @@
 
   // Returns true if the download of a new update should be deferred.
   // False if the update can be downloaded.
-  bool ShouldDeferDownload(xmlNode* updatecheck_node);
+  bool ShouldDeferDownload(OmahaResponse* output_object);
 
   // Returns true if the basic wall-clock-based waiting period has been
   // satisfied based on the scattering policy setting. False otherwise.
   // If true, it also indicates whether the additional update-check-count-based
   // waiting period also needs to be satisfied before the download can begin.
   WallClockWaitResult IsWallClockBasedWaitingSatisfied(
-      xmlNode* updatecheck_node);
+      OmahaResponse* output_object);
 
   // Returns true if the update-check-count-based waiting period has been
   // satisfied. False otherwise.
-  bool IsUpdateCheckCountBasedWaitingSatisfied(xmlNode* updatecheck_node);
+  bool IsUpdateCheckCountBasedWaitingSatisfied();
+
+  // Parses the response from Omaha that's available in |doc| using the other
+  // helper methods below and populates the |output_object| with the relevant
+  // values. Returns true if we should continue the parsing.  False otherwise,
+  // in which case it sets any error code using |completer|.
+  bool ParseResponse(xmlDoc* doc,
+                     OmahaResponse* output_object,
+                     ScopedActionCompleter* completer);
+
+  // Parses the status property in the given update_check_node and populates
+  // |output_object| if valid. Returns true if we should continue the parsing.
+  // False otherwise, in which case it sets any error code using |completer|.
+  bool ParseStatus(xmlNode* update_check_node,
+                   OmahaResponse* output_object,
+                   ScopedActionCompleter* completer);
+
+  // Parses the URL nodes in the given XML document and populates
+  // |output_object| if valid. Returns true if we should continue the parsing.
+  // False otherwise, in which case it sets any error code using |completer|.
+  bool ParseUrls(xmlDoc* doc,
+                 OmahaResponse* output_object,
+                 ScopedActionCompleter* completer);
+
+  // Parses the package node in the given XML document and populates
+  // |output_object| if valid. Returns true if we should continue the parsing.
+  // False otherwise, in which case it sets any error code using |completer|.
+  bool ParsePackage(xmlDoc* doc,
+                    OmahaResponse* output_object,
+                    ScopedActionCompleter* completer);
+
+  // Parses the other parameters in the given XML document and populates
+  // |output_object| if valid. Returns true if we should continue the parsing.
+  // False otherwise, in which case it sets any error code using |completer|.
+  bool ParseParams(xmlDoc* doc,
+                   OmahaResponse* output_object,
+                   ScopedActionCompleter* completer);
 
   // Access to the preferences store.
   PrefsInterface* prefs_;