Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / net / base / network_delegate.cc
blob745336f14253305d435e55bcf9abc06f86f6c541
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"
14 namespace net {
16 int NetworkDelegate::NotifyBeforeURLRequest(
17 URLRequest* request, const CompletionCallback& callback,
18 GURL* new_url) {
19 DCHECK(CalledOnValidThread());
20 DCHECK(request);
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(
30 const GURL& url,
31 int load_flags,
32 const ProxyService& proxy_service,
33 ProxyInfo* result) {
34 DCHECK(CalledOnValidThread());
35 DCHECK(result);
36 OnResolveProxy(url, load_flags, proxy_service, result);
39 void NetworkDelegate::NotifyProxyFallback(
40 const ProxyServer& bad_proxy,
41 int net_error) {
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());
50 DCHECK(headers);
51 DCHECK(!callback.is_null());
52 return OnBeforeSendHeaders(request, callback, headers);
55 void NetworkDelegate::NotifyBeforeSendProxyHeaders(
56 URLRequest* request,
57 const ProxyInfo& proxy_info,
58 HttpRequestHeaders* headers) {
59 DCHECK(CalledOnValidThread());
60 DCHECK(headers);
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(
71 URLRequest* request,
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,
80 callback,
81 original_response_headers,
82 override_response_headers,
83 allowed_unsafe_redirect_url);
86 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
87 DCHECK(CalledOnValidThread());
88 DCHECK(request);
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());
102 DCHECK(request);
103 OnBeforeRedirect(request, new_location);
106 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
107 DCHECK(CalledOnValidThread());
108 DCHECK(request);
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());
117 DCHECK(request);
118 OnURLRequestDestroyed(request);
121 void NetworkDelegate::NotifyURLRequestJobOrphaned(URLRequest* request) {
122 DCHECK(CalledOnValidThread());
123 DCHECK(request);
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(
134 URLRequest* request,
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(
164 const GURL& url,
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);
183 } // namespace net