Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 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 | |
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 | |
Etienne Pierre-Doray | d214e2c | 2018-03-29 13:33:46 | [diff] [blame^] | 7 | #include <algorithm> |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 8 | #include <limits> |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 9 | |
| 10 | #include "base/logging.h" |
| 11 | #include "base/strings/stringprintf.h" |
| 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 | }; |
| 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 | matches_.erase( |
| 34 | std::remove_if(matches_.begin(), matches_.end(), is_match_dex), |
| 35 | matches_.end()); |
| 36 | } |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 37 | } |
| 38 | |
Samuel Huang | fdb2f3a | 2017-12-20 17:45:14 | [diff] [blame] | 39 | } // namespace zucchini |