Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Samuel Huang | 577ef6c | 2018-03-13 18:19:34 | [diff] [blame] | 5 | #include "components/zucchini/ensemble_matcher.h" |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 6 | |
Peter Kasting | ccea0983 | 2025-01-27 18:38:22 | [diff] [blame] | 7 | #include <algorithm> |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 8 | #include <limits> |
Andrew Rayskiy | 4384ef7d | 2024-02-28 20:41:58 | [diff] [blame] | 9 | #include <vector> |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 10 | |
| 11 | #include "base/logging.h" |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 12 | |
| 13 | namespace zucchini { |
| 14 | |
| 15 | /******** EnsembleMatcher ********/ |
| 16 | |
| 17 | EnsembleMatcher::EnsembleMatcher() = default; |
| 18 | |
| 19 | EnsembleMatcher::~EnsembleMatcher() = default; |
| 20 | |
| 21 | void EnsembleMatcher::Trim() { |
Etienne Pierre-Doray | d214e2c | 2018-03-29 13:33:46 | [diff] [blame] | 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 | }; |
Peter Kasting | ccea0983 | 2025-01-27 18:38:22 | [diff] [blame] | 30 | auto num_dex = std::ranges::count_if(matches_, is_match_dex); |
Etienne Pierre-Doray | d214e2c | 2018-03-29 13:33:46 | [diff] [blame] | 31 | if (num_dex > 1) { |
| 32 | LOG(WARNING) << "Found " << num_dex << " DEX: Ignoring all."; |
Andrew Rayskiy | 4384ef7d | 2024-02-28 20:41:58 | [diff] [blame] | 33 | std::erase_if(matches_, is_match_dex); |
Etienne Pierre-Doray | d214e2c | 2018-03-29 13:33:46 | [diff] [blame] | 34 | } |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 35 | } |
| 36 | |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 37 | } // namespace zucchini |