AU: Update Downloader to support our image formats.

The downloader used to be dumb in the sense that it would pipe output
to either a DirectFileWriter or a DirectFileWriter via a
GzipDecompressingFileWriter, depending on if we were downloading an
update that was compressed or not. Sadly, things have gotten more
complex: we need to download to two partitions (kernel + rootfs), and
we may stream data via a DeltaPerformer (a type of FileWriter) to the
disk. Thus, the Downloader streams to either
1. gzip decompress->split_writer->direct to disk OR
2. delta performer

Other misc changes: Change FilesystemCopierAction to support
optionally copying the kernel partition rather than root partition.

InstallPlan struct: add an entry for destiation kernel partition.

Test Utils: a new ScopedTempFile class

Utils: support for getting the booted kernel partition device.

BUG=None
TEST=attached unittests

Review URL: http://codereview.chromium.org/1694025
diff --git a/download_action.h b/download_action.h
index d5ec026..0f375fa 100644
--- a/download_action.h
+++ b/download_action.h
@@ -16,13 +16,20 @@
 #include "base/scoped_ptr.h"
 #include "update_engine/action.h"
 #include "update_engine/decompressing_file_writer.h"
+#include "update_engine/delta_performer.h"
 #include "update_engine/file_writer.h"
 #include "update_engine/http_fetcher.h"
 #include "update_engine/install_plan.h"
 #include "update_engine/omaha_hash_calculator.h"
+#include "update_engine/split_file_writer.h"
 
-// The Download Action downloads a requested url to a specified path on disk.
-// The url and output path are determined by the InstallPlan passed in.
+// The Download Action downloads a specified url to disk. The url should
+// point to either a full or delta update. If a full update, the file will
+// be piped into a SplitFileWriter, which will direct it to the kernel
+// and rootfs partitions. If it's a delta update, the destination kernel
+// and rootfs should already contain the source-version that this delta
+// update goes from. In this case, the update will be piped into a
+// DeltaPerformer that will apply the delta to the disk.
 
 namespace chromeos_update_engine {
 
@@ -50,6 +57,11 @@
   void PerformAction();
   void TerminateProcessing();
 
+  // Testing
+  void SetTestFileWriter(FileWriter* writer) {
+    writer_ = writer;
+  }
+
   // Debugging/logging
   static std::string StaticType() { return "DownloadAction"; }
   std::string Type() const { return StaticType(); }
@@ -60,33 +72,23 @@
   virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
 
  private:
-  // Expected size of the file (will be used for progress info)
-  const size_t size_;
-
-  // URL to download
-  std::string url_;
-
-  // Path to save URL to
-  std::string output_path_;
-
-  // Expected hash of the file. The hash must match for this action to
-  // succeed.
-  std::string hash_;
-
-  // Whether the caller requested that we decompress the downloaded data.
-  bool should_decompress_;
+  // The InstallPlan passed in
+  InstallPlan install_plan_;
 
   // The FileWriter that downloaded data should be written to. It will
-  // either point to *decompressing_file_writer_ or *direct_file_writer_.
+  // either point to *decompressing_file_writer_ or *delta_performer_.
   FileWriter* writer_;
 
-  // If non-null, a FileWriter used for gzip decompressing downloaded data
+  // These are used for full updates:
   scoped_ptr<GzipDecompressingFileWriter> decompressing_file_writer_;
+  scoped_ptr<SplitFileWriter> split_file_writer_;
+  scoped_ptr<DirectFileWriter> kernel_file_writer_;
+  scoped_ptr<DirectFileWriter> rootfs_file_writer_;
 
-  // Used to write out the downloaded file
-  scoped_ptr<DirectFileWriter> direct_file_writer_;
+  // Used to apply a delta update:
+  scoped_ptr<DeltaPerformer> delta_performer_;
 
-  // pointer to the HttpFetcher that does the http work
+  // Pointer to the HttpFetcher that does the http work.
   scoped_ptr<HttpFetcher> http_fetcher_;
 
   // Used to find the hash of the bytes downloaded