update_engine: Relocate inference and storage of P2P related properties.

This change moves the inference of P2P related properties from
OmahaRequestAction to OmahaResponseHandlerAction, and their storage from
OmahaRequestParams to PayloadState. This is needed in order for the
UpdateCanStart policy to be able to decide P2P properties, which only
happens after the Omaha response is received and processed, and prior to
applying the update.  Further, P2P properties do not affect the Omaha
request, and so there's no reason for them to reside in
OmahaRequestParams nor decided as early as OmahaRequestAction.

Additional cleanup includes swapping expected/actual arguments to EXPECT
macros where appropriate, and removing redundant .Times(1) expectation
qualifiers.

BUG=chromium:384087
TEST=Unit tests.

Change-Id: I6d5b4b44745d5dab7e350bdf019dbf804bf196a1
Reviewed-on: https://chromium-review.googlesource.com/223618
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index fad9ad1..7d7af81 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -766,6 +766,8 @@
   string current_response(response_buffer_.begin(), response_buffer_.end());
   LOG(INFO) << "Omaha request response: " << current_response;
 
+  PayloadStateInterface* const payload_state = system_state_->payload_state();
+
   // Events are best effort transactions -- assume they always succeed.
   if (IsEvent()) {
     CHECK(!HasOutputPipe()) << "No output pipe allowed for event requests.";
@@ -840,12 +842,12 @@
   if (output_object.disable_p2p_for_downloading) {
     LOG(INFO) << "Forcibly disabling use of p2p for downloading as "
               << "requested by Omaha.";
-    params_->set_use_p2p_for_downloading(false);
+    payload_state->SetUsingP2PForDownloading(false);
   }
   if (output_object.disable_p2p_for_sharing) {
     LOG(INFO) << "Forcibly disabling use of p2p for sharing as "
               << "requested by Omaha.";
-    params_->set_use_p2p_for_sharing(false);
+    payload_state->SetUsingP2PForSharing(false);
   }
 
   // Update the payload state with the current response. The payload state
@@ -854,17 +856,16 @@
   // as possible in this method so that if a new release gets pushed and then
   // got pulled back due to some issues, we don't want to clear our internal
   // state unnecessarily.
-  PayloadStateInterface* payload_state = system_state_->payload_state();
   payload_state->SetResponse(output_object);
 
   // It could be we've already exceeded the deadline for when p2p is
   // allowed or that we've tried too many times with p2p. Check that.
-  if (params_->use_p2p_for_downloading()) {
+  if (payload_state->GetUsingP2PForDownloading()) {
     payload_state->P2PNewAttempt();
     if (!payload_state->P2PAttemptAllowed()) {
       LOG(INFO) << "Forcibly disabling use of p2p for downloading because "
                 << "of previous failures when using p2p.";
-      params_->set_use_p2p_for_downloading(false);
+      payload_state->SetUsingP2PForDownloading(false);
     }
   }
 
@@ -877,7 +878,7 @@
   // attention to wall-clock-based waiting if the URL is indeed
   // available via p2p. Therefore, check if the file is available via
   // p2p before deferring...
-  if (params_->use_p2p_for_downloading()) {
+  if (payload_state->GetUsingP2PForDownloading()) {
     LookupPayloadViaP2P(output_object);
   } else {
     CompleteProcessing();
@@ -909,11 +910,11 @@
 void OmahaRequestAction::OnLookupPayloadViaP2PCompleted(const string& url) {
   LOG(INFO) << "Lookup complete, p2p-client returned URL '" << url << "'";
   if (!url.empty()) {
-    params_->set_p2p_url(url);
+    system_state_->payload_state()->SetP2PUrl(url);
   } else {
     LOG(INFO) << "Forcibly disabling use of p2p for downloading "
               << "because no suitable peer could be found.";
-    params_->set_use_p2p_for_downloading(false);
+    system_state_->payload_state()->SetUsingP2PForDownloading(false);
   }
   CompleteProcessing();
 }
@@ -971,7 +972,9 @@
   // defer the download. This is because the download will always
   // happen from a peer on the LAN and we've been waiting in line for
   // our turn.
-  if (params_->use_p2p_for_downloading() && !params_->p2p_url().empty()) {
+  const PayloadStateInterface* payload_state = system_state_->payload_state();
+  if (payload_state->GetUsingP2PForDownloading() &&
+      !payload_state->GetP2PUrl().empty()) {
     LOG(INFO) << "Download not deferred because download "
               << "will happen from a local peer (via p2p).";
     return false;