update_engine: Move InstallOperation to the top level.

The InstallOperation message in the protobuf is a nested message
inside the DeltaArchiveManifest message, making all references to
operation types be very long names like
DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ while most other
messages are not nested in the DeltaArchiveManifest message.

To improve readability and to prepare for future update metadata
changes, this patch moves the InstallOperation message to the top level
and replaces all references to operation types with the new shorter
version like InstallOperation::REPLACE_BZ.

This change only impacts the scope of the generated classes and the
serialized format of the protobuf. This exact same question was
addressed by protobuf maintainers here:

https://groups.google.com/forum/#!topic/protobuf/azWAPa6hP4A

Finally coding style and indentation was automatically updated due to
the shorter names.

BUG=b:23179128
TEST=Unittest still pass.

Change-Id: I55add54265934cd1fd3e9cb786c5d3f784902d17
Reviewed-on: https://chromium-review.googlesource.com/293504
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/delta_performer.cc b/delta_performer.cc
index 0c06c8b..bf6972f 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -550,11 +550,11 @@
 
     const bool is_kernel_partition =
         (next_operation_num_ >= num_rootfs_operations_);
-    const DeltaArchiveManifest_InstallOperation &op =
+    const InstallOperation& op =
         is_kernel_partition ?
-        manifest_.kernel_install_operations(
-            next_operation_num_ - num_rootfs_operations_) :
-        manifest_.install_operations(next_operation_num_);
+            manifest_.kernel_install_operations(next_operation_num_ -
+                                                num_rootfs_operations_) :
+            manifest_.install_operations(next_operation_num_);
 
     CopyDataToBuffer(&c_bytes, &count, op.data_length());
 
@@ -591,23 +591,21 @@
         ScopedTerminatorExitUnblocker();  // Avoids a compiler unused var bug.
 
     bool op_result;
-    if (op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE ||
-        op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ)
+    if (op.type() == InstallOperation::REPLACE ||
+        op.type() == InstallOperation::REPLACE_BZ)
       op_result = HandleOpResult(
           PerformReplaceOperation(op, is_kernel_partition), "replace", error);
-    else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE)
+    else if (op.type() == InstallOperation::MOVE)
       op_result = HandleOpResult(
           PerformMoveOperation(op, is_kernel_partition), "move", error);
-    else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_BSDIFF)
+    else if (op.type() == InstallOperation::BSDIFF)
       op_result = HandleOpResult(
           PerformBsdiffOperation(op, is_kernel_partition), "bsdiff", error);
-    else if (op.type() ==
-             DeltaArchiveManifest_InstallOperation_Type_SOURCE_COPY)
+    else if (op.type() == InstallOperation::SOURCE_COPY)
       op_result =
           HandleOpResult(PerformSourceCopyOperation(op, is_kernel_partition),
                          "source_copy", error);
-    else if (op.type() ==
-             DeltaArchiveManifest_InstallOperation_Type_SOURCE_BSDIFF)
+    else if (op.type() == InstallOperation::SOURCE_BSDIFF)
       op_result =
           HandleOpResult(PerformSourceBsdiffOperation(op, is_kernel_partition),
                          "source_bsdiff", error);
@@ -629,13 +627,11 @@
 }
 
 bool DeltaPerformer::CanPerformInstallOperation(
-    const chromeos_update_engine::DeltaArchiveManifest_InstallOperation&
-    operation) {
+    const chromeos_update_engine::InstallOperation& operation) {
   // Move and source_copy operations don't require any data blob, so they can
   // always be performed.
-  if (operation.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE ||
-      operation.type() ==
-          DeltaArchiveManifest_InstallOperation_Type_SOURCE_COPY)
+  if (operation.type() == InstallOperation::MOVE ||
+      operation.type() == InstallOperation::SOURCE_COPY)
     return true;
 
   // See if we have the entire data blob in the buffer
@@ -648,13 +644,10 @@
           buffer_offset_ + buffer_.size());
 }
 
