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(cbentzel): Remove ScopedTracker below once crbug.com/475753 is fixed.
23 tracked_objects::ScopedTracker
tracking_profile(
24 FROM_HERE_WITH_EXPLICIT_FUNCTION(
25 "475753 NetworkDelegate::OnBeforeURLRequest"));
26 return OnBeforeURLRequest(request
, callback
, new_url
);
29 void NetworkDelegate::NotifyResolveProxy(
32 const ProxyService
& proxy_service
,
34 DCHECK(CalledOnValidThread());
36 OnResolveProxy(url
, load_flags
, proxy_service
, result
);
39 void NetworkDelegate::NotifyProxyFallback(
40 const ProxyServer
& bad_proxy
,
42 DCHECK(CalledOnValidThread());
43 OnProxyFallback(bad_proxy
, net_error
);
46 int NetworkDelegate::NotifyBeforeSendHeaders(
47 URLRequest
* request
, const CompletionCallback
& callback
,
48 HttpRequestHeaders
* headers
) {
49 DCHECK(CalledOnValidThread());
51 DCHECK(!callback
.is_null());
52 return OnBeforeSendHeaders(request
, callback
, headers
);
55 void NetworkDelegate::NotifyBeforeSendProxyHeaders(
57 const ProxyInfo
& proxy_info
,
58 HttpRequestHeaders
* headers
) {
59 DCHECK(CalledOnValidThread());
61 OnBeforeSendProxyHeaders(request
, proxy_info
, headers
);
64 void NetworkDelegate::NotifySendHeaders(URLRequest
* request
,
65 const HttpRequestHeaders
& headers
) {
66 DCHECK(CalledOnValidThread());
67 OnSendHeaders(request
, headers
);
70 int NetworkDelegate::NotifyHeadersReceived(
72 const CompletionCallback
& callback
,
73 const HttpResponseHeaders
* original_response_headers
,
74 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
75 GURL
* allowed_unsafe_redirect_url
) {
76 DCHECK(CalledOnValidThread());
77 DCHECK(original_response_headers
);
78 DCHECK(!callback
.is_null());
79 return OnHeadersReceived(request
,
81 original_response_headers
,
82 override_response_headers
,
83 allowed_unsafe_redirect_url
);
86 void NetworkDelegate::NotifyResponseStarted(URLRequest
* request
) {
87 DCHECK(CalledOnValidThread());
89 OnResponseStarted(request
);
92 void NetworkDelegate::NotifyNetworkBytesReceived(const URLRequest
& request
,
93 int64_t bytes_received
) {
94 DCHECK(CalledOnValidThread());
95 DCHECK_GT(bytes_received
, 0);
96 OnNetworkBytesReceived(request
, bytes_received
);
99 void NetworkDelegate::NotifyBeforeRedirect(URLRequest
* request
,
100 const GURL
& new_location
) {
101 DCHECK(CalledOnValidThread());
103 OnBeforeRedirect(request
, new_location
);
106 void NetworkDelegate::NotifyCompleted(URLRequest
* request
, bool started
) {
107 DCHECK(CalledOnValidThread());
109 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475753 is fixed.
110 tracked_objects::ScopedTracker
tracking_profile(
111 FROM_HERE_WITH_EXPLICIT_FUNCTION("475753 NetworkDelegate::OnCompleted"));
112 OnCompleted(request
, started
);
115 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest
* request
) {
116 DCHECK(CalledOnValidThread());
118 OnURLRequestDestroyed(request
);
121 void NetworkDelegate::NotifyURLRequestJobOrphaned(URLRequest
* request
) {
122 DCHECK(CalledOnValidThread());
124 OnURLRequestJobOrphaned(request
);
127 void NetworkDelegate::NotifyPACScriptError(int line_number
,
128 const base::string16
& error
) {
129 DCHECK(CalledOnValidThread());
130 OnPACScriptError(line_number
, error
);
133 NetworkDelegate::AuthRequiredResponse
NetworkDelegate::NotifyAuthRequired(
135 const AuthChallengeInfo
& auth_info
,
136 const AuthCallback
& callback
,
137 AuthCredentials
* credentials
) {
138 DCHECK(CalledOnValidThread());
139 return OnAuthRequired(request
, auth_info
, callback
, credentials
);
142 bool NetworkDelegate::CanGetCookies(const URLRequest
& request
,
143 const CookieList
& cookie_list
) {
144 DCHECK(CalledOnValidThread());
145 DCHECK(!(request
.load_flags() & LOAD_DO_NOT_SEND_COOKIES
));
146 return OnCanGetCookies(request
, cookie_list
);
149 bool NetworkDelegate::CanSetCookie(const URLRequest
& request
,
150 const std::string
& cookie_line
,
151 CookieOptions
* options
) {
152 DCHECK(CalledOnValidThread());
153 DCHECK(!(request
.load_flags() & LOAD_DO_NOT_SAVE_COOKIES
));
154 return OnCanSetCookie(request
, cookie_line
, options
);
157 bool NetworkDelegate::CanAccessFile(const URLRequest
& request
,
158 const base::FilePath
& path
) const {
159 DCHECK(CalledOnValidThread());
160 return OnCanAccessFile(request
, path
);
163 bool NetworkDelegate::CanEnablePrivacyMode(
165 const GURL
& first_party_for_cookies
) const {
166 DCHECK(CalledOnValidThread());
167 return OnCanEnablePrivacyMode(url
, first_party_for_cookies
);
170 bool NetworkDelegate::FirstPartyOnlyCookieExperimentEnabled() const {
171 return OnFirstPartyOnlyCookieExperimentEnabled();
174 bool NetworkDelegate::CancelURLRequestWithPolicyViolatingReferrerHeader(
175 const URLRequest
& request
,
176 const GURL
& target_url
,
177 const GURL
& referrer_url
) const {
178 DCHECK(CalledOnValidThread());
179 return OnCancelURLRequestWithPolicyViolatingReferrerHeader(
180 request
, target_url
, referrer_url
);