Home | History | Annotate | Download | only in http
      1 // Copyright (c) 2011 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 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
      6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
      7 
      8 #include <set>
      9 #include "base/memory/scoped_ptr.h"
     10 #include "googleurl/src/gurl.h"
     11 #include "net/base/net_log.h"
     12 #include "net/http/http_stream_factory_impl.h"
     13 
     14 namespace net {
     15 
     16 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
     17  public:
     18   Request(const GURL& url,
     19           HttpStreamFactoryImpl* factory,
     20           HttpStreamRequest::Delegate* delegate,
     21           const BoundNetLog& net_log);
     22   virtual ~Request();
     23 
     24   // The GURL from the HttpRequestInfo the started the Request.
     25   const GURL& url() const { return url_; }
     26 
     27   // Called when the Job determines the appropriate |spdy_session_key| for the
     28   // Request. Note that this does not mean that SPDY is necessarily supported
     29   // for this HostPortProxyPair, since we may need to wait for NPN to complete
     30   // before knowing if SPDY is available.
     31   void SetSpdySessionKey(const HostPortProxyPair& spdy_session_key);
     32 
     33   // Attaches |job| to this request. Does not mean that Request will use |job|,
     34   // but Request will own |job|.
     35   void AttachJob(HttpStreamFactoryImpl::Job* job);
     36 
     37   // Marks completion of the request. Must be called before OnStreamReady().
     38   // |source| is the NetLog::Source generated by the Job that fulfilled this
     39   // request.
     40   void Complete(bool was_npn_negotiated,
     41                 bool using_spdy,
     42                 const NetLog::Source& source);
     43 
     44   // If this Request has a spdy_session_key, remove this session from the
     45   // SpdySessionRequestMap.
     46   void RemoveRequestFromSpdySessionRequestMap();
     47 
     48   // Called by an attached Job if it sets up a SpdySession.
     49   void OnSpdySessionReady(Job* job,
     50                           scoped_refptr<SpdySession> spdy_session,
     51                           bool direct);
     52 
     53   // HttpStreamRequest::Delegate methods which we implement. Note we don't
     54   // actually subclass HttpStreamRequest::Delegate.
     55 
     56   void OnStreamReady(Job* job,
     57                      const SSLConfig& used_ssl_config,
     58                      const ProxyInfo& used_proxy_info,
     59                      HttpStream* stream);
     60   void OnStreamFailed(Job* job, int status, const SSLConfig& used_ssl_config);
     61   void OnCertificateError(Job* job,
     62                           int status,
     63                           const SSLConfig& used_ssl_config,
     64                           const SSLInfo& ssl_info);
     65   void OnNeedsProxyAuth(Job* job,
     66                         const HttpResponseInfo& proxy_response,
     67                         const SSLConfig& used_ssl_config,
     68                         const ProxyInfo& used_proxy_info,
     69                         HttpAuthController* auth_controller);
     70   void OnNeedsClientAuth(Job* job,
     71                          const SSLConfig& used_ssl_config,
     72                          SSLCertRequestInfo* cert_info);
     73   void OnHttpsProxyTunnelResponse(
     74       Job *job,
     75       const HttpResponseInfo& response_info,
     76       const SSLConfig& used_ssl_config,
     77       const ProxyInfo& used_proxy_info,
     78       HttpStream* stream);
     79 
     80   // HttpStreamRequest methods.
     81 
     82   virtual int RestartTunnelWithProxyAuth(const string16& username,
     83                                          const string16& password);
     84   virtual LoadState GetLoadState() const;
     85   virtual bool was_npn_negotiated() const;
     86   virtual bool using_spdy() const;
     87 
     88  private:
     89   // Used to orphan all jobs in |jobs_| other than |job| which becomes "bound"
     90   // to the request.
     91   void OrphanJobsExcept(Job* job);
     92 
     93   // Used to orphan all jobs in |jobs_|.
     94   void OrphanJobs();
     95 
     96   const GURL url_;
     97   HttpStreamFactoryImpl* const factory_;
     98   HttpStreamRequest::Delegate* const delegate_;
     99   const BoundNetLog net_log_;
    100 
    101   // At the point where Job is irrevocably tied to the Request, we set this.
    102   scoped_ptr<Job> bound_job_;
    103   std::set<HttpStreamFactoryImpl::Job*> jobs_;
    104   scoped_ptr<const HostPortProxyPair> spdy_session_key_;
    105 
    106   bool completed_;
    107   bool was_npn_negotiated_;
    108   bool using_spdy_;
    109 
    110   DISALLOW_COPY_AND_ASSIGN(Request);
    111 };
    112 
    113 }  // namespace net
    114 
    115 #endif  // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
    116