| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_HTTP_HTTP_PIPELINED_HOST_H_ | 5 #ifndef NET_HTTP_HTTP_PIPELINED_HOST_H_ |
| 6 #define NET_HTTP_HTTP_PIPELINED_HOST_H_ | 6 #define NET_HTTP_HTTP_PIPELINED_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| 16 #include "net/http/http_pipelined_connection.h" | 11 #include "net/http/http_pipelined_connection.h" |
| 17 | 12 |
| 18 namespace net { | 13 namespace net { |
| 19 | 14 |
| 20 class BoundNetLog; | 15 class BoundNetLog; |
| 21 class ClientSocketHandle; | 16 class ClientSocketHandle; |
| 22 class HttpPipelinedStream; | 17 class HttpPipelinedStream; |
| 23 class ProxyInfo; | 18 class ProxyInfo; |
| 24 struct SSLConfig; | 19 struct SSLConfig; |
| 25 | 20 |
| 26 // Manages all of the pipelining state for specific host with active pipelined | 21 // Manages all of the pipelining state for specific host with active pipelined |
| 27 // HTTP requests. Manages connection jobs, constructs pipelined streams, and | 22 // HTTP requests. Manages connection jobs, constructs pipelined streams, and |
| 28 // assigns requests to the least loaded pipelined connection. | 23 // assigns requests to the least loaded pipelined connection. |
| 29 class NET_EXPORT_PRIVATE HttpPipelinedHost | 24 class NET_EXPORT_PRIVATE HttpPipelinedHost { |
| 30 : public HttpPipelinedConnection::Delegate { | |
| 31 public: | 25 public: |
| 26 enum Capability { |
| 27 UNKNOWN, |
| 28 INCAPABLE, |
| 29 CAPABLE, |
| 30 }; |
| 31 |
| 32 class Delegate { | 32 class Delegate { |
| 33 public: | 33 public: |
| 34 // Called when a pipelined host has no outstanding requests on any of its | 34 // Called when a pipelined host has no outstanding requests on any of its |
| 35 // pipelined connections. | 35 // pipelined connections. |
| 36 virtual void OnHostIdle(HttpPipelinedHost* host) = 0; | 36 virtual void OnHostIdle(HttpPipelinedHost* host) = 0; |
| 37 | 37 |
| 38 // Called when a pipelined host has newly available pipeline capacity, like | 38 // Called when a pipelined host has newly available pipeline capacity, like |
| 39 // when a request completes. | 39 // when a request completes. |
| 40 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0; | 40 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0; |
| 41 |
| 42 // Called when a host determines if pipelining can be used. |
| 43 virtual void OnHostDeterminedCapability(HttpPipelinedHost* host, |
| 44 Capability capability) = 0; |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 HttpPipelinedHost(Delegate* delegate, const HostPortPair& origin, | 47 class Factory { |
| 44 HttpPipelinedConnection::Factory* factory); | 48 public: |
| 45 virtual ~HttpPipelinedHost(); | 49 virtual ~Factory() {} |
| 50 |
| 51 // Returns a new HttpPipelinedHost. |
| 52 virtual HttpPipelinedHost* CreateNewHost( |
| 53 Delegate* delegate, const HostPortPair& origin, |
| 54 HttpPipelinedConnection::Factory* factory, |
| 55 Capability capability) = 0; |
| 56 }; |
| 57 |
| 58 virtual ~HttpPipelinedHost() {} |
| 46 | 59 |
| 47 // Constructs a new pipeline on |connection| and returns a new | 60 // Constructs a new pipeline on |connection| and returns a new |
| 48 // HttpPipelinedStream that uses it. | 61 // HttpPipelinedStream that uses it. |
| 49 HttpPipelinedStream* CreateStreamOnNewPipeline( | 62 virtual HttpPipelinedStream* CreateStreamOnNewPipeline( |
| 50 ClientSocketHandle* connection, | 63 ClientSocketHandle* connection, |
| 51 const SSLConfig& used_ssl_config, | 64 const SSLConfig& used_ssl_config, |
| 52 const ProxyInfo& used_proxy_info, | 65 const ProxyInfo& used_proxy_info, |
| 53 const BoundNetLog& net_log, | 66 const BoundNetLog& net_log, |
| 54 bool was_npn_negotiated); | 67 bool was_npn_negotiated) = 0; |
| 55 | 68 |
| 56 // Tries to find an existing pipeline with capacity for a new request. If | 69 // Tries to find an existing pipeline with capacity for a new request. If |
| 57 // successful, returns a new stream on that pipeline. Otherwise, returns NULL. | 70 // successful, returns a new stream on that pipeline. Otherwise, returns NULL. |
| 58 HttpPipelinedStream* CreateStreamOnExistingPipeline(); | 71 virtual HttpPipelinedStream* CreateStreamOnExistingPipeline() = 0; |
| 59 | 72 |
| 60 // Returns true if we have a pipelined connection that can accept new | 73 // Returns true if we have a pipelined connection that can accept new |
| 61 // requests. | 74 // requests. |
| 62 bool IsExistingPipelineAvailable(); | 75 virtual bool IsExistingPipelineAvailable() = 0; |
| 63 | 76 |
| 64 // Callbacks for HttpPipelinedConnection. | 77 // Returns the host and port associated with this class. |
| 65 | 78 virtual const HostPortPair& origin() const = 0; |
| 66 // Called when a pipelined connection completes a request. Adds a pending | |
| 67 // request to the pipeline if the pipeline is still usable. | |
| 68 virtual void OnPipelineHasCapacity( | |
| 69 HttpPipelinedConnection* pipeline) OVERRIDE; | |
| 70 | |
| 71 const HostPortPair& origin() const { return origin_; } | |
| 72 | |
| 73 private: | |
| 74 // Called when a pipeline is empty and there are no pending requests. Closes | |
| 75 // the connection. | |
| 76 void OnPipelineEmpty(HttpPipelinedConnection* pipeline); | |
| 77 | |
| 78 // Adds the next pending request to the pipeline if it's still usuable. | |
| 79 void AddRequestToPipeline(HttpPipelinedConnection* connection); | |
| 80 | |
| 81 int max_pipeline_depth() const { return 3; } | |
| 82 | |
| 83 Delegate* delegate_; | |
| 84 const HostPortPair origin_; | |
| 85 std::set<HttpPipelinedConnection*> pipelines_; | |
| 86 scoped_ptr<HttpPipelinedConnection::Factory> factory_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHost); | |
| 89 }; | 79 }; |
| 90 | 80 |
| 91 } // namespace net | 81 } // namespace net |
| 92 | 82 |
| 93 #endif // NET_HTTP_HTTP_PIPELINED_HOST_H_ | 83 #endif // NET_HTTP_HTTP_PIPELINED_HOST_H_ |
| OLD | NEW |