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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void set_force_google_safe_search( | 109 void set_force_google_safe_search( |
140 BooleanPrefMember* force_google_safe_search) { | 110 BooleanPrefMember* force_google_safe_search) { |
141 force_google_safe_search_ = force_google_safe_search; | 111 force_google_safe_search_ = force_google_safe_search; |
142 } | 112 } |
143 | 113 |
144 void set_force_youtube_safety_mode( | 114 void set_force_youtube_safety_mode( |
145 BooleanPrefMember* force_youtube_safety_mode) { | 115 BooleanPrefMember* force_youtube_safety_mode) { |
146 force_youtube_safety_mode_ = force_youtube_safety_mode; | 116 force_youtube_safety_mode_ = force_youtube_safety_mode; |
147 } | 117 } |
148 | 118 |
149 void set_data_reduction_proxy_enabled_pref( | |
150 BooleanPrefMember* data_reduction_proxy_enabled) { | |
151 data_reduction_proxy_enabled_ = data_reduction_proxy_enabled; | |
152 } | |
153 | |
154 void set_domain_reliability_monitor( | 119 void set_domain_reliability_monitor( |
155 domain_reliability::DomainReliabilityMonitor* monitor) { | 120 domain_reliability::DomainReliabilityMonitor* monitor) { |
156 domain_reliability_monitor_ = monitor; | 121 domain_reliability_monitor_ = monitor; |
157 } | 122 } |
158 | 123 |
159 void set_prerender_tracker(prerender::PrerenderTracker* prerender_tracker) { | 124 void set_prerender_tracker(prerender::PrerenderTracker* prerender_tracker) { |
160 prerender_tracker_ = prerender_tracker; | 125 prerender_tracker_ = prerender_tracker; |
161 } | 126 } |
162 | 127 |
163 // |data_reduction_proxy_params_| must outlive this ChromeNetworkDelegate. | |
164 void set_data_reduction_proxy_params( | |
165 data_reduction_proxy::DataReductionProxyParams* params) { | |
166 data_reduction_proxy_params_ = params; | |
167 } | |
168 | |
169 // |data_reduction_proxy_usage_stats_| must outlive this | |
170 // ChromeNetworkDelegate. | |
171 void set_data_reduction_proxy_usage_stats( | |
172 data_reduction_proxy::DataReductionProxyUsageStats* usage_stats) { | |
173 data_reduction_proxy_usage_stats_ = usage_stats; | |
174 } | |
175 | |
176 // |data_reduction_proxy_auth_request_handler_| must outlive this | |
177 // ChromeNetworkDelegate. | |
178 void set_data_reduction_proxy_auth_request_handler( | |
179 data_reduction_proxy::DataReductionProxyAuthRequestHandler* handler) { | |
180 data_reduction_proxy_auth_request_handler_ = handler; | |
181 } | |
182 | |
183 // |data_reduction_proxy_statistics_prefs_| must outlive this | |
184 // ChromeNetworkDelegate. | |
185 void set_data_reduction_proxy_statistics_prefs( | |
186 data_reduction_proxy::DataReductionProxyStatisticsPrefs* | |
187 statistics_prefs) { | |
188 data_reduction_proxy_statistics_prefs_ = statistics_prefs; | |
189 } | |
190 | |
191 void set_on_resolve_proxy_handler(OnResolveProxyHandler handler) { | |
192 on_resolve_proxy_handler_ = handler; | |
193 } | |
194 | |
195 void set_proxy_config_getter(const ProxyConfigGetter& getter) { | |
196 proxy_config_getter_ = getter; | |
197 } | |
198 | |
199 // Adds the Client Hints header to HTTP requests. | 128 // Adds the Client Hints header to HTTP requests. |
200 void SetEnableClientHints(); | 129 void SetEnableClientHints(); |
201 | 130 |
202 // Causes |OnCanThrottleRequest| to always return false, for all | 131 // Causes |OnCanThrottleRequest| to always return false, for all |
203 // instances of this object. | 132 // instances of this object. |
204 static void NeverThrottleRequests(); | 133 static void NeverThrottleRequests(); |
205 | 134 |
206 // Binds the pref members to |pref_service| and moves them to the IO thread. | 135 // Binds the pref members to |pref_service| and moves them to the IO thread. |
207 // |enable_referrers| cannot be NULL, the others can. | 136 // |enable_referrers| cannot be NULL, the others can. |
208 // This method should be called on the UI thread. | 137 // This method should be called on the UI thread. |
209 static void InitializePrefsOnUIThread( | 138 static void InitializePrefsOnUIThread( |
210 BooleanPrefMember* enable_referrers, | 139 BooleanPrefMember* enable_referrers, |
211 BooleanPrefMember* enable_do_not_track, | 140 BooleanPrefMember* enable_do_not_track, |
212 BooleanPrefMember* force_safe_search, | 141 BooleanPrefMember* force_safe_search, |
213 BooleanPrefMember* force_google_safe_search, | 142 BooleanPrefMember* force_google_safe_search, |
214 BooleanPrefMember* force_youtube_safety_mode, | 143 BooleanPrefMember* force_youtube_safety_mode, |
215 PrefService* pref_service); | 144 PrefService* pref_service); |
216 | 145 |
217 // When called, all file:// URLs will now be accessible. If this is not | 146 // When called, all file:// URLs will now be accessible. If this is not |
218 // called, then some platforms restrict access to file:// paths. | 147 // called, then some platforms restrict access to file:// paths. |
219 static void AllowAccessToAllFiles(); | 148 static void AllowAccessToAllFiles(); |
220 | 149 |
221 // Creates a Value summary of the persistent state of the network session. | |
222 // The caller is responsible for deleting the returned value. | |
223 // Must be called on the UI thread. | |
224 static base::Value* HistoricNetworkStatsInfoToValue(PrefService* prefs); | |
225 | |
226 // Creates a Value summary of the state of the network session. The caller is | |
227 // responsible for deleting the returned value. | |
228 base::Value* SessionNetworkStatsInfoToValue() const; | |
229 | |
230 private: | 150 private: |
231 friend class ChromeNetworkDelegateTest; | 151 friend class ChromeNetworkDelegateTest; |
232 | 152 |
233 // NetworkDelegate implementation. | 153 // NetworkDelegate implementation. |
234 int OnBeforeURLRequest(net::URLRequest* request, | 154 int OnBeforeURLRequest(net::URLRequest* request, |
235 const net::CompletionCallback& callback, | 155 const net::CompletionCallback& callback, |
236 GURL* new_url) override; | 156 GURL* new_url) override; |
237 void OnResolveProxy(const GURL& url, | |
238 int load_flags, | |
239 const net::ProxyService& proxy_service, | |
240 net::ProxyInfo* result) override; | |
241 void OnProxyFallback(const net::ProxyServer& bad_proxy, | |
242 int net_error) override; | |
243 int OnBeforeSendHeaders(net::URLRequest* request, | 157 int OnBeforeSendHeaders(net::URLRequest* request, |
244 const net::CompletionCallback& callback, | 158 const net::CompletionCallback& callback, |
245 net::HttpRequestHeaders* headers) override; | 159 net::HttpRequestHeaders* headers) override; |
246 void OnBeforeSendProxyHeaders(net::URLRequest* request, | |
247 const net::ProxyInfo& proxy_info, | |
248 net::HttpRequestHeaders* headers) override; | |
249 void OnSendHeaders(net::URLRequest* request, | 160 void OnSendHeaders(net::URLRequest* request, |
250 const net::HttpRequestHeaders& headers) override; | 161 const net::HttpRequestHeaders& headers) override; |
251 int OnHeadersReceived( | 162 int OnHeadersReceived( |
252 net::URLRequest* request, | 163 net::URLRequest* request, |
253 const net::CompletionCallback& callback, | 164 const net::CompletionCallback& callback, |
254 const net::HttpResponseHeaders* original_response_headers, | 165 const net::HttpResponseHeaders* original_response_headers, |
255 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 166 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
256 GURL* allowed_unsafe_redirect_url) override; | 167 GURL* allowed_unsafe_redirect_url) override; |
257 void OnBeforeRedirect(net::URLRequest* request, | 168 void OnBeforeRedirect(net::URLRequest* request, |
258 const GURL& new_location) override; | 169 const GURL& new_location) override; |
(...skipping 18 matching lines...) Expand all Loading... |
277 bool OnCanEnablePrivacyMode( | 188 bool OnCanEnablePrivacyMode( |
278 const GURL& url, | 189 const GURL& url, |
279 const GURL& first_party_for_cookies) const override; | 190 const GURL& first_party_for_cookies) const override; |
280 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 191 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
281 const net::URLRequest& request, | 192 const net::URLRequest& request, |
282 const GURL& target_url, | 193 const GURL& target_url, |
283 const GURL& referrer_url) const override; | 194 const GURL& referrer_url) const override; |
284 | 195 |
285 void AccumulateContentLength( | 196 void AccumulateContentLength( |
286 int64 received_payload_byte_count, | 197 int64 received_payload_byte_count, |
287 int64 original_payload_byte_count, | 198 int64 original_payload_byte_count); |
288 data_reduction_proxy::DataReductionProxyRequestType request_type); | |
289 | 199 |
290 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_; | 200 scoped_ptr<ChromeExtensionsNetworkDelegate> extensions_delegate_; |
291 | 201 |
292 void* profile_; | 202 void* profile_; |
293 base::FilePath profile_path_; | 203 base::FilePath profile_path_; |
294 scoped_refptr<CookieSettings> cookie_settings_; | 204 scoped_refptr<CookieSettings> cookie_settings_; |
295 | 205 |
296 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_; | 206 scoped_ptr<chrome_browser_net::ConnectInterceptor> connect_interceptor_; |
297 | 207 |
298 // Weak, owned by our owner. | 208 // Weak, owned by our owner. |
299 BooleanPrefMember* enable_referrers_; | 209 BooleanPrefMember* enable_referrers_; |
300 BooleanPrefMember* enable_do_not_track_; | 210 BooleanPrefMember* enable_do_not_track_; |
301 BooleanPrefMember* force_safe_search_; | 211 BooleanPrefMember* force_safe_search_; |
302 BooleanPrefMember* force_google_safe_search_; | 212 BooleanPrefMember* force_google_safe_search_; |
303 BooleanPrefMember* force_youtube_safety_mode_; | 213 BooleanPrefMember* force_youtube_safety_mode_; |
304 BooleanPrefMember* data_reduction_proxy_enabled_; | |
305 | 214 |
306 // Weak, owned by our owner. | 215 // Weak, owned by our owner. |
307 #if defined(ENABLE_CONFIGURATION_POLICY) | 216 #if defined(ENABLE_CONFIGURATION_POLICY) |
308 const policy::URLBlacklistManager* url_blacklist_manager_; | 217 const policy::URLBlacklistManager* url_blacklist_manager_; |
309 #endif | 218 #endif |
310 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_; | 219 domain_reliability::DomainReliabilityMonitor* domain_reliability_monitor_; |
311 | 220 |
312 // When true, allow access to all file:// URLs. | 221 // When true, allow access to all file:// URLs. |
313 static bool g_allow_file_access_; | 222 static bool g_allow_file_access_; |
314 | 223 |
315 // True if OnCanThrottleRequest should always return false. | 224 // True if OnCanThrottleRequest should always return false. |
316 // | 225 // |
317 // Note: This needs to be static as the instance of | 226 // Note: This needs to be static as the instance of |
318 // ChromeNetworkDelegate used may change over time, and we need to | 227 // ChromeNetworkDelegate used may change over time, and we need to |
319 // set this variable once at start-up time. It is effectively | 228 // set this variable once at start-up time. It is effectively |
320 // static anyway since it is based on a command-line flag. | 229 // static anyway since it is based on a command-line flag. |
321 static bool g_never_throttle_requests_; | 230 static bool g_never_throttle_requests_; |
322 | 231 |
323 // Total size of all content (excluding headers) that has been received | |
324 // over the network. | |
325 int64 received_content_length_; | |
326 | |
327 // Total original size of all content before it was transferred. | |
328 int64 original_content_length_; | |
329 | |
330 scoped_ptr<ClientHints> client_hints_; | 232 scoped_ptr<ClientHints> client_hints_; |
331 | 233 |
332 bool first_request_; | 234 bool first_request_; |
333 | 235 |
334 prerender::PrerenderTracker* prerender_tracker_; | 236 prerender::PrerenderTracker* prerender_tracker_; |
335 | 237 |
336 // |data_reduction_proxy_params_| must outlive this ChromeNetworkDelegate. | |
337 data_reduction_proxy::DataReductionProxyParams* data_reduction_proxy_params_; | |
338 // |data_reduction_proxy_usage_stats_| must outlive this | |
339 // ChromeNetworkDelegate. | |
340 data_reduction_proxy::DataReductionProxyUsageStats* | |
341 data_reduction_proxy_usage_stats_; | |
342 data_reduction_proxy::DataReductionProxyAuthRequestHandler* | |
343 data_reduction_proxy_auth_request_handler_; | |
344 data_reduction_proxy::DataReductionProxyStatisticsPrefs* | |
345 data_reduction_proxy_statistics_prefs_; | |
346 | |
347 OnResolveProxyHandler on_resolve_proxy_handler_; | |
348 ProxyConfigGetter proxy_config_getter_; | |
349 | |
350 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); | 238 DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate); |
351 }; | 239 }; |
352 | 240 |
353 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ | 241 #endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_ |
OLD | NEW |