Implement exponential backoff for throttling repeated AU downloads.

Today we retry the same payload over and over again every hour. Ideally,
we shouldn't require ever to re-download the same payload again. But
from experience we find that post-install or firmware updates may succeed
on a second attempt. So until we have code that can do such selective
retries of those steps, we currently re-download and re-apply the whole
payload. So instead of retrying over and over again, we backoff the
successive payload download attempts at 1 day, 2 days, 4 days, etc. with
an upper limit of 16 days.

Another subtle reason for which we depend on the payload retry mechanism
today is if we've failed downloading the payload via all the URLs that are
specified in the rule, we don't want to keep re-attempting the download.
This case is different from the case discussed above, because in this case
we haven't even downloaded a payload once completely. In this case also,
there's a need for throttling the amount of bytes we end up downloading
repeatedly for a particular operation that may fail. This is done by
treating the exhaustion of all URLs as equivalent to having downloaded
a full payload and subjecting it to the same backoff behavior.

We waive backoffs for dev/test images so as not to cause any delay in
our testing or development.

BUG=chromium-os:36806
TEST=Added new unit tests. Tested all scenarios on my ZGB.
Change-Id: I6bd0d3f296a3c0da0a8026fb71b24785d825e39c
Reviewed-on: https://gerrit.chromium.org/gerrit/40220
Commit-Queue: Jay Srinivasan <jaysri@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/omaha_request_action.h b/omaha_request_action.h
index ebd3ed0..b6e31af 100644
--- a/omaha_request_action.h
+++ b/omaha_request_action.h
@@ -18,6 +18,7 @@
 
 #include "update_engine/action.h"
 #include "update_engine/http_fetcher.h"
+#include "update_engine/omaha_response.h"
 
 // The Omaha Request action makes a request to Omaha and can output
 // the response on the output ActionPipe.
@@ -28,47 +29,6 @@
 // UTF-8 formatted. Output will be UTF-8 formatted.
 std::string XmlEncode(const std::string& input);
 
-// This struct encapsulates the data Omaha's response for the request.
-// These strings in this struct are not XML escaped.
-struct OmahaResponse {
-  OmahaResponse()
-      : update_exists(false),
-        poll_interval(0),
-        size(0),
-        metadata_size(0),
-        max_days_to_scatter(0),
-        max_failure_count_per_url(0),
-        needs_admin(false),
-        prompt(false) {}
-  // True iff there is an update to be downloaded.
-  bool update_exists;
-
-  // If non-zero, server-dictated poll frequency in seconds.
-  int poll_interval;
-
-  // These are only valid if update_exists is true:
-  std::string display_version;
-
-  // The ordered list of URLs in the Omaha response. Each item is a complete
-  // URL (i.e. in terms of Omaha XML, each value is a urlBase + packageName)
-  std::vector<std::string> payload_urls;
-
-  std::string more_info_url;
-  std::string hash;
-  std::string metadata_signature;
-  std::string deadline;
-  off_t size;
-  off_t metadata_size;
-  int max_days_to_scatter;
-  // The number of URL-related failures to tolerate before moving on to the
-  // next URL in the current pass. This is a configurable value from the
-  // Omaha Response attribute, if ever we need to fine tune the behavior.
-  int max_failure_count_per_url;
-  bool needs_admin;
-  bool prompt;
-};
-COMPILE_ASSERT(sizeof(off_t) == 8, off_t_not_64bit);
-
 // This struct encapsulates the Omaha event information. For a
 // complete list of defined event types and results, see
 // http://code.google.com/p/omaha/wiki/ServerProtocol#event