Move partition writer to a separate file

Test: treehugger && serve an OTA update
Change-Id: I803692110841ce6d2207555ac7a682e9f989363d
diff --git a/payload_consumer/delta_performer.h b/payload_consumer/delta_performer.h
index bee7fde..d44f6c2 100644
--- a/payload_consumer/delta_performer.h
+++ b/payload_consumer/delta_performer.h
@@ -35,6 +35,7 @@
 #include "update_engine/payload_consumer/file_descriptor.h"
 #include "update_engine/payload_consumer/file_writer.h"
 #include "update_engine/payload_consumer/install_plan.h"
+#include "update_engine/payload_consumer/partition_writer.h"
 #include "update_engine/payload_consumer/payload_metadata.h"
 #include "update_engine/payload_consumer/payload_verifier.h"
 #include "update_engine/update_metadata.pb.h"
@@ -46,9 +47,6 @@
 class HardwareInterface;
 class PrefsInterface;
 
-// At the bottom of this file.
-class PartitionWriter;
-
 // This class performs the actions in a delta update synchronously. The delta
 // update itself should be passed in in chunks as it is received.
 class DeltaPerformer : public FileWriter {
@@ -412,88 +410,6 @@
   DISALLOW_COPY_AND_ASSIGN(DeltaPerformer);
 };
 
-class PartitionWriter {
- public:
-  PartitionWriter(const PartitionUpdate& partition_update,
-                  const InstallPlan::Partition& install_part,
-                  DynamicPartitionControlInterface* dynamic_control,
-                  size_t block_size,
-                  bool is_interactive);
-  ~PartitionWriter();
-  // Compare |calculated_hash| with source hash in |operation|, return false and
-  // dump hash and set |error| if don't match.
-  // |source_fd| is the file descriptor of the source partition.
-  static bool ValidateSourceHash(const brillo::Blob& calculated_hash,
-                                 const InstallOperation& operation,
-                                 const FileDescriptorPtr source_fd,
-                                 ErrorCode* error);
-
-  // Perform necessary initialization work before InstallOperation can be
-  // applied to this partition
-  [[nodiscard]] bool Init(const InstallPlan* install_plan,
-                          bool source_may_exist);
-
-  int Close();
-
-  // These perform a specific type of operation and return true on success.
-  // |error| will be set if source hash mismatch, otherwise |error| might not be
-  // set even if it fails.
-  [[nodiscard]] bool PerformReplaceOperation(const InstallOperation& operation,
-                                             const void* data,
-                                             size_t count);
-  [[nodiscard]] bool PerformZeroOrDiscardOperation(
-      const InstallOperation& operation);
-
-  [[nodiscard]] bool PerformSourceCopyOperation(
-      const InstallOperation& operation, ErrorCode* error);
-  [[nodiscard]] bool PerformSourceBsdiffOperation(
-      const InstallOperation& operation,
-      ErrorCode* error,
-      const void* data,
-      size_t count);
-  [[nodiscard]] bool PerformPuffDiffOperation(const InstallOperation& operation,
-                                              ErrorCode* error,
-                                              const void* data,
-                                              size_t count);
-
- private:
-  friend class PartitionWriterTest;
-  FRIEND_TEST(PartitionWriterTest, ChooseSourceFDTest);
-
-  bool OpenCurrentECCPartition();
-  // For a given operation, choose the source fd to be used (raw device or error
-  // correction device) based on the source operation hash.
-  // Returns nullptr if the source hash mismatch cannot be corrected, and set
-  // the |error| accordingly.
-  FileDescriptorPtr ChooseSourceFD(const InstallOperation& operation,
-                                   ErrorCode* error);
-
-  const PartitionUpdate& partition_update_;
-  const InstallPlan::Partition& install_part_;
-  DynamicPartitionControlInterface* dynamic_control_;
-  std::string source_path_;
-  std::string target_path_;
-  FileDescriptorPtr source_fd_;
-  FileDescriptorPtr target_fd_;
-  const bool interactive_;
-  const size_t block_size_;
-  // File descriptor of the error corrected source partition. Only set while
-  // updating partition using a delta payload for a partition where error
-  // correction is available. The size of the error corrected device is smaller
-  // than the underlying raw device, since it doesn't include the error
-  // correction blocks.
-  FileDescriptorPtr source_ecc_fd_{nullptr};
-
-  // The total number of operations that failed source hash verification but
-  // passed after falling back to the error-corrected |source_ecc_fd_| device.
-  uint64_t source_ecc_recovered_failures_{0};
-
-  // Whether opening the current partition as an error-corrected device failed.
-  // Used to avoid re-opening the same source partition if it is not actually
-  // error corrected.
-  bool source_ecc_open_failure_{false};
-};
-
 }  // namespace chromeos_update_engine
 
 #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_DELTA_PERFORMER_H_