Transfer memory ownership when stacking ExtentWriters.

The ExtentWriter implementations are meant to be stacked in a way that
the underlying extent writer can't be reused. Calling End() on the top
of the stack will call End() on every ExtentWriter.

This patch enforces this design decision in the interface transfering
the ownership of the ExtentWriter when stacking them using a unique_ptr
instead of a plain pointer.

Bug: 23604708
Test: Updated unittests.

Change-Id: Ie3b5b9cbb3058359c487a783f6fb3c0ac65bde00
diff --git a/bzip_extent_writer.h b/bzip_extent_writer.h
index d854dd2..6941c66 100644
--- a/bzip_extent_writer.h
+++ b/bzip_extent_writer.h
@@ -18,6 +18,7 @@
 #define UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_
 
 #include <bzlib.h>
+#include <memory>
 #include <vector>
 
 #include <chromeos/secure_blob.h>
@@ -33,19 +34,20 @@
 
 class BzipExtentWriter : public ExtentWriter {
  public:
-  explicit BzipExtentWriter(ExtentWriter* next) : next_(next) {
+  explicit BzipExtentWriter(std::unique_ptr<ExtentWriter> next)
+      : next_(std::move(next)) {
     memset(&stream_, 0, sizeof(stream_));
   }
-  ~BzipExtentWriter() {}
+  ~BzipExtentWriter() override = default;
 
   bool Init(FileDescriptorPtr fd,
             const std::vector<Extent>& extents,
-            uint32_t block_size);
-  bool Write(const void* bytes, size_t count);
-  bool EndImpl();
+            uint32_t block_size) override;
+  bool Write(const void* bytes, size_t count) override;
+  bool EndImpl() override;
 
  private:
-  ExtentWriter* const next_;  // The underlying ExtentWriter.
+  std::unique_ptr<ExtentWriter> next_;  // The underlying ExtentWriter.
   bz_stream stream_;  // the libbz2 stream
   chromeos::Blob input_buffer_;
 };