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_IMPL_H_ |
| 6 #define NET_HTTP_HTTP_PIPELINED_HOST_IMPL_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_export.h" |
| 16 #include "net/http/http_pipelined_connection.h" |
| 17 #include "net/http/http_pipelined_host.h" |
| 18 |
| 19 namespace net { |
| 20 |
| 21 class BoundNetLog; |
| 22 class ClientSocketHandle; |
| 23 class HttpPipelinedStream; |
| 24 class ProxyInfo; |
| 25 struct SSLConfig; |
| 26 |
| 27 // Manages all of the pipelining state for specific host with active pipelined |
| 28 // HTTP requests. Manages connection jobs, constructs pipelined streams, and |
| 29 // assigns requests to the least loaded pipelined connection. |
| 30 class NET_EXPORT_PRIVATE HttpPipelinedHostImpl |
| 31 : public HttpPipelinedHost, |
| 32 public HttpPipelinedConnection::Delegate { |
| 33 public: |
| 34 HttpPipelinedHostImpl(HttpPipelinedHost::Delegate* delegate, |
| 35 const HostPortPair& origin, |
| 36 HttpPipelinedConnection::Factory* factory, |
| 37 Capability capability); |
| 38 virtual ~HttpPipelinedHostImpl(); |
| 39 |
| 40 // HttpPipelinedHost interface |
| 41 virtual HttpPipelinedStream* CreateStreamOnNewPipeline( |
| 42 ClientSocketHandle* connection, |
| 43 const SSLConfig& used_ssl_config, |
| 44 const ProxyInfo& used_proxy_info, |
| 45 const BoundNetLog& net_log, |
| 46 bool was_npn_negotiated) OVERRIDE; |
| 47 |
| 48 virtual HttpPipelinedStream* CreateStreamOnExistingPipeline() OVERRIDE; |
| 49 |
| 50 virtual bool IsExistingPipelineAvailable() const OVERRIDE; |
| 51 |
| 52 // HttpPipelinedConnection::Delegate interface |
| 53 |
| 54 // Called when a pipelined connection completes a request. Adds a pending |
| 55 // request to the pipeline if the pipeline is still usable. |
| 56 virtual void OnPipelineHasCapacity( |
| 57 HttpPipelinedConnection* pipeline) OVERRIDE; |
| 58 |
| 59 virtual void OnPipelineFeedback( |
| 60 HttpPipelinedConnection* pipeline, |
| 61 HttpPipelinedConnection::Feedback feedback) OVERRIDE; |
| 62 |
| 63 virtual const HostPortPair& origin() const OVERRIDE; |
| 64 |
| 65 // Returns the maximum number of in-flight pipelined requests we'll allow on a |
| 66 // single connection. |
| 67 NET_EXPORT_PRIVATE static int max_pipeline_depth() { return 3; } |
| 68 |
| 69 private: |
| 70 struct PipelineInfo { |
| 71 PipelineInfo(); |
| 72 |
| 73 int num_successes; |
| 74 }; |
| 75 typedef std::map<HttpPipelinedConnection*, PipelineInfo> PipelineInfoMap; |
| 76 |
| 77 // Called when a pipeline is empty and there are no pending requests. Closes |
| 78 // the connection. |
| 79 void OnPipelineEmpty(HttpPipelinedConnection* pipeline); |
| 80 |
| 81 // Adds the next pending request to the pipeline if it's still usuable. |
| 82 void AddRequestToPipeline(HttpPipelinedConnection* connection); |
| 83 |
| 84 // Returns the current pipeline capacity based on |capability_|. This should |
| 85 // not be called if |capability_| is INCAPABLE. |
| 86 int GetPipelineCapacity() const; |
| 87 |
| 88 HttpPipelinedHost::Delegate* delegate_; |
| 89 const HostPortPair origin_; |
| 90 PipelineInfoMap pipelines_; |
| 91 scoped_ptr<HttpPipelinedConnection::Factory> factory_; |
| 92 Capability capability_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostImpl); |
| 95 }; |
| 96 |
| 97 } // namespace net |
| 98 |
| 99 #endif // NET_HTTP_HTTP_PIPELINED_HOST_IMPL_H_ |
OLD | NEW |