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/payload_state.h b/payload_state.h
index 8eb541c..a301ceb 100644
--- a/payload_state.h
+++ b/payload_state.h
@@ -50,6 +50,10 @@
   virtual void ExpectRebootInNewVersion(const std::string& target_version_uid);
   virtual void SetUsingP2PForDownloading(bool value);
 
+  void SetUsingP2PForSharing(bool value) override {
+    using_p2p_for_sharing_ = value;
+  }
+
   virtual inline std::string GetResponseSignature() {
     return response_signature_;
   }
@@ -109,16 +113,28 @@
   virtual void P2PNewAttempt();
   virtual bool P2PAttemptAllowed();
 
-  virtual bool GetUsingP2PForDownloading() {
+  bool GetUsingP2PForDownloading() const override {
     return using_p2p_for_downloading_;
   }
 
+  bool GetUsingP2PForSharing() const override {
+    return using_p2p_for_sharing_;
+  }
+
   base::TimeDelta GetScatteringWaitPeriod() override {
     return scattering_wait_period_;
   }
 
   void SetScatteringWaitPeriod(base::TimeDelta wait_period) override;
 
+  void SetP2PUrl(const std::string& url) override {
+    p2p_url_ = url;
+  }
+
+  std::string GetP2PUrl() const override {
+    return p2p_url_;
+  }
+
  private:
   enum class AttemptType {
     kUpdate,
@@ -410,9 +426,18 @@
   // This is the current response object from Omaha.
   OmahaResponse response_;
 
-  // Whether p2p is being used for downloading as set with the
-  // SetUsingP2PForDownloading() method.
+  // Whether P2P is being used for downloading and sharing.
   bool using_p2p_for_downloading_;
+  bool using_p2p_for_sharing_;
+
+  // Stores the P2P download URL, if one is used.
+  std::string p2p_url_;
+
+  // The cached value of |kPrefsP2PFirstAttemptTimestamp|.
+  base::Time p2p_first_attempt_timestamp_;
+
+  // The cached value of |kPrefsP2PNumAttempts|.
+  int p2p_num_attempts_;
 
   // This stores a "signature" of the current response. The signature here
   // refers to a subset of the current response from Omaha.  Each update to
@@ -517,12 +542,6 @@
   // reboot.
   std::string rollback_version_;
 
-  // The cached value of |kPrefsP2PFirstAttemptTimestamp|.
-  base::Time p2p_first_attempt_timestamp_;
-
-  // The cached value of |kPrefsP2PNumAttempts|.
-  int p2p_num_attempts_;
-
   // The number of bytes downloaded per attempt.
   int64_t attempt_num_bytes_downloaded_;