Home | History | Annotate | Download | only in http
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_HTTP_HTTP_PIPELINED_HOST_H_
      6 #define NET_HTTP_HTTP_PIPELINED_HOST_H_
      7 
      8 #include "net/base/host_port_pair.h"
      9 #include "net/base/net_export.h"
     10 #include "net/http/http_pipelined_connection.h"
     11 #include "net/http/http_pipelined_host_capability.h"
     12 
     13 namespace base {
     14 class Value;
     15 }
     16 
     17 namespace net {
     18 
     19 class BoundNetLog;
     20 class ClientSocketHandle;
     21 class HostPortPair;
     22 class HttpPipelinedStream;
     23 class ProxyInfo;
     24 struct SSLConfig;
     25 
     26 // Manages all of the pipelining state for specific host with active pipelined
     27 // HTTP requests. Manages connection jobs, constructs pipelined streams, and
     28 // assigns requests to the least loaded pipelined connection.
     29 class NET_EXPORT_PRIVATE HttpPipelinedHost {
     30  public:
     31   class NET_EXPORT_PRIVATE Key {
     32    public:
     33     Key(const HostPortPair& origin);
     34 
     35     // The host and port associated with this key.
     36     const HostPortPair& origin() const { return origin_; }
     37 
     38     bool operator<(const Key& rhs) const;
     39 
     40    private:
     41     const HostPortPair origin_;
     42   };
     43 
     44   class Delegate {
     45    public:
     46     // Called when a pipelined host has no outstanding requests on any of its
     47     // pipelined connections.
     48     virtual void OnHostIdle(HttpPipelinedHost* host) = 0;
     49 
     50     // Called when a pipelined host has newly available pipeline capacity, like
     51     // when a request completes.
     52     virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0;
     53 
     54     // Called when a host determines if pipelining can be used.
     55     virtual void OnHostDeterminedCapability(
     56         HttpPipelinedHost* host,
     57         HttpPipelinedHostCapability capability) = 0;
     58   };
     59 
     60   class Factory {
     61    public:
     62     virtual ~Factory() {}
     63 
     64     // Returns a new HttpPipelinedHost.
     65     virtual HttpPipelinedHost* CreateNewHost(
     66         Delegate* delegate, const Key& key,
     67         HttpPipelinedConnection::Factory* factory,
     68         HttpPipelinedHostCapability capability,
     69         bool force_pipelining) = 0;
     70   };
     71 
     72   virtual ~HttpPipelinedHost() {}
     73 
     74   // Constructs a new pipeline on |connection| and returns a new
     75   // HttpPipelinedStream that uses it.
     76   virtual HttpPipelinedStream* CreateStreamOnNewPipeline(
     77       ClientSocketHandle* connection,
     78       const SSLConfig& used_ssl_config,
     79       const ProxyInfo& used_proxy_info,
     80       const BoundNetLog& net_log,
     81       bool was_npn_negotiated,
     82       NextProto protocol_negotiated) = 0;
     83 
     84   // Tries to find an existing pipeline with capacity for a new request. If
     85   // successful, returns a new stream on that pipeline. Otherwise, returns NULL.
     86   virtual HttpPipelinedStream* CreateStreamOnExistingPipeline() = 0;
     87 
     88   // Returns true if we have a pipelined connection that can accept new
     89   // requests.
     90   virtual bool IsExistingPipelineAvailable() const = 0;
     91 
     92   // Returns a Key that uniquely identifies this host.
     93   virtual const Key& GetKey() const = 0;
     94 
     95   // Creates a Value summary of this host's pipelines. Caller assumes
     96   // ownership of the returned Value.
     97   virtual base::Value* PipelineInfoToValue() const = 0;
     98 };
     99 
    100 }  // namespace net
    101 
    102 #endif  // NET_HTTP_HTTP_PIPELINED_HOST_H_
    103