AU: Verify source rootfs/kernel hashes before applying delta.

New style full updates will not send the old rootfs hash so no check takes
place.

BUG=7562
TEST=unit tests, gmerged on device and tested with good/bad source partition

Change-Id: I65b28bf57110e4d87472d4aea59121878cde24b0

Review URL: http://codereview.chromium.org/3712003
diff --git a/download_action.cc b/download_action.cc
index 2920d16..b6f7f81 100644
--- a/download_action.cc
+++ b/download_action.cc
@@ -64,6 +64,10 @@
       writer_ = decompressing_file_writer_.get();
     } else {
       delta_performer_.reset(new DeltaPerformer(prefs_));
+      delta_performer_->set_current_kernel_hash(
+          &install_plan_.current_kernel_hash);
+      delta_performer_->set_current_rootfs_hash(
+          &install_plan_.current_rootfs_hash);
       writer_ = delta_performer_.get();
     }
   }
@@ -93,9 +97,10 @@
 }
 
 void DownloadAction::TerminateProcessing() {
-  CHECK(writer_);
-  CHECK_EQ(writer_->Close(), 0);
-  writer_ = NULL;
+  if (writer_) {
+    LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer.";
+    writer_ = NULL;
+  }
   http_fetcher_->TerminateTransfer();
   if (delegate_) {
     delegate_->SetDownloadStatus(false);  // Set to inactive.
@@ -108,8 +113,12 @@
   bytes_received_ += length;
   if (delegate_)
     delegate_->BytesReceived(bytes_received_, install_plan_.size);
-  int rc = writer_->Write(bytes, length);
-  TEST_AND_RETURN(rc >= 0);
+  if (writer_ && writer_->Write(bytes, length) < 0) {
+    LOG(ERROR) << "Write error -- terminating processing.";
+    TerminateProcessing();
+    processor_->ActionComplete(this, kActionCodeDownloadWriteError);
+    return;
+  }
   omaha_hash_calculator_.Update(bytes, length);
 }
 
@@ -131,7 +140,7 @@
 
 void DownloadAction::TransferComplete(HttpFetcher *fetcher, bool successful) {
   if (writer_) {
-    CHECK_EQ(writer_->Close(), 0) << errno;
+    LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer.";
     writer_ = NULL;
   }
   if (delegate_) {