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_POOL_H_ | 5 #ifndef NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ |
6 #define NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ | 6 #define NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/mru_cache.h" |
| 14 #include "base/memory/scoped_ptr.h" |
12 #include "net/http/http_pipelined_host.h" | 15 #include "net/http/http_pipelined_host.h" |
13 | 16 |
14 namespace net { | 17 namespace net { |
15 | 18 |
16 class HostPortPair; | 19 class HostPortPair; |
17 class HttpPipelinedStream; | 20 class HttpPipelinedStream; |
18 class HttpStreamFactoryImpl; | |
19 | 21 |
20 // Manages all of the pipelining state for specific host with active pipelined | 22 // Manages all of the pipelining state for specific host with active pipelined |
21 // HTTP requests. Manages connection jobs, constructs pipelined streams, and | 23 // HTTP requests. Manages connection jobs, constructs pipelined streams, and |
22 // assigns requests to the least loaded pipelined connection. | 24 // assigns requests to the least loaded pipelined connection. |
23 class HttpPipelinedHostPool : public HttpPipelinedHost::Delegate { | 25 class NET_EXPORT_PRIVATE HttpPipelinedHostPool |
| 26 : public HttpPipelinedHost::Delegate { |
24 public: | 27 public: |
25 explicit HttpPipelinedHostPool(HttpStreamFactoryImpl* factory); | 28 class Delegate { |
26 ~HttpPipelinedHostPool(); | 29 public: |
| 30 // Called when a HttpPipelinedHost has new capacity. Attempts to allocate |
| 31 // any pending pipeline-capable requests to pipelines. |
| 32 virtual void OnHttpPipelinedHostHasAdditionalCapacity( |
| 33 const HostPortPair& origin) = 0; |
| 34 }; |
| 35 |
| 36 HttpPipelinedHostPool(Delegate* delegate, |
| 37 HttpPipelinedHost::Factory* factory); |
| 38 virtual ~HttpPipelinedHostPool(); |
| 39 |
| 40 // Returns true if pipelining might work for |origin|. Generally, this returns |
| 41 // true, unless |origin| is known to have failed pipelining recently. |
| 42 bool IsHostEligibleForPipelining(const HostPortPair& origin); |
27 | 43 |
28 // Constructs a new pipeline on |connection| and returns a new | 44 // Constructs a new pipeline on |connection| and returns a new |
29 // HttpPipelinedStream that uses it. | 45 // HttpPipelinedStream that uses it. |
30 HttpPipelinedStream* CreateStreamOnNewPipeline( | 46 HttpPipelinedStream* CreateStreamOnNewPipeline( |
31 const HostPortPair& origin, | 47 const HostPortPair& origin, |
32 ClientSocketHandle* connection, | 48 ClientSocketHandle* connection, |
33 const SSLConfig& used_ssl_config, | 49 const SSLConfig& used_ssl_config, |
34 const ProxyInfo& used_proxy_info, | 50 const ProxyInfo& used_proxy_info, |
35 const BoundNetLog& net_log, | 51 const BoundNetLog& net_log, |
36 bool was_npn_negotiated); | 52 bool was_npn_negotiated); |
37 | 53 |
38 // Tries to find an existing pipeline with capacity for a new request. If | 54 // Tries to find an existing pipeline with capacity for a new request. If |
39 // successful, returns a new stream on that pipeline. Otherwise, returns NULL. | 55 // successful, returns a new stream on that pipeline. Otherwise, returns NULL. |
40 HttpPipelinedStream* CreateStreamOnExistingPipeline( | 56 HttpPipelinedStream* CreateStreamOnExistingPipeline( |
41 const HostPortPair& origin); | 57 const HostPortPair& origin); |
42 | 58 |
43 // Returns true if a pipelined connection already exists for this origin and | 59 // Returns true if a pipelined connection already exists for this origin and |
44 // can accept new requests. | 60 // can accept new requests. |
45 bool IsExistingPipelineAvailableForOrigin(const HostPortPair& origin); | 61 bool IsExistingPipelineAvailableForOrigin(const HostPortPair& origin); |
46 | 62 |
47 // Callbacks for HttpPipelinedHost. | 63 // Callbacks for HttpPipelinedHost. |
48 virtual void OnHostIdle(HttpPipelinedHost* host) OVERRIDE; | 64 virtual void OnHostIdle(HttpPipelinedHost* host) OVERRIDE; |
49 | 65 |
50 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) OVERRIDE; | 66 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) OVERRIDE; |
51 | 67 |
| 68 virtual void OnHostDeterminedCapability( |
| 69 HttpPipelinedHost* host, |
| 70 HttpPipelinedHost::Capability capability) OVERRIDE; |
| 71 |
52 private: | 72 private: |
| 73 typedef base::MRUCache<HostPortPair, |
| 74 HttpPipelinedHost::Capability> CapabilityMap; |
53 typedef std::map<const HostPortPair, HttpPipelinedHost*> HostMap; | 75 typedef std::map<const HostPortPair, HttpPipelinedHost*> HostMap; |
54 | 76 |
55 HttpPipelinedHost* GetPipelinedHost(const HostPortPair& origin, | 77 HttpPipelinedHost* GetPipelinedHost(const HostPortPair& origin, |
56 bool create_if_not_found); | 78 bool create_if_not_found); |
57 | 79 |
58 HttpStreamFactoryImpl* factory_; | 80 HttpPipelinedHost::Capability GetHostCapability(const HostPortPair& origin); |
| 81 |
| 82 Delegate* delegate_; |
| 83 scoped_ptr<HttpPipelinedHost::Factory> factory_; |
59 HostMap host_map_; | 84 HostMap host_map_; |
| 85 CapabilityMap known_capability_map_; |
60 | 86 |
61 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool); | 87 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool); |
62 }; | 88 }; |
63 | 89 |
64 } // namespace net | 90 } // namespace net |
65 | 91 |
66 #endif // NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ | 92 #endif // NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ |
OLD | NEW |