OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
6 #define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 6 #define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr
ics.h" | 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr
ics.h" |
17 #include "net/base/network_delegate.h" | 17 #include "net/base/network_delegate_impl.h" |
18 #include "net/proxy/proxy_retry_info.h" | |
19 | 18 |
20 class ChromeExtensionsNetworkDelegate; | 19 class ChromeExtensionsNetworkDelegate; |
21 class ClientHints; | 20 class ClientHints; |
22 class CookieSettings; | 21 class CookieSettings; |
23 class PrefService; | 22 class PrefService; |
24 | 23 |
25 template<class T> class PrefMember; | 24 template<class T> class PrefMember; |
26 | 25 |
27 typedef PrefMember<bool> BooleanPrefMember; | 26 typedef PrefMember<bool> BooleanPrefMember; |
28 | 27 |
29 namespace base { | 28 namespace base { |
30 class Value; | 29 class Value; |
31 } | 30 } |
32 | 31 |
33 namespace chrome_browser_net { | 32 namespace chrome_browser_net { |
34 class ConnectInterceptor; | 33 class ConnectInterceptor; |
35 class Predictor; | 34 class Predictor; |
36 } | 35 } |
37 | 36 |
38 namespace data_reduction_proxy { | |
39 class DataReductionProxyAuthRequestHandler; | |
40 class DataReductionProxyParams; | |
41 class DataReductionProxyStatisticsPrefs; | |
42 class DataReductionProxyUsageStats; | |
43 } | |
44 | |
45 namespace domain_reliability { | 37 namespace domain_reliability { |
46 class DomainReliabilityMonitor; | 38 class DomainReliabilityMonitor; |
47 } | 39 } |
48 | 40 |
49 namespace extensions { | 41 namespace extensions { |
50 class EventRouterForwarder; | 42 class EventRouterForwarder; |
51 class InfoMap; | 43 class InfoMap; |
52 } | 44 } |
53 | 45 |
54 namespace net { | 46 namespace net { |
55 class ProxyConfig; | |
56 class ProxyInfo; | |
57 class ProxyServer; | |
58 class ProxyService; | |
59 class URLRequest; | 47 class URLRequest; |
60 } | 48 } |
61 | 49 |
62 namespace policy { | 50 namespace policy { |
63 class URLBlacklistManager; | 51 class URLBlacklistManager; |
64 } | 52 } |
65 | 53 |
66 namespace prerender { | 54 namespace prerender { |
67 class PrerenderTracker; | 55 class PrerenderTracker; |
68 } | 56 } |
69 | 57 |
70 // ChromeNetworkDelegate is the central point from within the chrome code to | 58 // ChromeNetworkDelegate is the central point from within the chrome code to |
71 // add hooks into the network stack. | 59 // add hooks into the network stack. |
72 class ChromeNetworkDelegate : public net::NetworkDelegate { | 60 class ChromeNetworkDelegate : public net::NetworkDelegateImpl { |
73 public: | 61 public: |
74 // Provides an opportunity to interpose on proxy resolution. Called before | |
75 // ProxyService.ResolveProxy() returns. Two proxy configurations are provided | |
76 // that specify the data reduction proxy's configuration and the effective | |
77 // configuration according to the proxy service, respectively. Retry info is | |
78 // presumed to be from the proxy service. | |
79 typedef base::Callback<void( | |
80 const GURL& url, | |
81 int load_flags, | |
82 const net::ProxyConfig& data_reduction_proxy_config, | |
83 const net::ProxyConfig& proxy_service_proxy_config, | |
84 const net::ProxyRetryInfoMap& proxy_retry_info_map, | |
85 const data_reduction_proxy::DataReductionProxyParams* params, | |
86 net::ProxyInfo* result)> OnResolveProxyHandler; | |
87 | |
88 // Provides an additional proxy configuration that can be consulted after | |
89 // proxy resolution. | |
90 typedef base::Callback<const net::ProxyConfig&()> ProxyConfigGetter; | |
91 | |
92 // |enable_referrers| (and all of the other optional PrefMembers) should be | 62 // |enable_referrers| (and all of the other optional PrefMembers) should be |
93 // initialized on the UI thread (see below) beforehand. This object's owner is | 63 // initialized on the UI thread (see below) beforehand. This object's owner is |
94 // responsible for cleaning them up at shutdown. | 64 // responsible for cleaning them up at shutdown. |
95 ChromeNetworkDelegate(extensions::EventRouterForwarder* event_router, | 65 ChromeNetworkDelegate(extensions::EventRouterForwarder* event_router, |
96 BooleanPrefMember* enable_referrers); | 66 BooleanPrefMember* enable_referrers); |
97 ~ChromeNetworkDelegate() override; | 67 ~ChromeNetworkDelegate() override; |
98 | 68 |
99 // Pass through to ChromeExtensionsNetworkDelegate::set_extension_info_map(). | 69 // Pass through to ChromeExtensionsNetworkDelegate::set_extension_info_map(). |
100 void set_extension_info_map(extensions::InfoMap* extension_info_map); | 70 void set_extension_info_map(extensions::InfoMap* extension_info_map); |
101 | 71 |
(...skipping 27 matching lines...) Expand all Loading... |
129 | 99 |
130 void set_enable_do_not_track(BooleanPrefMember* enable_do_not_track) { | 100 void set_enable_do_not_track(BooleanPrefMember* enable_do_not_track) { |
131 enable_do_not_track_ = enable_do_not_track; | 101 enable_do_not_track_ = enable_do_not_track; |
132 } | 102 } |
133 | 103 |
134 void set_force_google_safe_search( | 104 void set_force_google_safe_search( |
135 BooleanPrefMember* force_google_safe_search) { | 105 BooleanPrefMember* force_google_safe_search) { |
136 force_google_safe_search_ = force_google_safe_search; | 106 force_google_safe_search_ = force_google_safe_search; |
137 } | 107 } |
138 | 108 |
139 void set_data_reduction_proxy_enabled_pref( | |
140 BooleanPrefMember* data_reduction_proxy_enabled) { | |
141 data_reduction_proxy_enabled_ = data_reduction_proxy_enabled; | |
142 } | |
143 | |
144 void set_domain_reliability_monitor( | 109 void set_domain_reliability_monitor( |
145 domain_reliability::DomainReliabilityMonitor* monitor) { | 110 domain_reliability::DomainReliabilityMonitor* monitor) { |
146 domain_reliability_monitor_ = monitor; | 111 domain_reliability_monitor_ = monitor; |
147 } | 112 } |
148 | 113 |
149 void set_prerender_tracker(prerender::PrerenderTracker* prerender_tracker) { | 114 void set_prerender_tracker(prerender::PrerenderTracker* prerender_tracker) { |
150 prerender_tracker_ = prerender_tracker; | 115 prerender_tracker_ = prerender_tracker; |
151 } | 116 } |
152 | 117 |
153 // |data_reduction_proxy_params_| must outlive this ChromeNetworkDelegate. | |
154 void set_data_reduction_proxy_params( | |
155 data_reduction_proxy::DataReductionProxyParams* params) { | |
156 data_reduction_proxy_params_ = params; | |
157 } | |
158 | |
159 // |data_reduction_proxy_usage_stats_| must outlive this | |
160 // ChromeNetworkDelegate. | |
161 void set_data_reduction_proxy_usage_stats( | |
162 data_reduction_proxy::DataReductionProxyUsageStats* usage_stats) { | |
163 data_reduction_proxy_usage_stats_ = usage_stats; | |
164 } | |
165 | |
166 // |data_reduction_proxy_auth_request_handler_| must outlive this | |
167 // ChromeNetworkDelegate. | |
168 void set_data_reduction_proxy_auth_request_handler( | |
169 data_reduction_proxy::DataReductionProxyAuthRequestHandler* handler) { | |
170 data_reduction_proxy_auth_request_handler_ = handler; | |
171 } | |
172 | |
173 // |data_reduction_proxy_statistics_prefs_| must outlive this | |
174 // ChromeNetworkDelegate. | |
175 void set_data_reduction_proxy_statistics_prefs( | |
176 data_reduction_proxy::DataReductionProxyStatisticsPrefs* | |
177 statistics_prefs) { | |
178 data_reduction_proxy_statistics_prefs_ = statistics_prefs; | |
179 } | |
180 | |
181 void set_on_resolve_proxy_handler(OnResolveProxyHandler handler) { | |
182 on_resolve_proxy_handler_ = handler; | |
183 } | |
184 | |
185 void set_proxy_config_getter(const ProxyConfigGetter& getter) { | |
186 proxy_config_getter_ = getter; | |
187 } | |
188 | |
189 // Adds the Client Hints header to HTTP requests. | 118 // Adds the Client Hints header to HTTP requests. |
190 void SetEnableClientHints(); | 119 void SetEnableClientHints(); |
191 | 120 |
192 // Causes |OnCanThrottleRequest| to always return false, for all | 121 // Causes |OnCanThrottleRequest| to always return false, for all |
193 // instances of this object. | 122 // instances of this object. |
194 static void NeverThrottleRequests(); | 123 static void NeverThrottleRequests(); |
195 | 124 |
196 // Binds the pref members to |pref_service| and moves them to the IO thread. | 125 // Binds the pref members to |pref_service| and moves them to the IO thread. |
197 // |enable_referrers| cannot be NULL, the others can. | 126 // |enable_referrers| cannot be NULL, the others can. |
198 // This method should be called on the UI thread. | 127 // This method should be called on the UI thread. |
199 static void InitializePrefsOnUIThread( | 128 static void InitializePrefsOnUIThread( |
200 BooleanPrefMember* enable_referrers, | 129 BooleanPrefMember* enable_referrers, |
201 BooleanPrefMember* enable_do_not_track, | 130 BooleanPrefMember* enable_do_not_track, |
202 BooleanPrefMember* force_google_safe_search, | 131 BooleanPrefMember* force_google_safe_search, |
203 PrefService* pref_service); | 132 PrefService* pref_service); |
204 | 133 |
205 // When called, all file:// URLs will now be accessible. If this is not | 134 // When called, all file:// URLs will now be accessible. If this is not |
206 // called, then some platforms restrict access to file:// paths. | 135 // called, then some platforms restrict access to file:// paths. |
207 static void AllowAccessToAllFiles(); | 136 static void AllowAccessToAllFiles(); |
208 | 137 |
209 // Creates a Value summary of the persistent state of the network session. | 138 // // Creates a Value summary of the persistent state of the network session. |
210 // The caller is responsible for deleting the returned value. | 139 // // The caller is responsible for deleting the returned value. |
211 // Must be called on the UI thread. | 140 // // Must be called on the UI thread. |
212 static base::Value* HistoricNetworkStatsInfoToValue(PrefService* prefs); | 141 // static base::Value* HistoricNetworkStatsInfoToValue(PrefService* prefs); |
213 | |
214 // Creates a Value summary of the state of the network session. The caller is | |
215 // responsible for deleting the returned value. | |
216 base::Value* SessionNetworkStatsInfoToValue() const; | |
217 | 142 |
218 private: | 143 private: |
219 friend class ChromeNetworkDelegateTest; | 144 friend class ChromeNetworkDelegateTest; |
220 | 145 |
221 // NetworkDelegate implementation. | 146 // NetworkDelegate implementation. |
222 int OnBeforeURLRequest(net::URLRequest* request, | 147 int OnBeforeURLRequest(net::URLRequest* request, |
223 const net::CompletionCallback& callback, | 148 const net::CompletionCallback& callback, |
224 GURL* new_url) override; | 149 GURL* new_url) override; |
225 void OnResolveProxy(const GURL& url, | |
226 int load_flags, | |
227 const net::ProxyService& proxy_service, | |
228 net::ProxyInfo* result) override; | |
229 void OnProxyFallback(const net::ProxyServer& bad_proxy, | |
230 int net_error) override; | |
231 int OnBeforeSendHeaders(net::URLRequest* request, | 150 int OnBeforeSendHeaders(net::URLRequest* request, |
232 const net::CompletionCallback& callback, | 151 const net::CompletionCallback& callback, |
233 net::HttpRequestHeaders* headers) override; | 152 net::HttpRequestHeaders* headers) override; |
234 void OnBeforeSendProxyHeaders(net::URLRequest* request, | |
235 const net::ProxyInfo& proxy_info, | |
236 net::HttpRequestHeaders* headers) override; | |
237 void OnSendHeaders(net::URLRequest* request, | 153 void OnSendHeaders(net::URLRequest* request, |
238 const net::HttpRequestHeaders& headers) override; | 154 const net::HttpRequestHeaders& headers) override; |
239 int OnHeadersReceived( | 155 int OnHeadersReceived( |
240 net::URLRequest* request, | 156 net::URLRequest* request, |
241 const net::CompletionCallback& callback, | 157 const net::CompletionCallback& callback, |
242 const net::HttpResponseHeaders* original_response_headers, | 158 const net::HttpResponseHeaders* original_response_headers, |
243 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 159 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
244 GURL* allowed_unsafe_redirect_url) override; | 160 GURL* allowed_unsafe_redirect_url) override; |
245 void OnBeforeRedirect(net::URLRequest* request, | 161 void OnBeforeRedirect(net::URLRequest* request, |
246 const GURL& new_location) override; | 162 const GURL& new_location) override; |
(...skipping 18 matching lines...) Expand all Loading... |
265 bool OnCanEnablePrivacyMode( | 181 bool OnCanEnablePrivacyMode( |
266 const GURL& url, | 182 const GURL& url, |
267 const GURL& first_party_for_cookies) const override; | 183 const GURL& first_party_for_cookies) const override; |
268 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 184 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
269 const net::URLRequest& request, | 185 const net::URLRequest& request, |
270 const GURL& target_url, | 186 const GURL& target_url, |
271 const GURL& referrer_url) const override; | 187 const GURL& referrer_url) const override; |
272 | 188 |
273 void AccumulateContentLength( | 189 void AccumulateContentLength( |
274 int64 received_payload_byte_count, | 190 int64 received_payload_byte_count, |
275 int64 original_payload_byte_count, | 191 int64 original_payload_byte_count); |
276 data_reduction_proxy::DataReductionProxyRequestType request_type); | |
277 | 192 |
278 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_; | 193 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_; |
279 | 194 |
280 void* profile_; | 195 void* profile_; |
281 base::FilePath profile_path_; | 196 base::FilePath profile_path_; |
282 scoped_refptr<CookieSettings> cookie_settings_; | 197 scoped_refptr<CookieSettings> cookie_settings_; |
283 | 198 |
284 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_; | 199 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_; |
285 | 200 |
286 // Weak, owned by our owner. | 201 // Weak, owned by our owner. |
287 BooleanPrefMember* enable_referrers_; | 202 BooleanPrefMember* enable_referrers_; |
288 BooleanPrefMember* enable_do_not_track_; | 203 BooleanPrefMember* enable_do_not_track_; |
289 BooleanPrefMember* force_google_safe_search_; | 204 BooleanPrefMember* force_google_safe_search_; |
290 BooleanPrefMember* data_reduction_proxy_enabled_; | |
291 | 205 |
292 // Weak, owned by our owner. | 206 // Weak, owned by our owner. |
293 #if defined(ENABLE_CONFIGURATION_POLICY) | 207 #if defined(ENABLE_CONFIGURATION_POLICY) |
294 const policy::URLBlacklistManager* url_blacklist_manager_; | 208 const policy::URLBlacklistManager* url_blacklist_manager_; |
295 #endif | 209 #endif |
296 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_; | 210 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_; |
297 | 211 |
298 // When true, allow access to all file:// URLs. | 212 // When true, allow access to all file:// URLs. |
299 static bool g_allow_file_access_; | 213 static bool g_allow_file_access_; |
300 | 214 |
301 // True if OnCanThrottleRequest should always return false. | 215 // True if OnCanThrottleRequest should always return false. |
302 // | 216 // |
303 // Note: This needs to be static as the instance of | 217 // Note: This needs to be static as the instance of |
304 // ChromeNetworkDelegate used may change over time, and we need to | 218 // ChromeNetworkDelegate used may change over time, and we need to |
305 // set this variable once at start-up time. It is effectively | 219 // set this variable once at start-up time. It is effectively |
306 // static anyway since it is based on a command-line flag. | 220 // static anyway since it is based on a command-line flag. |
307 static bool g_never_throttle_requests_; | 221 static bool g_never_throttle_requests_; |
308 | 222 |
309 // Total size of all content (excluding headers) that has been received | |
310 // over the network. | |
311 int64 received_content_length_; | |
312 | |
313 // Total original size of all content before it was transferred. | |
314 int64 original_content_length_; | |
315 | |
316 scoped_ptr<ClientHints> client_hints_; | 223 scoped_ptr<ClientHints> client_hints_; |
317 | 224 |
318 bool first_request_; | 225 bool first_request_; |
319 | 226 |
320 prerender::PrerenderTracker* prerender_tracker_; | 227 prerender::PrerenderTracker* prerender_tracker_; |
321 | 228 |
322 // |data_reduction_proxy_params_| must outlive this ChromeNetworkDelegate. | |
323 data_reduction_proxy::DataReductionProxyParams* data_reduction_proxy_params_; | |
324 // |data_reduction_proxy_usage_stats_| must outlive this | |
325 // ChromeNetworkDelegate. | |
326 data_reduction_proxy::DataReductionProxyUsageStats* | |
327 data_reduction_proxy_usage_stats_; | |
328 data_reduction_proxy::DataReductionProxyAuthRequestHandler* | |
329 data_reduction_proxy_auth_request_handler_; | |
330 data_reduction_proxy::DataReductionProxyStatisticsPrefs* | |
331 data_reduction_proxy_statistics_prefs_; | |
332 | |
333 OnResolveProxyHandler on_resolve_proxy_handler_; | |
334 ProxyConfigGetter proxy_config_getter_; | |
335 | |
336 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); | 229 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); |
337 }; | 230 }; |
338 | 231 |
339 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 232 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
OLD | NEW |