-bool DeltaPerformer::PerformReplaceOperation(
-    const DeltaArchiveManifest_InstallOperation& operation,
-    bool is_kernel_partition) {
-  CHECK(operation.type() == \
-        DeltaArchiveManifest_InstallOperation_Type_REPLACE || \
-        operation.type() == \
-        DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ);
+bool DeltaPerformer::PerformReplaceOperation(const InstallOperation& operation,
+                                             bool is_kernel_partition) {
+  CHECK(operation.type() == InstallOperation::REPLACE ||
+        operation.type() == InstallOperation::REPLACE_BZ);
 
   // Since we delete data off the beginning of the buffer as we use it,
   // the data we need should be exactly at the beginning of the buffer.
@@ -671,10 +664,9 @@
   // Since bzip decompression is optional, we have a variable writer that will
   // point to one of the ExtentWriter objects above.
   ExtentWriter* writer = nullptr;
-  if (operation.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE) {
+  if (operation.type() == InstallOperation::REPLACE) {
     writer = &zero_pad_writer;
-  } else if (operation.type() ==
-             DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ) {
+  } else if (operation.type() == InstallOperation::REPLACE_BZ) {
     bzip_writer.reset(new BzipExtentWriter(&zero_pad_writer));
     writer = bzip_writer.get();
   } else {
@@ -698,9 +690,8 @@
   return true;
 }
 
-bool DeltaPerformer::PerformMoveOperation(
-    const DeltaArchiveManifest_InstallOperation& operation,
-    bool is_kernel_partition) {
+bool DeltaPerformer::PerformMoveOperation(const InstallOperation& operation,
+                                          bool is_kernel_partition) {
   // Calculate buffer size. Note, this function doesn't do a sliding
   // window to copy in case the source and destination blocks overlap.
   // If we wanted to do a sliding window, we could program the server
@@ -777,7 +768,7 @@
 }  // namespace
 
 bool DeltaPerformer::PerformSourceCopyOperation(
-    const DeltaArchiveManifest_InstallOperation& operation,
+    const InstallOperation& operation,
     bool is_kernel_partition) {
   if (operation.has_src_length())
     TEST_AND_RETURN_FALSE(operation.src_length() % block_size_ == 0);
@@ -853,9 +844,8 @@
   return true;
 }
 
-bool DeltaPerformer::PerformBsdiffOperation(
-    const DeltaArchiveManifest_InstallOperation& operation,
-    bool is_kernel_partition) {
+bool DeltaPerformer::PerformBsdiffOperation(const InstallOperation& operation,
+                                            bool is_kernel_partition) {
   // Since we delete data off the beginning of the buffer as we use it,
   // the data we need should be exactly at the beginning of the buffer.
   TEST_AND_RETURN_FALSE(buffer_offset_ == operation.data_offset());
@@ -916,7 +906,7 @@
 }
 
 bool DeltaPerformer::PerformSourceBsdiffOperation(
-    const DeltaArchiveManifest_InstallOperation& operation,
+    const InstallOperation& operation,
     bool is_kernel_partition) {
   // Since we delete data off the beginning of the buffer as we use it,
   // the data we need should be exactly at the beginning of the buffer.
@@ -970,8 +960,8 @@
 }
 
 bool DeltaPerformer::ExtractSignatureMessage(
-    const DeltaArchiveManifest_InstallOperation& operation) {
-  if (operation.type() != DeltaArchiveManifest_InstallOperation_Type_REPLACE ||
+    const InstallOperation& operation) {
+  if (operation.type() != InstallOperation::REPLACE ||
       !manifest_.has_signatures_offset() ||
       manifest_.signatures_offset() != operation.data_offset()) {
     return false;
@@ -1137,8 +1127,7 @@
 }
 
 ErrorCode DeltaPerformer::ValidateOperationHash(
-    const DeltaArchiveManifest_InstallOperation& operation) {
-
+    const InstallOperation& operation) {
   if (!operation.data_sha256_hash().size()) {
     if (!operation.data_length()) {
       // Operations that do not have any data blob won't have any operation hash
@@ -1463,11 +1452,11 @@
     if (next_operation_num_ < num_total_operations_) {
       const bool is_kernel_partition =
           next_operation_num_ >= num_rootfs_operations_;
-      const DeltaArchiveManifest_InstallOperation &op =
-          is_kernel_partition ?
-          manifest_.kernel_install_operations(
-              next_operation_num_ - num_rootfs_operations_) :
-          manifest_.install_operations(next_operation_num_);
+      const InstallOperation& op =
+          is_kernel_partition
+              ? manifest_.kernel_install_operations(next_operation_num_ -
+                                                    num_rootfs_operations_)
+              : manifest_.install_operations(next_operation_num_);
       TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextDataLength,
                                              op.data_length()));
     } else {