Home | History | Annotate | Download | only in base
      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.
      4 
      5 #include "net/base/network_delegate.h"
      6 
      7 #include "base/logging.h"
      8 #include "net/base/load_flags.h"
      9 #include "net/base/net_errors.h"
     10 #include "net/url_request/url_request.h"
     11 
     12 namespace net {
     13 
     14 int NetworkDelegate::NotifyBeforeURLRequest(
     15     URLRequest* request, const CompletionCallback& callback,
     16     GURL* new_url) {
     17   DCHECK(CalledOnValidThread());
     18   DCHECK(request);
     19   DCHECK(!callback.is_null());
     20   return OnBeforeURLRequest(request, callback, new_url);
     21 }
     22 
     23 int NetworkDelegate::NotifyBeforeSendHeaders(
     24     URLRequest* request, const CompletionCallback& callback,
     25     HttpRequestHeaders* headers) {
     26   DCHECK(CalledOnValidThread());
     27   DCHECK(headers);
     28   DCHECK(!callback.is_null());
     29   return OnBeforeSendHeaders(request, callback, headers);
     30 }
     31 
     32 void NetworkDelegate::NotifySendHeaders(URLRequest* request,
     33                                         const HttpRequestHeaders& headers) {
     34   DCHECK(CalledOnValidThread());
     35   OnSendHeaders(request, headers);
     36 }
     37 
     38 int NetworkDelegate::NotifyHeadersReceived(
     39     URLRequest* request,
     40     const CompletionCallback& callback,
     41     const HttpResponseHeaders* original_response_headers,
     42     scoped_refptr<HttpResponseHeaders>* override_response_headers) {
     43   DCHECK(CalledOnValidThread());
     44   DCHECK(original_response_headers);
     45   DCHECK(!callback.is_null());
     46   return OnHeadersReceived(request, callback, original_response_headers,
     47                            override_response_headers);
     48 }
     49 
     50 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
     51   DCHECK(CalledOnValidThread());
     52   DCHECK(request);
     53   OnResponseStarted(request);
     54 }
     55 
     56 void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request,
     57                                          int bytes_read) {
     58   DCHECK(CalledOnValidThread());
     59   OnRawBytesRead(request, bytes_read);
     60 }
     61 
     62 void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
     63                                            const GURL& new_location) {
     64   DCHECK(CalledOnValidThread());
     65   DCHECK(request);
     66   OnBeforeRedirect(request, new_location);
     67 }
     68 
     69 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
     70   DCHECK(CalledOnValidThread());
     71   DCHECK(request);
     72   OnCompleted(request, started);
     73 }
     74 
     75 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
     76   DCHECK(CalledOnValidThread());
     77   DCHECK(request);
     78   OnURLRequestDestroyed(request);
     79 }
     80 
     81 void NetworkDelegate::NotifyPACScriptError(int line_number,
     82                                            const base::string16& error) {
     83   DCHECK(CalledOnValidThread());
     84   OnPACScriptError(line_number, error);
     85 }
     86 
     87 NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
     88     URLRequest* request,
     89     const AuthChallengeInfo& auth_info,
     90     const AuthCallback& callback,
     91     AuthCredentials* credentials) {
     92   DCHECK(CalledOnValidThread());
     93   return OnAuthRequired(request, auth_info, callback, credentials);
     94 }
     95 
     96 int NetworkDelegate::NotifyBeforeSocketStreamConnect(
     97     SocketStream* socket,
     98     const CompletionCallback& callback) {
     99   DCHECK(CalledOnValidThread());
    100   DCHECK(socket);
    101   DCHECK(!callback.is_null());
    102   return OnBeforeSocketStreamConnect(socket, callback);
    103 }
    104 
    105 void NetworkDelegate::NotifyRequestWaitStateChange(const URLRequest& request,
    106                                                    RequestWaitState state) {
    107   DCHECK(CalledOnValidThread());
    108   OnRequestWaitStateChange(request, state);
    109 }
    110 
    111 bool NetworkDelegate::CanGetCookies(const URLRequest& request,
    112                                     const CookieList& cookie_list) {
    113   DCHECK(CalledOnValidThread());
    114   DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES));
    115   return OnCanGetCookies(request, cookie_list);
    116 }
    117 
    118 bool NetworkDelegate::CanSetCookie(const URLRequest& request,
    119                                    const std::string& cookie_line,
    120                                    CookieOptions* options) {
    121   DCHECK(CalledOnValidThread());
    122   DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES));
    123   return OnCanSetCookie(request, cookie_line, options);
    124 }
    125 
    126 bool NetworkDelegate::CanAccessFile(const URLRequest& request,
    127                                     const base::FilePath& path) const {
    128   DCHECK(CalledOnValidThread());
    129   return OnCanAccessFile(request, path);
    130 }
    131 
    132 bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const {
    133   DCHECK(CalledOnValidThread());
    134   return OnCanThrottleRequest(request);
    135 }
    136 
    137 bool NetworkDelegate::CanEnablePrivacyMode(
    138     const GURL& url,
    139     const GURL& first_party_for_cookies) const {
    140   DCHECK(CalledOnValidThread());
    141   return OnCanEnablePrivacyMode(url, first_party_for_cookies);
    142 }
    143 
    144 int NetworkDelegate::OnBeforeURLRequest(URLRequest* request,
    145                                         const CompletionCallback& callback,
    146                                         GURL* new_url) {
    147   return OK;
    148 }
    149 
    150 int NetworkDelegate::OnBeforeSendHeaders(URLRequest* request,
    151                                          const CompletionCallback& callback,
    152                                          HttpRequestHeaders* headers) {
    153   return OK;
    154 }
    155 
    156 void NetworkDelegate::OnSendHeaders(URLRequest* request,
    157                                     const HttpRequestHeaders& headers) {
    158 }
    159 
    160 int NetworkDelegate::OnHeadersReceived(
    161     URLRequest* request,
    162     const CompletionCallback& callback,
    163     const HttpResponseHeaders* original_response_headers,
    164     scoped_refptr<HttpResponseHeaders>* override_response_headers) {
    165   return OK;
    166 }
    167 
    168 void NetworkDelegate::OnBeforeRedirect(URLRequest* request,
    169                                        const GURL& new_location) {
    170 }
    171 
    172 void NetworkDelegate::OnResponseStarted(URLRequest* request) {
    173 }
    174 
    175 void NetworkDelegate::OnRawBytesRead(const URLRequest& request,
    176                                      int bytes_read) {
    177 }
    178 
    179 void NetworkDelegate::OnCompleted(URLRequest* request, bool started) {
    180 }
    181 
    182 void NetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
    183 }
    184 
    185 void NetworkDelegate::OnPACScriptError(int line_number,
    186                                        const base::string16& error) {
    187 }
    188 
    189 NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
    190     URLRequest* request,
    191     const AuthChallengeInfo& auth_info,
    192     const AuthCallback& callback,
    193     AuthCredentials* credentials) {
    194   return AUTH_REQUIRED_RESPONSE_NO_ACTION;
    195 }
    196 
    197 bool NetworkDelegate::OnCanGetCookies(const URLRequest& request,
    198                                       const CookieList& cookie_list)  {
    199   return true;
    200 }
    201 
    202 bool NetworkDelegate::OnCanSetCookie(const URLRequest& request,
    203                                      const std::string& cookie_line,
    204                                      CookieOptions* options) {
    205   return true;
    206 }
    207 
    208 bool NetworkDelegate::OnCanAccessFile(const URLRequest& request,
    209                                       const base::FilePath& path) const  {
    210   return false;
    211 }
    212 
    213 bool NetworkDelegate::OnCanThrottleRequest(const URLRequest& request) const {
    214   return false;
    215 }
    216 
    217 bool NetworkDelegate::OnCanEnablePrivacyMode(
    218     const GURL& url,
    219     const GURL& first_party_for_cookies) const {
    220   return false;
    221 }
    222 
    223 int NetworkDelegate::OnBeforeSocketStreamConnect(
    224     SocketStream* socket,
    225     const CompletionCallback& callback) {
    226   return OK;
    227 }
    228 
    229 void NetworkDelegate::OnRequestWaitStateChange(const URLRequest& request,
    230                                                RequestWaitState state) {
    231 }
    232 
    233 }  // namespace net
    234