url_request_context_storage.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Copyright (c) 2012 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. #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_STORAGE_H_
  5. #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_STORAGE_H_
  6. #include <memory>
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "build/buildflag.h"
  10. #include "net/base/net_export.h"
  11. #include "net/net_buildflags.h"
  12. namespace net {
  13. class CertVerifier;
  14. class CookieStore;
  15. class CTPolicyEnforcer;
  16. class HostResolver;
  17. class HttpAuthHandlerFactory;
  18. class HttpNetworkSession;
  19. class HttpServerProperties;
  20. class HttpTransactionFactory;
  21. class HttpUserAgentSettings;
  22. class NetworkDelegate;
  23. class ProxyDelegate;
  24. class ProxyResolutionService;
  25. class QuicContext;
  26. class SCTAuditingDelegate;
  27. class SSLConfigService;
  28. class TransportSecurityState;
  29. class URLRequestContext;
  30. class ClientSocketFactory;
  31. class URLRequestJobFactory;
  32. class URLRequestThrottlerManager;
  33. #if BUILDFLAG(ENABLE_REPORTING)
  34. class NetworkErrorLoggingService;
  35. class PersistentReportingAndNelStore;
  36. class ReportingService;
  37. #endif // BUILDFLAG(ENABLE_REPORTING)
  38. // URLRequestContextStorage is a helper class that provides storage for unowned
  39. // member variables of URLRequestContext.
  40. class NET_EXPORT URLRequestContextStorage {
  41. public:
  42. // Note that URLRequestContextStorage does not acquire a reference to
  43. // URLRequestContext, since it is often designed to be embedded in a
  44. // URLRequestContext subclass.
  45. explicit URLRequestContextStorage(URLRequestContext* context);
  46. URLRequestContextStorage(const URLRequestContextStorage&) = delete;
  47. URLRequestContextStorage& operator=(const URLRequestContextStorage&) = delete;
  48. ~URLRequestContextStorage();
  49. // These setters will set both the member variables and call the setter on the
  50. // URLRequestContext object. In all cases, ownership is passed to |this|.
  51. void set_host_resolver(std::unique_ptr<HostResolver> host_resolver);
  52. void set_cert_verifier(std::unique_ptr<CertVerifier> cert_verifier);
  53. void set_http_auth_handler_factory(
  54. std::unique_ptr<HttpAuthHandlerFactory> http_auth_handler_factory);
  55. void set_proxy_delegate(std::unique_ptr<ProxyDelegate> proxy_delegate);
  56. void set_network_delegate(std::unique_ptr<NetworkDelegate> network_delegate);
  57. void set_proxy_resolution_service(
  58. std::unique_ptr<ProxyResolutionService> proxy_resolution_service);
  59. void set_ssl_config_service(
  60. std::unique_ptr<SSLConfigService> ssl_config_service);
  61. void set_http_server_properties(
  62. std::unique_ptr<HttpServerProperties> http_server_properties);
  63. void set_cookie_store(std::unique_ptr<CookieStore> cookie_store);
  64. void set_transport_security_state(
  65. std::unique_ptr<TransportSecurityState> transport_security_state);
  66. void set_ct_policy_enforcer(
  67. std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer);
  68. void set_sct_auditing_delegate(
  69. std::unique_ptr<SCTAuditingDelegate> sct_auditing_delegate);
  70. void set_http_network_session(
  71. std::unique_ptr<HttpNetworkSession> http_network_session);
  72. void set_http_transaction_factory(
  73. std::unique_ptr<HttpTransactionFactory> http_transaction_factory);
  74. void set_job_factory(std::unique_ptr<URLRequestJobFactory> job_factory);
  75. void set_throttler_manager(
  76. std::unique_ptr<URLRequestThrottlerManager> throttler_manager);
  77. void set_quic_context(std::unique_ptr<QuicContext> quic_context);
  78. void set_http_user_agent_settings(
  79. std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings);
  80. #if BUILDFLAG(ENABLE_REPORTING)
  81. void set_persistent_reporting_and_nel_store(
  82. std::unique_ptr<PersistentReportingAndNelStore>
  83. persistent_reporting_and_nel_store);
  84. void set_reporting_service(
  85. std::unique_ptr<ReportingService> reporting_service);
  86. void set_network_error_logging_service(
  87. std::unique_ptr<NetworkErrorLoggingService>
  88. network_error_logging_service);
  89. #endif // BUILDFLAG(ENABLE_REPORTING)
  90. void set_client_socket_factory(
  91. std::unique_ptr<ClientSocketFactory> client_socket_factory);
  92. // Everything else can be access through the URLRequestContext, but this
  93. // cannot. Having an accessor for it makes usage a little cleaner.
  94. HttpNetworkSession* http_network_session() const {
  95. return http_network_session_.get();
  96. }
  97. private:
  98. // Not owned.
  99. const raw_ptr<URLRequestContext> context_;
  100. // Owned members.
  101. std::unique_ptr<HostResolver> host_resolver_;
  102. std::unique_ptr<CertVerifier> cert_verifier_;
  103. std::unique_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_;
  104. std::unique_ptr<ProxyDelegate> proxy_delegate_;
  105. std::unique_ptr<NetworkDelegate> network_delegate_;
  106. std::unique_ptr<ProxyResolutionService> proxy_resolution_service_;
  107. std::unique_ptr<SSLConfigService> ssl_config_service_;
  108. std::unique_ptr<HttpServerProperties> http_server_properties_;
  109. std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings_;
  110. std::unique_ptr<CookieStore> cookie_store_;
  111. std::unique_ptr<TransportSecurityState> transport_security_state_;
  112. std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer_;
  113. std::unique_ptr<SCTAuditingDelegate> sct_auditing_delegate_;
  114. std::unique_ptr<QuicContext> quic_context_;
  115. std::unique_ptr<ClientSocketFactory> client_socket_factory_;
  116. // Not actually pointed at by the URLRequestContext, but may be used (but not
  117. // owned) by the HttpTransactionFactory.
  118. std::unique_ptr<HttpNetworkSession> http_network_session_;
  119. std::unique_ptr<HttpTransactionFactory> http_transaction_factory_;
  120. std::unique_ptr<URLRequestJobFactory> job_factory_;
  121. std::unique_ptr<URLRequestThrottlerManager> throttler_manager_;
  122. #if BUILDFLAG(ENABLE_REPORTING)
  123. // Must precede |reporting_service_| and |network_error_logging_service_|
  124. std::unique_ptr<PersistentReportingAndNelStore>
  125. persistent_reporting_and_nel_store_;
  126. std::unique_ptr<ReportingService> reporting_service_;
  127. std::unique_ptr<NetworkErrorLoggingService> network_error_logging_service_;
  128. #endif // BUILDFLAG(ENABLE_REPORTING)
  129. };
  130. } // namespace net
  131. #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_STORAGE_H_