ensemble_matcher.cc 1.2 KB

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