update_engine: Adds BROTLI_BSDIFF operation

Brotli compression creates on average 10%-20% smaller output than bzip2
in addition to having faster decompressor. With recent changes in bsdiff
to compress the its patch with brotli, we can use it in the
update_engine as a new operation BROTLI_BSDIFF. This operation will be
turned on in minor version 4. However, this CL only adds support for it
in the client. It will not generate BROTLI_BSDIFF operations yet.

BUG=chromium:783437
TEST=unittests pass for both update_engine and update_payload;
'brillo_update_payload {generate|verify}' passes;
'scripts/paycheck.py payload.delta' passes;

Change-Id: Ie791ba5431561c95de6fbc031a8196dbfd912288
Reviewed-on: https://chromium-review.googlesource.com/764791
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/delta_performer.cc b/payload_consumer/delta_performer.cc
index c3fd411..95cc390 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -768,6 +768,7 @@
         OP_DURATION_HISTOGRAM("SOURCE_COPY", op_start_time);
         break;
       case InstallOperation::SOURCE_BSDIFF:
+      case InstallOperation::BROTLI_BSDIFF:
         op_result = PerformSourceBsdiffOperation(op, error);
         OP_DURATION_HISTOGRAM("SOURCE_BSDIFF", op_start_time);
         break;
@@ -1226,15 +1227,17 @@
   }
 
   string input_positions;
-  TEST_AND_RETURN_FALSE(ExtentsToBsdiffPositionsString(operation.src_extents(),
-                                                       block_size_,
-                                                       operation.src_length(),
-                                                       &input_positions));
+  TEST_AND_RETURN_FALSE(ExtentsToBsdiffPositionsString(
+      operation.src_extents(),
+      block_size_,
+      utils::BlocksInExtents(operation.src_extents()) * block_size_,
+      &input_positions));
   string output_positions;
-  TEST_AND_RETURN_FALSE(ExtentsToBsdiffPositionsString(operation.dst_extents(),
-                                                       block_size_,
-                                                       operation.dst_length(),
-                                                       &output_positions));
+  TEST_AND_RETURN_FALSE(ExtentsToBsdiffPositionsString(
+      operation.dst_extents(),
+      block_size_,
+      utils::BlocksInExtents(operation.dst_extents()) * block_size_,
+      &output_positions));
 
   TEST_AND_RETURN_FALSE(bsdiff::bspatch(source_path_.c_str(),
                                         target_path_.c_str(),