update_engine: Replace vector<Extent> with RepeatedPtrField<Extent>

This patch removes references to vector<Extent> and replaces them with
RepeatedPtrField in payload_consumer. Extent itself is a protobuf item
and it makes sense to use google::protobuf::RepeatedPtrField instead of
vector because then we won't have any extra copy to vector. We can
directly use the list of extents given in the payload protobuf.

Also removed references to vector in files which did not use vector.

BUG=chromium:766397
TEST=FEATURES="test" emerge-amd64-generic update_engine

Change-Id: I1f12332ff4d6303c1e4b7470bb87bf934acdf81a
Reviewed-on: https://chromium-review.googlesource.com/672006
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
diff --git a/payload_consumer/extent_writer.h b/payload_consumer/extent_writer.h
index 6484ebf..2c15861 100644
--- a/payload_consumer/extent_writer.h
+++ b/payload_consumer/extent_writer.h
@@ -17,7 +17,8 @@
 #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_EXTENT_WRITER_H_
 #define UPDATE_ENGINE_PAYLOAD_CONSUMER_EXTENT_WRITER_H_
 
-#include <vector>
+#include <memory>
+#include <utility>
 
 #include <base/logging.h>
 #include <brillo/secure_blob.h>
@@ -40,7 +41,7 @@
 
   // Returns true on success.
   virtual bool Init(FileDescriptorPtr fd,
-                    const std::vector<Extent>& extents,
+                    const google::protobuf::RepeatedPtrField<Extent>& extents,
                     uint32_t block_size) = 0;
 
   // Returns true on success.
@@ -66,11 +67,12 @@
   ~DirectExtentWriter() override = default;
 
   bool Init(FileDescriptorPtr fd,
-            const std::vector<Extent>& extents,
+            const google::protobuf::RepeatedPtrField<Extent>& extents,
             uint32_t block_size) override {
     fd_ = fd;
     block_size_ = block_size;
     extents_ = extents;
+    cur_extent_ = extents_.begin();
     return true;
   }
   bool Write(const void* bytes, size_t count) override;
@@ -80,11 +82,11 @@
   FileDescriptorPtr fd_{nullptr};
 
   size_t block_size_{0};
-  // Bytes written into next_extent_index_ thus far
+  // Bytes written into |cur_extent_| thus far.
   uint64_t extent_bytes_written_{0};
-  std::vector<Extent> extents_;
-  // The next call to write should correspond to extents_[next_extent_index_]
-  std::vector<Extent>::size_type next_extent_index_{0};
+  google::protobuf::RepeatedPtrField<Extent> extents_;
+  // The next call to write should correspond to |cur_extents_|.
+  google::protobuf::RepeatedPtrField<Extent>::iterator cur_extent_;
 };
 
 // Takes an underlying ExtentWriter to which all operations are delegated.
@@ -100,7 +102,7 @@
   ~ZeroPadExtentWriter() override = default;
 
   bool Init(FileDescriptorPtr fd,
-            const std::vector<Extent>& extents,
+            const google::protobuf::RepeatedPtrField<Extent>& extents,
             uint32_t block_size) override {
     block_size_ = block_size;
     return underlying_extent_writer_->Init(fd, extents, block_size);