url_request.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_URL_REQUEST_URL_REQUEST_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_URL_REQUEST_URL_REQUEST_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/debug/leak_tracker.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/string16.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/supports_user_data.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/time.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/non_thread_safe.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "googleurl/src/gurl.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/completion_callback.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/load_states.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/load_timing_info.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_log.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/network_delegate.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/request_priority.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/upload_progress.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_request_headers.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_response_info.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_status.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChildProcessSecurityPolicyTest;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestAutomationProvider;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestAutomationJob;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace debug {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StackTrace;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace appcache {
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheInterceptor;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheRequestHandlerTest;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheURLRequestJobTest;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceDispatcherHostTest;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace fileapi {
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemDirURLRequestJobTest;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemURLRequestJobTest;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileWriterDelegateTest;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace webkit_blob {
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BlobURLRequestJobTest;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CookieOptions;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HostPortPair;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IOBuffer;
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct LoadTimingInfo;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLCertRequestInfo;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLInfo;
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UploadDataStream;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContext;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestJob;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class X509Certificate;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This stores the values of the Set-Cookie headers received during the request.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Each item in the vector corresponds to a Set-Cookie: line received,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// excluding the "Set-Cookie:" part.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<std::string> ResponseCookies;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//-----------------------------------------------------------------------------
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A class  representing the asynchronous load of a data stream from an URL.
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The lifetime of an instance of this class is completely controlled by the
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// consumer, and the instance is not required to live on the heap or be
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// allocated in any special way.  It is also valid to delete an URLRequest
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// object during the handling of a callback to its delegate.  Of course, once
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the URLRequest is deleted, no further callbacks to its delegate will occur.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: All usage of all instances of this class should be on the same thread.
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              public base::SupportsUserData {
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback function implemented by protocol handlers to create new jobs.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The factory may return NULL to indicate an error, which will cause other
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // factories to be queried.  If no factory handles the request, then the
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // default job will be used.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef URLRequestJob* (ProtocolFactory)(URLRequest* request,
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           NetworkDelegate* network_delegate,
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const std::string& scheme);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP request/response header IDs (via some preprocessor fun) for use with
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // SetRequestHeaderById and GetResponseHeaderById.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum {
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define HTTP_ATOM(x) HTTP_ ## x,
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_atom_list.h"
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#undef HTTP_ATOM
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Referrer policies (see set_referrer_policy): During server redirects, the
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // referrer header might be cleared, if the protocol changes from HTTPS to
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP. This is the default behavior of URLRequest, corresponding to
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // referrer policy can be set to never change the referrer header. This
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NEVER_CLEAR_REFERRER when implementing the meta-referrer support
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // non-default referrer policy. Only the default referrer policy requires
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the referrer to be cleared on transitions from HTTPS to HTTP.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ReferrerPolicy {
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NEVER_CLEAR_REFERRER,
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This class handles network interception.  Use with
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (Un)RegisterRequestInterceptor.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NET_EXPORT Interceptor {
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  public:
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~Interceptor() {}
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called for every request made.  Should return a new job to handle the
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request if it should be intercepted, or NULL to allow the request to
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // be handled in the normal manner.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual URLRequestJob* MaybeIntercept(
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request, NetworkDelegate* network_delegate) = 0;
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called after having received a redirect response, but prior to the
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the request delegate being informed of the redirect. Can return a new
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // job to replace the existing job if it should be intercepted, or NULL
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // to allow the normal handling to continue. If a new job is provided,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the delegate never sees the original redirect response, instead the
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // response produced by the intercept job will be returned.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual URLRequestJob* MaybeInterceptRedirect(
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request,
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        NetworkDelegate* network_delegate,
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        const GURL& location);
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called after having received a final response, but prior to the
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the request delegate being informed of the response. This is also
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // called when there is no server response at all to allow interception
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // on dns or network errors. Can return a new job to replace the existing
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // job if it should be intercepted, or NULL to allow the normal handling to
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // continue. If a new job is provided, the delegate never sees the original
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // response, instead the response produced by the intercept job will be
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // returned.
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual URLRequestJob* MaybeInterceptResponse(
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request, NetworkDelegate* network_delegate);
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deprecated interfaces in net::URLRequest. They have been moved to
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLRequest's private section to prevent new uses. Existing uses are
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // explicitly friended here and should be removed over time.
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NET_EXPORT Deprecated {
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // TODO(willchan): Kill off these friend declarations.
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class ::ChildProcessSecurityPolicyTest;
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class ::TestAutomationProvider;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class ::URLRequestAutomationJob;
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class TestInterceptor;
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class URLRequestFilter;
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class appcache::AppCacheInterceptor;
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class appcache::AppCacheRequestHandlerTest;
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class appcache::AppCacheURLRequestJobTest;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class content::ResourceDispatcherHostTest;
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class fileapi::FileSystemDirURLRequestJobTest;
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class fileapi::FileSystemURLRequestJobTest;
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class fileapi::FileWriterDelegateTest;
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class webkit_blob::BlobURLRequestJobTest;
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Use URLRequestJobFactory::ProtocolHandler instead.
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                    ProtocolFactory* factory);
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // TODO(pauljensen): Remove this when AppCacheInterceptor is a
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // ProtocolHandler, see crbug.com/161547.
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    static void RegisterRequestInterceptor(Interceptor* interceptor);
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    static void UnregisterRequestInterceptor(Interceptor* interceptor);
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_IMPLICIT_CONSTRUCTORS(Deprecated);
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The delegate's methods are called from the message loop of the thread
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on which the request's Start() method is called. See above for the
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ordering of callbacks.
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The callbacks will be called in the following order:
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   Start()
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnCertificateRequested* (zero or more calls, if the SSL server and/or
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      SSL proxy requests a client certificate for authentication)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnSSLCertificateError* (zero or one call, if the SSL server's
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      certificate has an error)
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnReceivedRedirect* (zero or more calls, for the number of redirects)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnAuthRequired* (zero or more calls, for the number of
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //      authentication failures)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnResponseStarted
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   Read() initiated by delegate
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    - OnReadCompleted* (zero or more calls until all data is read)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Read() must be called at least once. Read() returns true when it completed
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // immediately, and false if an IO is pending or if there is an error.  When
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Read() returns false, the caller can check the Request's status() to see
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if an error occurred, or if the IO is just pending.  When Read() returns
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // true with zero bytes read, it indicates the end of the response.
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NET_EXPORT Delegate {
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called upon a server-initiated redirect.  The delegate may call the
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request's Cancel method to prevent the redirect from being followed.
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Since there may be multiple chained redirects, there may also be more
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // than one redirect call.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // When this function is called, the request will still contain the
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // original URL, the destination of the redirect is provided in 'new_url'.
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If the delegate does not cancel the request and |*defer_redirect| is
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // false, then the redirect will be followed, and the request's URL will be
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // changed to the new URL.  Otherwise if the delegate does not cancel the
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request and |*defer_redirect| is true, then the redirect will be
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // followed once FollowDeferredRedirect is called on the URLRequest.
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The caller must set |*defer_redirect| to false, so that delegates do not
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // need to set it if they are happy with the default behavior of not
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // deferring redirect.
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnReceivedRedirect(URLRequest* request,
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const GURL& new_url,
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    bool* defer_redirect);
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when we receive an authentication failure.  The delegate should
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // call request->SetAuth() with the user's credentials once it obtains them,
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // or request->CancelAuth() to cancel the login and display the error page.
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // When it does so, the request will be reissued, restarting the sequence
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // of On* callbacks.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnAuthRequired(URLRequest* request,
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                AuthChallengeInfo* auth_info);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when we receive an SSL CertificateRequest message for client
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // authentication.  The delegate should call
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request->ContinueWithCertificate() with the client certificate the user
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // selected, or request->ContinueWithCertificate(NULL) to continue the SSL
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // handshake without a client certificate.
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnCertificateRequested(
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        URLRequest* request,
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        SSLCertRequestInfo* cert_request_info);
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when using SSL and the server responds with a certificate with
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // an error, for example, whose common name does not match the common name
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // we were expecting for that host.  The delegate should either do the
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // safe thing and Cancel() the request or decide to proceed by calling
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // ContinueDespiteLastError().  cert_error is a ERR_* error code
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // indicating what's wrong with the certificate.
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If |fatal| is true then the host in question demands a higher level
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // of security (due e.g. to HTTP Strict Transport Security, user
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // preference, or built-in policy). In this case, errors must not be
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // bypassable by the user.
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnSSLCertificateError(URLRequest* request,
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       const SSLInfo& ssl_info,
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       bool fatal);
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // After calling Start(), the delegate will receive an OnResponseStarted
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // callback when the request has completed.  If an error occurred, the
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // request->status() will be set.  On success, all redirects have been
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // followed and the final response is beginning to arrive.  At this point,
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // meta data about the response is available, including for example HTTP
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // response headers if this is a request for a HTTP resource.
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnResponseStarted(URLRequest* request) = 0;
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called when the a Read of the response body is completed after an
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // IO_PENDING status from a Read() call.
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The data read is filled into the buffer which the caller passed
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // to Read() previously.
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If an error occurred, request->status() will contain the error,
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // and bytes read will be -1.
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   protected:
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~Delegate() {}
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(shalev): Get rid of this constructor in favour of the one below it.
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initialize an URL request.
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  URLRequest(const GURL& url,
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             Delegate* delegate,
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             const URLRequestContext* context);
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  URLRequest(const GURL& url,
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             Delegate* delegate,
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             const URLRequestContext* context,
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)             NetworkDelegate* network_delegate);
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If destroyed after Start() has been called but while IO is pending,
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // then the request will be effectively canceled and the delegate
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will not have any more of its methods called.
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~URLRequest();
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the default cookie policy from allowing all cookies to blocking all
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookies. Embedders that want to implement a more flexible policy should
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // change the default to blocking all cookies, and provide a NetworkDelegate
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with the URLRequestContext that maintains the CookieStore.
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The cookie policy default has to be set before the first URLRequest is
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // started. Once it was set to block all cookies, it cannot be changed back.
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void SetDefaultCookiePolicyToBlock();
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the scheme can be handled by URLRequest. False otherwise.
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsHandledProtocol(const std::string& scheme);
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the url can be handled by URLRequest. False otherwise.
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The function returns true for invalid urls because URLRequest knows how
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to handle those.
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE: This will also return true for URLs that are handled by
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ProtocolFactories that only work for requests that are scoped to a
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Profile.
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsHandledURL(const GURL& url);
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The original url is the url used to initialize the request, and it may
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // differ from the url if the request was redirected.
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL& original_url() const { return url_chain_.front(); }
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The chain of urls traversed by this request.  If the request had no
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // redirects, this vector will contain one element.
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::vector<GURL>& url_chain() const { return url_chain_; }
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL& url() const { return url_chain_.back(); }
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The URL that should be consulted for the third-party cookie blocking
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // policy.
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WARNING: This URL must only be used for the third-party cookie blocking
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          policy. It MUST NEVER be used for any kind of SECURITY check.
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          For example, if a top-level navigation is redirected, the
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          first-party for cookies will be the URL of the first URL in the
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          redirect chain throughout the whole redirect. If it was used for
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          a security check, an attacker might try to get around this check
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          by starting from some page that redirects to the
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          host-to-be-attacked.
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL& first_party_for_cookies() const {
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return first_party_for_cookies_;
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called before Start() or FollowDeferredRedirect() is
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called.
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_first_party_for_cookies(const GURL& first_party_for_cookies);
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The request method, as an uppercase string.  "GET" is the default value.
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The request method may only be changed before Start() is called and
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // should only be assigned an uppercase value.
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& method() const { return method_; }
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_method(const std::string& method);
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The referrer URL for the request.  This header may actually be suppressed
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from the underlying network request for security reasons (e.g., a HTTPS
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL will not be sent as the referrer for a HTTP request).  The referrer
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may only be changed before Start() is called.
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& referrer() const { return referrer_; }
373c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Referrer is sanitized to remove URL fragment, user name and password.
374c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetReferrer(const std::string& referrer);
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The referrer policy to apply when updating the referrer during redirects.
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The referrer policy may only be changed before Start() is called.
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_referrer_policy(ReferrerPolicy referrer_policy);
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the delegate of the request.  This value may be changed at any time,
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and it is permissible for it to be null.
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_delegate(Delegate* delegate);
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates that the request body should be sent using chunked transfer
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // encoding. This method may only be called before Start() is called.
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void EnableChunkedUpload();
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Appends the given bytes to the request's upload data to be sent
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // immediately via chunked transfer encoding. When all data has been sent,
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // call MarkEndOfChunks() to indicate the end of upload data.
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called only after calling EnableChunkedUpload().
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AppendChunkToUpload(const char* bytes,
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           int bytes_len,
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           bool is_last_chunk);
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the upload data.
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_upload(scoped_ptr<UploadDataStream> upload);
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets the upload data.
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const UploadDataStream* get_upload() const;
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request has a non-empty message body to upload.
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool has_upload() const;
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Set an extra request header by ID or name, or remove one by name.  These
4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // methods may only be called before Start() is called, or before a new
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // redirect in the request chain.
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetExtraRequestHeaderById(int header_id, const std::string& value,
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 bool overwrite);
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetExtraRequestHeaderByName(const std::string& name,
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const std::string& value, bool overwrite);
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void RemoveRequestHeaderByName(const std::string& name);
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets all extra request headers.  Any extra request headers set by other
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // methods are overwritten by this method.  This method may only be called
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before Start() is called.  It is an error to call it later.
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetExtraRequestHeaders(const HttpRequestHeaders& headers);
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HttpRequestHeaders& extra_request_headers() const {
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return extra_request_headers_;
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the current load state for the request. |param| is an optional
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // parameter describing details related to the load state. Not all load states
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // have a parameter.
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LoadStateWithParam GetLoadState() const;
428c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetLoadStateParam(const base::string16& param) {
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    load_state_param_ = param;
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the current upload progress in bytes. When the upload data is
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // chunked, size is set to zero, but position will not be.
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UploadProgress GetUploadProgress() const;
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get response header(s) by ID or name.  These methods may only be called
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // once the delegate's OnResponseStarted method has been called.  Headers
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that appear more than once in the response are coalesced, with values
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // separated by commas (per RFC 2616). This will not work with cookies since
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // comma can be used in cookie values.
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(darin): add API to enumerate response headers.
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetResponseHeaderById(int header_id, std::string* value);
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetResponseHeaderByName(const std::string& name, std::string* value);
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get all response headers, \n-delimited and \n\0-terminated.  This includes
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the response status line.  Restrictions on GetResponseHeaders apply.
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetAllResponseHeaders(std::string* headers);
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The time when |this| was constructed.
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks creation_time() const { return creation_time_; }
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The time at which the returned response was requested.  For cached
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // responses, this is the last time the cache entry was validated.
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time& request_time() const {
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.request_time;
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The time at which the returned response was generated.  For cached
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // responses, this is the last time the cache entry was validated.
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time& response_time() const {
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.response_time;
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicate if this response was fetched from disk cache.
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool was_cached() const { return response_info_.was_cached; }
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the URLRequest was delivered through a proxy.
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool was_fetched_via_proxy() const {
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.was_fetched_via_proxy;
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the host and port that the content was fetched from.  See
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // http_response_info.h for caveats relating to cached content.
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HostPortPair GetSocketAddress() const;
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get all response headers, as a HttpResponseHeaders object.  See comments
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in HttpResponseHeaders class as to the format of the data.
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpResponseHeaders* response_headers() const;
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the SSL connection info.
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const SSLInfo& ssl_info() const {
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return response_info_.ssl_info;
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Gets timing information related to the request.  Events that have not yet
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // occurred are left uninitialized.  After a second request starts, due to
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // a redirect or authentication, values will be reset.
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // LoadTimingInfo only contains ConnectTiming information and socket IDs for
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // non-cached HTTP responses.
4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const;
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the cookie values included in the response, if the request is one
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that can have cookies.  Returns true if the request is a cookie-bearing
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type, false otherwise.  This method may only be called once the
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // delegate's OnResponseStarted method has been called.
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetResponseCookies(ResponseCookies* cookies);
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the mime type.  This method may only be called once the delegate's
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnResponseStarted method has been called.
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetMimeType(std::string* mime_type);
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the charset (character encoding).  This method may only be called once
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the delegate's OnResponseStarted method has been called.
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetCharset(std::string* charset);
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the HTTP response code (e.g., 200, 404, and so on).  This method
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may only be called once the delegate's OnResponseStarted method has been
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called.  For non-HTTP requests, this method returns -1.
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int GetResponseCode();
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the HTTP response info in its entirety.
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HttpResponseInfo& response_info() const { return response_info_; }
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Access the LOAD_* flags modifying this request (see load_flags.h).
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int load_flags() const { return load_flags_; }
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_load_flags(int flags) { load_flags_ = flags; }
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request is "pending" (i.e., if Start() has been called,
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and the response has not yet been called).
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_pending() const { return is_pending_; }
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request is in the process of redirecting to a new
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URL but has not yet initiated the new request.
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_redirecting() const { return is_redirecting_; }
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the error status of the request.
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const URLRequestStatus& status() const { return status_; }
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a globally unique identifier for this request.
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint64 identifier() const { return identifier_; }
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method is called to start the request.  The delegate will receive
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a OnResponseStarted callback when the request is started.
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Start();
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called at any time after Start() has been called to
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancel the request.  This method may be called many times, and it has
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // no effect once the response has completed.  It is guaranteed that no
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // methods of the delegate will be called after the request has been
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancelled, except that this may call the delegate's OnReadCompleted()
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // during the call to Cancel itself.
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Cancel();
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels the request and sets the error to |error| (see net_error_list.h
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for values).
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelWithError(int error);
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels the request and sets the error to |error| (see net_error_list.h
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for values) and attaches |ssl_info| as the SSLInfo for that request.  This
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is useful to attach a certificate and certificate error to a canceled
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // request.
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelWithSSLError(int error, const SSLInfo& ssl_info);
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Read initiates an asynchronous read from the response, and must only
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be called after the OnResponseStarted callback is received with a
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // successful status.
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If data is available, Read will return true, and the data and length will
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be returned immediately.  If data is not available, Read returns false,
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and an asynchronous Read is initiated.  The Read is finished when
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the caller receives the OnReadComplete callback.  Unless the request was
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancelled, OnReadComplete will always be called, even if the read failed.
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The buf parameter is a buffer to receive the data.  If the operation
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completes asynchronously, the implementation will reference the buffer
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // until OnReadComplete is called.  The buffer must be at least max_bytes in
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // length.
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The max_bytes parameter is the maximum number of bytes to read.
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The bytes_read parameter is an output parameter containing the
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the number of bytes read.  A value of 0 indicates that there is no
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // more data available to read from the stream.
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If a read error occurs, Read returns false and the request->status
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be set to an error.
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Read(IOBuffer* buf, int max_bytes, int* bytes_read);
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If this request is being cached by the HTTP cache, stop subsequent caching.
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that this method has no effect on other (simultaneous or not) requests
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for the same resource. The typical example is a request that results in
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the data being stored to disk (downloaded instead of rendered) so we don't
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // want to store it twice.
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StopCaching();
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may be called to follow a redirect that was deferred in
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // response to an OnReceivedRedirect call.
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FollowDeferredRedirect();
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // One of the following two methods should be called in response to an
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnAuthRequired() callback (and only then).
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // SetAuth will reissue the request with the given credentials.
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CancelAuth will give up and display the error page.
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetAuth(const AuthCredentials& credentials);
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CancelAuth();
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method can be called after the user selects a client certificate to
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // instruct this URLRequest to continue with the request with the
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // certificate.  Pass NULL if the user doesn't have a client certificate.
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ContinueWithCertificate(X509Certificate* client_cert);
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method can be called after some error notifications to instruct this
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLRequest to ignore the current error and continue with the request.  To
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cancel the request instead, call Cancel().
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ContinueDespiteLastError();
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used to specify the context (cookie store, cache) for this request.
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const URLRequestContext* context() const;
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const BoundNetLog& net_log() const { return net_log_; }
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the expected content size if available
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 GetExpectedContentSize() const;
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the priority level for this request.
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RequestPriority priority() const { return priority_; }
6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the priority level for this request and any related jobs.
6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetPriority(RequestPriority priority);
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true iff this request would be internally redirected to HTTPS
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // due to HSTS. If so, |redirect_url| is rewritten to the new HTTPS URL.
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetHSTSRedirect(GURL* redirect_url) const;
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(willchan): Undo this. Only temporarily public.
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool has_delegate() const { return delegate_ != NULL; }
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE(willchan): This is just temporary for debugging
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // http://crbug.com/90971.
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allows to setting debug info into the URLRequest.
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_stack_trace(const base::debug::StackTrace& stack_trace);
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::debug::StackTrace* stack_trace() const;
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_received_response_content_length(int64 received_content_length) {
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    received_response_content_length_ = received_content_length;
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 received_response_content_length() {
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return received_response_content_length_;
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow the URLRequestJob class to control the is_pending() flag.
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_is_pending(bool value) { is_pending_ = value; }
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow the URLRequestJob class to set our status too
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_status(const URLRequestStatus& value) { status_ = value; }
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow the URLRequestJob to redirect this request.  Returns OK if
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // successful, otherwise an error code is returned.
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int Redirect(const GURL& location, int http_status_code);
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by URLRequestJob to allow interception when a redirect occurs.
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect);
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Allow an interceptor's URLRequestJob to restart this request.
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Should only be called if the original job has not started a response.
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Restart();
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class URLRequestJob;
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Registers a new protocol handler for the given scheme. If the scheme is
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // already handled, this will overwrite the given factory. To delete the
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // protocol factory, use NULL for the factory BUT this WILL NOT put back
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // any previously registered protocol factory. It will have returned
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the previously registered factory (or NULL if none is registered) when
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the scheme was first registered so that the caller can manually put it
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // back if desired.
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The scheme must be all-lowercase ASCII. See the ProtocolFactory
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // declaration for its requirements.
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The registered protocol factory may return NULL, which will cause the
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // regular "built-in" protocol factory to be used.
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                  ProtocolFactory* factory);
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Registers or unregisters a network interception class.
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void RegisterRequestInterceptor(Interceptor* interceptor);
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void UnregisterRequestInterceptor(Interceptor* interceptor);
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // handler. If |blocked| is true, the request is blocked and an error page is
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returned indicating so. This should only be called after Start is called
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and OnBeforeRequest returns true (signalling that the request should be
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // paused).
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void BeforeRequestComplete(int error);
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StartJob(URLRequestJob* job);
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restarting involves replacing the current job with a new one such as what
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // happens when following a HTTP redirect.
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RestartWithJob(URLRequestJob* job);
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void PrepareToRestart();
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Detaches the job from this request in preparation for this object going
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // away or the job being replaced. The job will not call us back when it has
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // been orphaned.
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OrphanJob();
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cancels the request and set the error and ssl info for this request to the
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // passed values.
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoCancel(int error, const SSLInfo& ssl_info);
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Called by the URLRequestJob when the headers are received, before any other
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // method, to allow caching of load timing information.
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void OnHeadersComplete();
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies the network delegate that the request has been completed.
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This does not imply a successful completion. Also a canceled request is
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // considered completed.
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyRequestCompleted();
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by URLRequestJob to allow interception when the final response
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // occurs.
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyResponseStarted();
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These functions delegate to |delegate_| and may only be used if
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |delegate_| is not NULL. See URLRequest::Delegate for the meaning
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of these functions.
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyAuthRequired(AuthChallengeInfo* auth_info);
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyAuthRequiredComplete(NetworkDelegate::AuthRequiredResponse result);
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyCertificateRequested(SSLCertRequestInfo* cert_request_info);
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifySSLCertificateError(const SSLInfo& ssl_info, bool fatal);
7262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyReadCompleted(int bytes_read);
7272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // These functions delegate to |network_delegate_| if it is not NULL.
7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If |network_delegate_| is NULL, cookies can be used unless
7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // SetDefaultCookiePolicyToBlock() has been called.
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanGetCookies(const CookieList& cookie_list) const;
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanSetCookie(const std::string& cookie_line,
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    CookieOptions* options) const;
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when the delegate blocks or unblocks this request when intercepting
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // certain requests.
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBlockedOnDelegate();
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetUnblockedOnDelegate();
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Contextual information used for this request. Cannot be NULL. This contains
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // most of the dependencies which are shared between requests (disk cache,
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookie store, socket pool, etc.)
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const URLRequestContext* context_;
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NetworkDelegate* network_delegate_;
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tracks the time spent in various load states throughout this request.
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BoundNetLog net_log_;
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<URLRequestJob> job_;
7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<UploadDataStream> upload_data_stream_;
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> url_chain_;
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL first_party_for_cookies_;
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL delegate_redirect_url_;
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string method_;  // "GET", "POST", etc. Should be all uppercase.
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string referrer_;
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ReferrerPolicy referrer_policy_;
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpRequestHeaders extra_request_headers_;
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int load_flags_;  // Flags indicating the request type for the load;
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    // expected values are LOAD_* enums above.
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Never access methods of the |delegate_| directly. Always use the
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notify... methods for this.
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Delegate* delegate_;
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Current error status of the job. When no error has been encountered, this
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will be SUCCESS. If multiple errors have been encountered, this will be
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the first non-SUCCESS status seen.
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  URLRequestStatus status_;
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The HTTP response info, lazily initialized.
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpResponseInfo response_info_;
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tells us whether the job is outstanding. This is true from the time
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start() is called to the time we dispatch RequestComplete and indicates
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // whether the job is active.
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_pending_;
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates if the request is in the process of redirecting to a new
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // location.  It is true from the time the headers complete until a
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new request begins.
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_redirecting_;
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Number of times we're willing to redirect.  Used to guard against
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // infinite redirects.
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int redirect_limit_;
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cached value for use after we've orphaned the job handling the
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // first transaction in a request involving redirects.
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UploadProgress final_upload_progress_;
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The priority level for this request.  Objects like ClientSocketPool use
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // this to determine which URLRequest to allocate sockets to first.
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RequestPriority priority_;
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(battre): The only consumer of the identifier_ is currently the
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // web request API. We need to match identifiers of requests between the
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // web request API and the web navigation API. As the URLRequest does not
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // exist when the web navigation API is triggered, the tracking probably
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // needs to be done outside of the URLRequest anyway. Therefore, this
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // identifier should be deleted here. http://crbug.com/89321
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A globally unique identifier for this request.
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const uint64 identifier_;
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True if this request is blocked waiting for the network delegate to resume
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it.
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool blocked_on_delegate_;
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // An optional parameter that provides additional information about the load
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // state. Only used with the LOAD_STATE_WAITING_FOR_DELEGATE state.
811c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 load_state_param_;
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::debug::LeakTracker<URLRequest> leak_tracker_;
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Callback passed to the network delegate to notify us when a blocked request
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is ready to be resumed or canceled.
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CompletionCallback before_request_callback_;
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Safe-guard to ensure that we do not send multiple "I am completed"
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // messages to network delegate.
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(battre): Remove this. http://crbug.com/89049
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool has_notified_completion_;
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Authentication data used by the NetworkDelegate for this request,
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if one is present. |auth_credentials_| may be filled in when calling
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |NotifyAuthRequired| on the NetworkDelegate. |auth_info_| holds
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the authentication challenge being handled by |NotifyAuthRequired|.
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AuthCredentials auth_credentials_;
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<AuthChallengeInfo> auth_info_;
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 received_response_content_length_;
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks creation_time_;
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Timing information for the most recent request.  Its start times are
8362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // populated during Start(), and the rest are populated in OnResponseReceived.
8372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LoadTimingInfo load_timing_info_;
8382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<const base::debug::StackTrace> stack_trace_;
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(URLRequest);
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_URL_REQUEST_URL_REQUEST_H_
847