AU: DeltaPerformer performs the download size/hash check now.

DownloadAction still calculates a hash in this case, however,
we can remove it when we remove old-style download support.

BUG=7393
TEST=unit tests, gmerge on device and updated with signed load,
with different download size/hash.

Change-Id: I5af9a09f87264159fc55070735463ad920fd7373

Review URL: http://codereview.chromium.org/3547019
diff --git a/delta_performer.h b/delta_performer.h
index 87a27dd..5425ea5 100644
--- a/delta_performer.h
+++ b/delta_performer.h
@@ -29,6 +29,7 @@
         fd_(-1),
         kernel_fd_(-1),
         manifest_valid_(false),
+        manifest_metadata_size_(0),
         next_operation_num_(0),
         buffer_offset_(0),
         last_updated_buffer_offset_(kuint64max),
@@ -51,12 +52,15 @@
   int Close();
 
   // Verifies the downloaded payload against the signed hash included in the
-  // payload and returns true on success, false on failure. This method should
-  // be called after closing the stream. Note this method returns true if the
-  // public key is unavailable; it returns false if the public key is available
-  // but the delta payload doesn't include a signature. If |public_key_path| is
-  // an empty string, uses the default public key path.
-  bool VerifyPayload(const std::string& public_key_path);
+  // payload as well as against the update check hash and size and returns true
+  // on success, false on failure. This method should be called after closing
+  // the stream. Note this method skips the signed hash check if the public key
+  // is unavailable; it returns false if the public key is available but the
+  // delta payload doesn't include a signature. If |public_key_path| is an empty
+  // string, uses the default public key path.
+  bool VerifyPayload(const std::string& public_key_path,
+                     const std::string& update_check_response_hash,
+                     const uint64_t update_check_response_size);
 
   // Converts an ordered collection of Extent objects which contain data of
   // length full_length to a comma-separated string. For each Extent, the
@@ -108,9 +112,9 @@
   bool ExtractSignatureMessage(
       const DeltaArchiveManifest_InstallOperation& operation);
 
-  // Discard |count| bytes from the beginning of buffer_. If |do_hash| is true,
-  // updates the hash calculator with these bytes before discarding them.
-  void DiscardBufferHeadBytes(size_t count, bool do_hash);
+  // Updates the hash calculator with |count| bytes at the head of |buffer_| and
+  // then discards them.
+  void DiscardBufferHeadBytes(size_t count);
 
   // Checkpoints the update progress into persistent storage to allow this
   // update attempt to be resumed after reboot.
@@ -130,6 +134,7 @@
 
   DeltaArchiveManifest manifest_;
   bool manifest_valid_;
+  uint64_t manifest_metadata_size_;
 
   // Index of the next operation to perform in the manifest.
   int next_operation_num_;
@@ -148,9 +153,12 @@
   // The block size (parsed from the manifest).
   uint32_t block_size_;
 
-  // Calculate the payload hash to verify against the signed hash.
+  // Calculates the payload hash.
   OmahaHashCalculator hash_calculator_;
 
+  // Saves the signed hash context.
+  std::string signed_hash_context_;
+
   // Signatures message blob extracted directly from the payload.
   std::vector<char> signatures_message_data_;