update_engine: UM: Properly handle update download deterrents.

The UpdateCanStart policy request needs to satisfy two related
requirements:

* It must allow the caller to proceed with the update even if some forms
  of download are not allowed (for example, HTTP/HTTPS download blocked
  due to scattering) but other are allowed (for example, P2P).

* It needs to assess all the input provided and, upon returning
  successfully, convey any new values that pertain to downloading of the
  update payload and that need to be persisted (such as the download
  URL, backoff and scattering values, and so on). The caller in turn is
  assured that, having successfully returned, the policy has indeed
  considered all state and it is safe to clear parts of it (such as the
  download error history).

This change ensures that the policy suppresses scattering and backoff
decisions if P2P download is allowed.  This only suppresses the final
decision, but otherwise still returns whatever URL index and error count
that were inferred. It further adjusts the way in which various download
deterrents (check due, scattering, backoff) are handled, deferring
responses to the very end of the evaluation and thus returning
a complete result.

BUG=chromium:384087
TEST=Unit tests.

Change-Id: Ie95976295c0cd635e2a10912308b8756a677682f
Reviewed-on: https://chromium-review.googlesource.com/222263
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/update_manager/policy.h b/update_manager/policy.h
index b801d91..42f4e15 100644
--- a/update_manager/policy.h
+++ b/update_manager/policy.h
@@ -132,15 +132,16 @@
   // If update cannot proceed, a reason code for why it cannot do so.
   UpdateCannotStartReason cannot_start_reason;
 
-  // Attributes pertaining to the case where update is allowed. The update
-  // engine uses them to choose the means for downloading and applying an
-  // update.
+  // Download related attributes. The update engine uses them to choose the
+  // means for downloading and applying an update.
   //
-  // The index of the download URL to use, or -1 if no suitable URL was found;
-  // in the latter case, there may still be other means for download (like P2P).
-  // This value needs to be persisted and handed back to the policy on the next
-  // time it is called.
+  // The index of the download URL to use (-1 means no suitable URL was found)
+  // and whether it can be used. Even if there's no URL or its use is not
+  // allowed (backoff, scattering) there may still be other means for download
+  // (like P2P).  The URL index needs to be persisted and handed back to the
+  // policy on the next time it is called.
   int download_url_idx;
+  bool download_url_allowed;
   // The number of download errors associated with this download URL. This value
   // needs to be persisted and handed back to the policy on the next time it is
   // called.