blob: 37a7af9f3284fcb297b44d70e3083211229de09b [file] [log] [blame]
Samuel Huangfdb2f3a2017-12-20 17:45:141// 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 Huang577ef6c2018-03-13 18:19:345#include "components/zucchini/ensemble_matcher.h"
Samuel Huangfdb2f3a2017-12-20 17:45:146
Etienne Pierre-Dorayd214e2c2018-03-29 13:33:467#include <algorithm>
Samuel Huangfdb2f3a2017-12-20 17:45:148#include <limits>
Samuel Huangfdb2f3a2017-12-20 17:45:149
10#include "base/logging.h"
11#include "base/strings/stringprintf.h"
12
13namespace zucchini {
14
15/******** EnsembleMatcher ********/
16
17EnsembleMatcher::EnsembleMatcher() = default;
18
19EnsembleMatcher::~EnsembleMatcher() = default;
20
21void EnsembleMatcher::Trim() {
Etienne Pierre-Dorayd214e2c2018-03-29 13:33:4622 // 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 Huangfdb2f3a2017-12-20 17:45:1437}
38
Samuel Huangfdb2f3a2017-12-20 17:45:1439} // namespace zucchini