xref: /aosp_15_r20/external/zucchini/ensemble_matcher.cc (revision a03ca8b91e029cd15055c20c78c2e087c84792e4)
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 #include "components/zucchini/ensemble_matcher.h"
6 
7 #include <algorithm>
8 #include <limits>
9 
10 #include "base/containers/cxx20_erase.h"
11 #include "base/logging.h"
12 
13 namespace zucchini {
14 
15 /******** EnsembleMatcher ********/
16 
17 EnsembleMatcher::EnsembleMatcher() = default;
18 
19 EnsembleMatcher::~EnsembleMatcher() = default;
20 
Trim()21 void EnsembleMatcher::Trim() {
22   // Trim rule: If > 1 DEX files are found then ignore all DEX. This is done
23   // because we do not yet support MultiDex, under which contents can move
24   // across file boundary between "old" and "new" archives. When this occurs,
25   // forcing matches of DEX files and patching them separately can result in
26   // larger patches than naive patching.
27   auto is_match_dex = [](const ElementMatch& match) {
28     return match.exe_type() == kExeTypeDex;
29   };
30   auto num_dex = std::count_if(matches_.begin(), matches_.end(), is_match_dex);
31   if (num_dex > 1) {
32     LOG(WARNING) << "Found " << num_dex << " DEX: Ignoring all.";
33     base::EraseIf(matches_, is_match_dex);
34   }
35 }
36 
37 }  // namespace zucchini
38