command_line_top_host_provider.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019 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/optimization_guide/core/command_line_top_host_provider.h"
  5. #include "base/memory/ptr_util.h"
  6. #include "components/optimization_guide/core/optimization_guide_switches.h"
  7. #include "third_party/abseil-cpp/absl/types/optional.h"
  8. namespace optimization_guide {
  9. // static
  10. std::unique_ptr<CommandLineTopHostProvider>
  11. CommandLineTopHostProvider::CreateIfEnabled() {
  12. absl::optional<std::vector<std::string>> top_hosts =
  13. switches::ParseHintsFetchOverrideFromCommandLine();
  14. if (top_hosts) {
  15. // Note: wrap_unique is used because the constructor is private.
  16. return base::WrapUnique(new CommandLineTopHostProvider(*top_hosts));
  17. }
  18. return nullptr;
  19. }
  20. CommandLineTopHostProvider::CommandLineTopHostProvider(
  21. const std::vector<std::string>& top_hosts)
  22. : top_hosts_(top_hosts) {}
  23. CommandLineTopHostProvider::~CommandLineTopHostProvider() = default;
  24. std::vector<std::string> CommandLineTopHostProvider::GetTopHosts() {
  25. return top_hosts_;
  26. }
  27. } // namespace optimization_guide