1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_ZUCCHINI_ZUCCHINI_GEN_H_ 6 #define COMPONENTS_ZUCCHINI_ZUCCHINI_GEN_H_ 7 8 #include <vector> 9 10 #include "components/zucchini/buffer_view.h" 11 #include "components/zucchini/image_utils.h" 12 #include "components/zucchini/zucchini.h" 13 14 namespace zucchini { 15 16 class EquivalenceMap; 17 class OffsetMapper; 18 class ImageIndex; 19 class PatchElementWriter; 20 class ReferenceBytesMixer; 21 class ReferenceDeltaSink; 22 class ReferenceSet; 23 class TargetPool; 24 25 // Extract all targets in |new_targets| with no associated target in 26 // |projected_old_targets| and returns these targets in a new vector. 27 std::vector<offset_t> FindExtraTargets(const TargetPool& projected_old_targets, 28 const TargetPool& new_targets); 29 30 // Creates an EquivalenceMap from "old" image to "new" image and returns the 31 // result. The params |*_image_index|: 32 // - Provide "old" and "new" raw image data and references. 33 // - Mediate Label matching, which links references between "old" and "new", and 34 // guides EquivalenceMap construction. 35 EquivalenceMap CreateEquivalenceMap(const ImageIndex& old_image_index, 36 const ImageIndex& new_image_index); 37 38 // Writes equivalences from |equivalence_map|, and extra data from |new_image| 39 // found in gaps between equivalences to |patch_writer|. 40 bool GenerateEquivalencesAndExtraData(ConstBufferView new_image, 41 const EquivalenceMap& equivalence_map, 42 PatchElementWriter* patch_writer); 43 44 // Writes raw delta between |old_image| and |new_image| matched by 45 // |equivalence_map| to |patch_writer|, using |new_image_index| to ignore 46 // reference bytes. 47 bool GenerateRawDelta(ConstBufferView old_image, 48 ConstBufferView new_image, 49 const EquivalenceMap& equivalence_map, 50 const ImageIndex& new_image_index, 51 ReferenceBytesMixer* reference_bytes_mixer, 52 PatchElementWriter* patch_writer); 53 54 // Writes reference delta between references from |old_refs| and from 55 // |new_refs| to |patch_writer|. |projected_target_pool| contains projected 56 // targets from old to new image for references pool associated with |new_refs|. 57 bool GenerateReferencesDelta(const ReferenceSet& src_refs, 58 const ReferenceSet& dst_refs, 59 const TargetPool& projected_target_pool, 60 const OffsetMapper& offset_mapper, 61 const EquivalenceMap& equivalence_map, 62 ReferenceDeltaSink* reference_delta_sink); 63 64 // Writes |extra_targets| associated with |pool_tag| to |patch_writer|. 65 bool GenerateExtraTargets(const std::vector<offset_t>& extra_targets, 66 PoolTag pool_tag, 67 PatchElementWriter* patch_writer); 68 69 // Generates raw patch element data between |old_image| and |new_image|, and 70 // writes them to |patch_writer|. |old_sa| is the suffix array for |old_image|. 71 bool GenerateRawElement(const std::vector<offset_t>& old_sa, 72 ConstBufferView old_image, 73 ConstBufferView new_image, 74 PatchElementWriter* patch_writer); 75 76 // Generates patch element of type |exe_type| from |old_image| to |new_image|, 77 // and writes it to |patch_writer|. 78 bool GenerateExecutableElement(ExecutableType exe_type, 79 ConstBufferView old_image, 80 ConstBufferView new_image, 81 PatchElementWriter* patch_writer); 82 83 } // namespace zucchini 84 85 #endif // COMPONENTS_ZUCCHINI_ZUCCHINI_GEN_H_ 86