OLD | NEW |
(Empty) | |
| 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_PIPELINED_HOST_H_ |
| 6 #define NET_HTTP_HTTP_PIPELINED_HOST_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "base/compiler_specific.h" |
| 13 #include "net/base/host_port_pair.h" |
| 14 #include "net/http/http_pipelined_connection.h" |
| 15 |
| 16 namespace net { |
| 17 |
| 18 class BoundNetLog; |
| 19 class ClientSocketHandle; |
| 20 class ProxyInfo; |
| 21 class SSLConfig; |
| 22 |
| 23 // Manages all of the pipelining state for specific host with active pipelined |
| 24 // HTTP requests. Manages connection jobs, constructs pipelined streams, and |
| 25 // assigns requests to the least loaded pipelined connection. |
| 26 class NET_EXPORT_PRIVATE HttpPipelinedHost |
| 27 : public HttpPipelinedConnection::Delegate { |
| 28 public: |
| 29 class Delegate { |
| 30 public: |
| 31 // Called when a pipelined host has no outstanding requests on any of its |
| 32 // pipelined connections. |
| 33 virtual void OnHostIdle(HttpPipelinedHost* host) = 0; |
| 34 |
| 35 // Called when a pipelined host has newly available pipeline capacity, like |
| 36 // when a request completes. |
| 37 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0; |
| 38 }; |
| 39 |
| 40 HttpPipelinedHost(Delegate* delegate, const HostPortPair& origin, |
| 41 HttpPipelinedConnection::Factory* factory); |
| 42 ~HttpPipelinedHost(); |
| 43 |
| 44 // Returns a new HttpPipelinedConnection registered with this Host. |
| 45 HttpPipelinedConnection* CreateNewPipeline(ClientSocketHandle* connection, |
| 46 const SSLConfig& used_ssl_config, |
| 47 const ProxyInfo& used_proxy_info, |
| 48 const BoundNetLog& net_log, |
| 49 bool was_npn_negotiated); |
| 50 |
| 51 // Returns the pipeline that is best to use for a new request and still has |
| 52 // additional capacity. If there are no pipelines that can accept a new |
| 53 // request, then NULL is returned. |
| 54 HttpPipelinedConnection* FindAvailablePipeline(); |
| 55 |
| 56 // Callbacks for HttpPipelinedConnection. |
| 57 |
| 58 // Called when a pipelined connection completes a request. Adds a pending |
| 59 // request to the pipeline if the pipeline is still usable. |
| 60 virtual void OnPipelineHasCapacity( |
| 61 HttpPipelinedConnection* pipeline) OVERRIDE; |
| 62 |
| 63 const HostPortPair& origin() const { return origin_; } |
| 64 |
| 65 private: |
| 66 // Called when a pipeline is empty and there are no pending requests. Closes |
| 67 // the connection. |
| 68 void OnPipelineEmpty(HttpPipelinedConnection* pipeline); |
| 69 |
| 70 // Adds the next pending request to the pipeline if it's still usuable. |
| 71 void AddRequestToPipeline(HttpPipelinedConnection* connection); |
| 72 |
| 73 int max_pipeline_depth() const { return 3; } |
| 74 |
| 75 Delegate* delegate_; |
| 76 const HostPortPair origin_; |
| 77 std::set<HttpPipelinedConnection*> pipelines_; |
| 78 HttpPipelinedConnection::Factory* factory_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHost); |
| 81 }; |
| 82 |
| 83 } // namespace net |
| 84 |
| 85 #endif // NET_HTTP_HTTP_PIPELINED_HOST_H_ |
OLD | NEW |