component_updater_utils.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2021 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/component_updater/component_updater_utils.h"
  5. #include <string>
  6. #include <vector>
  7. #include "base/containers/flat_map.h"
  8. #include "components/component_updater/component_updater_service.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace component_updater {
  11. absl::optional<ComponentRegistration> GetComponent(
  12. const base::flat_map<std::string, ComponentRegistration>& components,
  13. const std::string& id) {
  14. const auto it = components.find(id);
  15. if (it != components.end())
  16. return it->second;
  17. return absl::nullopt;
  18. }
  19. std::vector<absl::optional<ComponentRegistration>> GetCrxComponents(
  20. const base::flat_map<std::string, ComponentRegistration>&
  21. registered_components,
  22. const std::vector<std::string>& ids) {
  23. std::vector<absl::optional<ComponentRegistration>> components;
  24. for (const auto& id : ids)
  25. components.push_back(GetComponent(registered_components, id));
  26. return components;
  27. }
  28. } // namespace component_updater