cronet_global_state_stubs.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2018 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/cronet/cronet_global_state.h"
  5. #include <tuple>
  6. #include "base/at_exit.h"
  7. #include "base/feature_list.h"
  8. #include "base/task/thread_pool.h"
  9. #include "base/task/thread_pool/thread_pool_instance.h"
  10. #include "net/proxy_resolution/configured_proxy_resolution_service.h"
  11. #include "net/proxy_resolution/proxy_config_service.h"
  12. // This file provides minimal "stub" implementations of the Cronet global-state
  13. // functions for the native library build, sufficient to have cronet_tests and
  14. // cronet_unittests build.
  15. namespace cronet {
  16. namespace {
  17. scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner() {
  18. // Cronet tests sets AtExitManager as part of TestSuite, so statically linked
  19. // library is not allowed to set its own.
  20. #if !defined(CRONET_TESTS_IMPLEMENTATION)
  21. std::ignore = new base::AtExitManager;
  22. #endif
  23. base::FeatureList::InitializeInstance(std::string(), std::string());
  24. // Note that in component builds this ThreadPoolInstance will be shared with
  25. // the calling process, if it also depends on //base. In particular this means
  26. // that the Cronet test binaries must avoid initializing or shutting-down the
  27. // ThreadPoolInstance themselves.
  28. base::ThreadPoolInstance::CreateAndStartWithDefaultParams("cronet");
  29. return base::ThreadPool::CreateSingleThreadTaskRunner({});
  30. }
  31. base::SingleThreadTaskRunner* InitTaskRunner() {
  32. static scoped_refptr<base::SingleThreadTaskRunner> init_task_runner =
  33. InitializeAndCreateTaskRunner();
  34. return init_task_runner.get();
  35. }
  36. } // namespace
  37. void EnsureInitialized() {
  38. std::ignore = InitTaskRunner();
  39. }
  40. bool OnInitThread() {
  41. return InitTaskRunner()->BelongsToCurrentThread();
  42. }
  43. void PostTaskToInitThread(const base::Location& posted_from,
  44. base::OnceClosure task) {
  45. InitTaskRunner()->PostTask(posted_from, std::move(task));
  46. }
  47. std::unique_ptr<net::ProxyConfigService> CreateProxyConfigService(
  48. const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) {
  49. return net::ProxyConfigService::CreateSystemProxyConfigService(
  50. io_task_runner);
  51. }
  52. std::unique_ptr<net::ProxyResolutionService> CreateProxyResolutionService(
  53. std::unique_ptr<net::ProxyConfigService> proxy_config_service,
  54. net::NetLog* net_log) {
  55. return net::ConfiguredProxyResolutionService::CreateUsingSystemProxyResolver(
  56. std::move(proxy_config_service), net_log, /*quick_check_enabled=*/true);
  57. }
  58. std::string CreateDefaultUserAgent(const std::string& partial_user_agent) {
  59. return partial_user_agent;
  60. }
  61. void SetNetworkThreadPriorityOnNetworkThread(double priority) {
  62. NOTIMPLEMENTED();
  63. }
  64. } // namespace cronet