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.
5 #include "net/base/network_delegate.h"
7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h"
9 #include "net/base/load_flags.h"
10 #include "net/base/net_errors.h"
11 #include "net/proxy/proxy_info.h"
12 #include "net/url_request/url_request.h"
16 int NetworkDelegate::NotifyBeforeURLRequest(
17 URLRequest
* request
, const CompletionCallback
& callback
,
19 DCHECK(CalledOnValidThread());
21 DCHECK(!callback
.is_null());
22 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
23 tracked_objects::ScopedTracker
tracking_profile(
24 FROM_HERE_WITH_EXPLICIT_FUNCTION(
25 "423948 NetworkDelegate::OnBeforeURLRequest"));
26 return OnBeforeURLRequest(request
, callback
, new_url
);
29 void NetworkDelegate::NotifyResolveProxy(
32 const ProxyService
& proxy_service
,
34 DCHECK(CalledOnValidThread());
36 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
37 tracked_objects::ScopedTracker
tracking_profile(
38 FROM_HERE_WITH_EXPLICIT_FUNCTION(
39 "423948 NetworkDelegate::OnResolveProxy"));
40 OnResolveProxy(url
, load_flags
, proxy_service
, result
);
43 void NetworkDelegate::NotifyProxyFallback(
44 const ProxyServer
& bad_proxy
,
46 DCHECK(CalledOnValidThread());
47 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
48 tracked_objects::ScopedTracker
tracking_profile(
49 FROM_HERE_WITH_EXPLICIT_FUNCTION(
50 "423948 NetworkDelegate::OnProxyFallback"));
51 OnProxyFallback(bad_proxy
, net_error
);
54 int NetworkDelegate::NotifyBeforeSendHeaders(
55 URLRequest
* request
, const CompletionCallback
& callback
,
56 HttpRequestHeaders
* headers
) {
57 DCHECK(CalledOnValidThread());
59 DCHECK(!callback
.is_null());
60 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
61 tracked_objects::ScopedTracker
tracking_profile(
62 FROM_HERE_WITH_EXPLICIT_FUNCTION(
63 "423948 NetworkDelegate::OnBeforeSendHeaders"));
64 return OnBeforeSendHeaders(request
, callback
, headers
);
67 void NetworkDelegate::NotifyBeforeSendProxyHeaders(
69 const ProxyInfo
& proxy_info
,
70 HttpRequestHeaders
* headers
) {
71 DCHECK(CalledOnValidThread());
73 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
74 tracked_objects::ScopedTracker
tracking_profile(
75 FROM_HERE_WITH_EXPLICIT_FUNCTION(
76 "423948 NetworkDelegate::OnBeforeSendProxyHeaders"));
77 OnBeforeSendProxyHeaders(request
, proxy_info
, headers
);
80 void NetworkDelegate::NotifySendHeaders(URLRequest
* request
,
81 const HttpRequestHeaders
& headers
) {
82 DCHECK(CalledOnValidThread());
83 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
84 tracked_objects::ScopedTracker
tracking_profile(
85 FROM_HERE_WITH_EXPLICIT_FUNCTION(
86 "423948 NetworkDelegate::OnSendHeaders"));
87 OnSendHeaders(request
, headers
);
90 int NetworkDelegate::NotifyHeadersReceived(
92 const CompletionCallback
& callback
,
93 const HttpResponseHeaders
* original_response_headers
,
94 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
95 GURL
* allowed_unsafe_redirect_url
) {
96 DCHECK(CalledOnValidThread());
97 DCHECK(original_response_headers
);
98 DCHECK(!callback
.is_null());
99 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
100 tracked_objects::ScopedTracker
tracking_profile(
101 FROM_HERE_WITH_EXPLICIT_FUNCTION(
102 "423948 NetworkDelegate::OnHeadersReceived"));
103 return OnHeadersReceived(request
,
105 original_response_headers
,
106 override_response_headers
,
107 allowed_unsafe_redirect_url
);
110 void NetworkDelegate::NotifyResponseStarted(URLRequest
* request
) {
111 DCHECK(CalledOnValidThread());
113 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
114 tracked_objects::ScopedTracker
tracking_profile(
115 FROM_HERE_WITH_EXPLICIT_FUNCTION(
116 "423948 NetworkDelegate::OnResponseStarted"));
117 OnResponseStarted(request
);
120 void NetworkDelegate::NotifyRawBytesRead(const URLRequest
& request
,
122 DCHECK(CalledOnValidThread());
123 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
124 tracked_objects::ScopedTracker
tracking_profile(
125 FROM_HERE_WITH_EXPLICIT_FUNCTION(
126 "423948 NetworkDelegate::OnRawBytesRead"));
127 OnRawBytesRead(request
, bytes_read
);
130 void NetworkDelegate::NotifyBeforeRedirect(URLRequest
* request
,
131 const GURL
& new_location
) {
132 DCHECK(CalledOnValidThread());
134 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
135 tracked_objects::ScopedTracker
tracking_profile(
136 FROM_HERE_WITH_EXPLICIT_FUNCTION(
137 "423948 NetworkDelegate::OnBeforeRedirect"));
138 OnBeforeRedirect(request
, new_location
);
141 void NetworkDelegate::NotifyCompleted(URLRequest
* request
, bool started
) {
142 DCHECK(CalledOnValidThread());
144 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
145 tracked_objects::ScopedTracker
tracking_profile(
146 FROM_HERE_WITH_EXPLICIT_FUNCTION("423948 NetworkDelegate::OnCompleted"));
147 OnCompleted(request
, started
);
150 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest
* request
) {
151 DCHECK(CalledOnValidThread());
153 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
154 tracked_objects::ScopedTracker
tracking_profile(
155 FROM_HERE_WITH_EXPLICIT_FUNCTION(
156 "423948 NetworkDelegate::OnURLRequestDestroyed"));
157 OnURLRequestDestroyed(request
);
160 void NetworkDelegate::NotifyPACScriptError(int line_number
,
161 const base::string16
& error
) {
162 DCHECK(CalledOnValidThread());
163 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
164 tracked_objects::ScopedTracker
tracking_profile(
165 FROM_HERE_WITH_EXPLICIT_FUNCTION(
166 "423948 NetworkDelegate::OnPACScriptError"));
167 OnPACScriptError(line_number
, error
);
170 NetworkDelegate::AuthRequiredResponse
NetworkDelegate::NotifyAuthRequired(
172 const AuthChallengeInfo
& auth_info
,
173 const AuthCallback
& callback
,
174 AuthCredentials
* credentials
) {
175 DCHECK(CalledOnValidThread());
176 return OnAuthRequired(request
, auth_info
, callback
, credentials
);
179 bool NetworkDelegate::CanGetCookies(const URLRequest
& request
,
180 const CookieList
& cookie_list
) {
181 DCHECK(CalledOnValidThread());
182 DCHECK(!(request
.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES
));
183 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
184 tracked_objects::ScopedTracker
tracking_profile(
185 FROM_HERE_WITH_EXPLICIT_FUNCTION(
186 "423948 NetworkDelegate::OnCanGetCookies"));
187 return OnCanGetCookies(request
, cookie_list
);
190 bool NetworkDelegate::CanSetCookie(const URLRequest
& request
,
191 const std::string
& cookie_line
,
192 CookieOptions
* options
) {
193 DCHECK(CalledOnValidThread());
194 DCHECK(!(request
.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES
));
195 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
196 tracked_objects::ScopedTracker
tracking_profile(
197 FROM_HERE_WITH_EXPLICIT_FUNCTION(
198 "423948 NetworkDelegate::OnCanSetCookie"));
199 return OnCanSetCookie(request
, cookie_line
, options
);
202 bool NetworkDelegate::CanAccessFile(const URLRequest
& request
,
203 const base::FilePath
& path
) const {
204 DCHECK(CalledOnValidThread());
205 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
206 tracked_objects::ScopedTracker
tracking_profile(
207 FROM_HERE_WITH_EXPLICIT_FUNCTION(
208 "423948 NetworkDelegate::OnCanAccessFile"));
209 return OnCanAccessFile(request
, path
);
212 bool NetworkDelegate::CanThrottleRequest(const URLRequest
& request
) const {
213 DCHECK(CalledOnValidThread());
214 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
215 tracked_objects::ScopedTracker
tracking_profile(
216 FROM_HERE_WITH_EXPLICIT_FUNCTION(
217 "423948 NetworkDelegate::OnCanThrottleRequest"));
218 return OnCanThrottleRequest(request
);
221 bool NetworkDelegate::CanEnablePrivacyMode(
223 const GURL
& first_party_for_cookies
) const {
224 DCHECK(CalledOnValidThread());
225 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
226 tracked_objects::ScopedTracker
tracking_profile(
227 FROM_HERE_WITH_EXPLICIT_FUNCTION(
228 "423948 NetworkDelegate::OnCanEnablePrivacyMode"));
229 return OnCanEnablePrivacyMode(url
, first_party_for_cookies
);
232 bool NetworkDelegate::CancelURLRequestWithPolicyViolatingReferrerHeader(
233 const URLRequest
& request
,
234 const GURL
& target_url
,
235 const GURL
& referrer_url
) const {
236 DCHECK(CalledOnValidThread());
237 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
238 tracked_objects::ScopedTracker
tracking_profile(
239 FROM_HERE_WITH_EXPLICIT_FUNCTION(
240 "423948 NetworkDelegate::OnCancelURLRequestWithPolicy..."));
241 return OnCancelURLRequestWithPolicyViolatingReferrerHeader(
242 request
, target_url
, referrer_url
);