Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: components/cronet/ios/cronet_environment.h

Issue 2146643002: [Cronet] Integrate CrNet functionality into Cronet on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify TestServer. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ 5 #ifndef COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_
6 #define COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ 6 #define COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "components/cronet/url_request_context_config.h" 17 #include "components/cronet/url_request_context_config.h"
17 #include "net/cert/cert_verifier.h" 18 #include "net/cert/cert_verifier.h"
18 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_context_getter.h"
20 22
21 class JsonPrefStore; 23 class JsonPrefStore;
22 24
23 namespace base { 25 namespace base {
24 class WaitableEvent; 26 class WaitableEvent;
25 } // namespace base 27 } // namespace base
26 28
27 namespace net { 29 namespace net {
28 class HttpCache; 30 class HttpCache;
29 class NetworkChangeNotifier; 31 class NetworkChangeNotifier;
30 class NetLog; 32 class NetLog;
31 class ProxyConfigService; 33 class ProxyConfigService;
32 class WriteToFileNetLogObserver; 34 class WriteToFileNetLogObserver;
33 } // namespace net 35 } // namespace net
34 36
35 namespace cronet { 37 namespace cronet {
36 // CronetEnvironment contains all the network stack configuration 38 // CronetEnvironment contains all the network stack configuration
37 // and initialization. 39 // and initialization.
38 class CronetEnvironment { 40 class CronetEnvironment {
39 public: 41 public:
40 // Initialize Cronet environment globals. Must be called only once on the 42 // Initialize Cronet environment globals. Must be called only once on the
41 // main thread. 43 // main thread.
42 static void Initialize(); 44 static void Initialize();
43 45
44 // |user_agent_product_name| will be used to generate the user-agent. 46 // |user_agent| will be used to generate the user-agent if
45 CronetEnvironment(const std::string& user_agent_product_name); 47 // |user_agent_partial|
48 // is true, or will be used as complete user-agent otherwise.
49 CronetEnvironment(const std::string& user_agent, bool user_agent_partial);
46 ~CronetEnvironment(); 50 ~CronetEnvironment();
47 51
48 // Starts this instance of Cronet environment. 52 // Starts this instance of Cronet environment.
49 void Start(); 53 void Start();
50 54
51 // The full user-agent. 55 // The full user-agent.
52 std::string user_agent(); 56 std::string user_agent();
53 57
58 // Get global UMA histogram deltas.
59 std::vector<uint8_t> GetHistogramDeltas();
60
54 // Creates a new net log (overwrites existing file with this name). If 61 // Creates a new net log (overwrites existing file with this name). If
55 // actively logging, this call is ignored. 62 // actively logging, this call is ignored.
56 void StartNetLog(base::FilePath::StringType file_name, bool log_bytes); 63 void StartNetLog(base::FilePath::StringType file_name, bool log_bytes);
57 // Stops logging and flushes file. If not currently logging this call is 64 // Stops logging and flushes file. If not currently logging this call is
58 // ignored. 65 // ignored.
59 void StopNetLog(); 66 void StopNetLog();
60 67
61 void AddQuicHint(const std::string& host, int port, int alternate_port); 68 void AddQuicHint(const std::string& host, int port, int alternate_port);
62 69
63 // Setters and getters for |http2_enabled_|, |quic_enabled_|, and 70 // Setters and getters for |http2_enabled_|, |quic_enabled_|, and
64 // |forced_quic_origin_|. These only have any effect before Start() is 71 // |forced_quic_origin_|. These only have any effect before Start() is
65 // called. 72 // called.
66 void set_http2_enabled(bool enabled) { http2_enabled_ = enabled; } 73 void set_http2_enabled(bool enabled) { http2_enabled_ = enabled; }
67 void set_quic_enabled(bool enabled) { quic_enabled_ = enabled; } 74 void set_quic_enabled(bool enabled) { quic_enabled_ = enabled; }
68 75
69 bool http2_enabled() const { return http2_enabled_; } 76 bool http2_enabled() const { return http2_enabled_; }
70 bool quic_enabled() const { return quic_enabled_; } 77 bool quic_enabled() const { return quic_enabled_; }
71 78
79 void set_accept_language(const std::string& accept_language) {
80 accept_language_ = accept_language;
81 }
82
72 void set_cert_verifier(std::unique_ptr<net::CertVerifier> cert_verifier) { 83 void set_cert_verifier(std::unique_ptr<net::CertVerifier> cert_verifier) {
73 cert_verifier_ = std::move(cert_verifier); 84 cert_verifier_ = std::move(cert_verifier);
74 } 85 }
75 86
76 void set_host_resolver_rules(const std::string& host_resolver_rules) { 87 void set_host_resolver_rules(const std::string& host_resolver_rules) {
77 host_resolver_rules_ = host_resolver_rules; 88 host_resolver_rules_ = host_resolver_rules;
78 } 89 }
79 90
80 void set_ssl_key_log_file_name(const std::string& ssl_key_log_file_name) { 91 void set_ssl_key_log_file_name(const std::string& ssl_key_log_file_name) {
81 ssl_key_log_file_name_ = ssl_key_log_file_name; 92 ssl_key_log_file_name_ = ssl_key_log_file_name;
82 } 93 }
83 94
84 net::URLRequestContext* GetURLRequestContext() const; 95 net::URLRequestContext* GetURLRequestContext() const;
85 96
97 net::URLRequestContextGetter* GetURLRequestContextGetter() const;
98
86 bool IsOnNetworkThread(); 99 bool IsOnNetworkThread();
87 100
88 // Runs a closure on the network thread. 101 // Runs a closure on the network thread.
89 void PostToNetworkThread(const tracked_objects::Location& from_here, 102 void PostToNetworkThread(const tracked_objects::Location& from_here,
90 const base::Closure& task); 103 const base::Closure& task);
91 104
92 private: 105 private:
93 // Performs initialization tasks that must happen on the network thread. 106 // Performs initialization tasks that must happen on the network thread.
94 void InitializeOnNetworkThread(); 107 void InitializeOnNetworkThread();
95 108
96 // Runs a closure on the file user blocking thread. 109 // Runs a closure on the file user blocking thread.
97 void PostToFileUserBlockingThread(const tracked_objects::Location& from_here, 110 void PostToFileUserBlockingThread(const tracked_objects::Location& from_here,
98 const base::Closure& task); 111 const base::Closure& task);
99 112
100 // Helper methods that start/stop net logging on the network thread. 113 // Helper methods that start/stop net logging on the network thread.
101 void StartNetLogOnNetworkThread(const base::FilePath::StringType& file_name, 114 void StartNetLogOnNetworkThread(const base::FilePath::StringType& file_name,
102 bool log_bytes); 115 bool log_bytes);
103 void StopNetLogOnNetworkThread(base::WaitableEvent* log_stopped_event); 116 void StopNetLogOnNetworkThread(base::WaitableEvent* log_stopped_event);
104 117
105 // Returns the HttpNetworkSession object from the passed in 118 // Returns the HttpNetworkSession object from the passed in
106 // URLRequestContext or NULL if none exists. 119 // URLRequestContext or NULL if none exists.
107 net::HttpNetworkSession* GetHttpNetworkSession( 120 net::HttpNetworkSession* GetHttpNetworkSession(
108 net::URLRequestContext* context); 121 net::URLRequestContext* context);
109 122
110 bool http2_enabled_; 123 bool http2_enabled_;
111 bool quic_enabled_; 124 bool quic_enabled_;
125 std::string accept_language_;
112 std::string host_resolver_rules_; 126 std::string host_resolver_rules_;
113 std::string ssl_key_log_file_name_; 127 std::string ssl_key_log_file_name_;
114 128
115 std::list<net::HostPortPair> quic_hints_; 129 std::list<net::HostPortPair> quic_hints_;
116 130
117 std::unique_ptr<base::Thread> network_io_thread_; 131 std::unique_ptr<base::Thread> network_io_thread_;
118 std::unique_ptr<base::Thread> network_cache_thread_; 132 std::unique_ptr<base::Thread> network_cache_thread_;
119 std::unique_ptr<base::Thread> file_thread_; 133 std::unique_ptr<base::Thread> file_thread_;
120 std::unique_ptr<base::Thread> file_user_blocking_thread_; 134 std::unique_ptr<base::Thread> file_user_blocking_thread_;
121 scoped_refptr<base::SequencedTaskRunner> pref_store_worker_pool_; 135 scoped_refptr<base::SequencedTaskRunner> pref_store_worker_pool_;
122 scoped_refptr<JsonPrefStore> net_pref_store_; 136 scoped_refptr<JsonPrefStore> net_pref_store_;
123 std::unique_ptr<net::CertVerifier> cert_verifier_; 137 std::unique_ptr<net::CertVerifier> cert_verifier_;
124 std::unique_ptr<net::ProxyConfigService> proxy_config_service_; 138 std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
125 std::unique_ptr<net::HttpServerProperties> http_server_properties_; 139 std::unique_ptr<net::HttpServerProperties> http_server_properties_;
126 std::unique_ptr<net::URLRequestContext> main_context_; 140 std::unique_ptr<net::URLRequestContext> main_context_;
127 std::string user_agent_product_name_; 141 scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
142 std::string user_agent_;
143 bool user_agent_partial_;
128 std::unique_ptr<net::NetLog> net_log_; 144 std::unique_ptr<net::NetLog> net_log_;
129 std::unique_ptr<net::WriteToFileNetLogObserver> net_log_observer_; 145 std::unique_ptr<net::WriteToFileNetLogObserver> net_log_observer_;
130 146
131 DISALLOW_COPY_AND_ASSIGN(CronetEnvironment); 147 DISALLOW_COPY_AND_ASSIGN(CronetEnvironment);
132 }; 148 };
133 149
134 } // namespace cronet 150 } // namespace cronet
135 151
136 #endif // COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_ 152 #endif // COMPONENTS_CRONET_IOS_CRONET_ENVIRONMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698