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" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/mru_cache.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "net/http/http_pipelined_host.h" | 15 #include "net/http/http_pipelined_host.h" |
15 #include "net/http/http_pipelined_host_capability.h" | |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 class HostPortPair; | 19 class HostPortPair; |
20 class HttpPipelinedStream; | 20 class HttpPipelinedStream; |
21 class HttpServerProperties; | |
22 | 21 |
23 // 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 |
24 // HTTP requests. Manages connection jobs, constructs pipelined streams, and | 23 // HTTP requests. Manages connection jobs, constructs pipelined streams, and |
25 // assigns requests to the least loaded pipelined connection. | 24 // assigns requests to the least loaded pipelined connection. |
26 class NET_EXPORT_PRIVATE HttpPipelinedHostPool | 25 class NET_EXPORT_PRIVATE HttpPipelinedHostPool |
27 : public HttpPipelinedHost::Delegate { | 26 : public HttpPipelinedHost::Delegate { |
28 public: | 27 public: |
29 class Delegate { | 28 class Delegate { |
30 public: | 29 public: |
31 // Called when a HttpPipelinedHost has new capacity. Attempts to allocate | 30 // Called when a HttpPipelinedHost has new capacity. Attempts to allocate |
32 // any pending pipeline-capable requests to pipelines. | 31 // any pending pipeline-capable requests to pipelines. |
33 virtual void OnHttpPipelinedHostHasAdditionalCapacity( | 32 virtual void OnHttpPipelinedHostHasAdditionalCapacity( |
34 const HostPortPair& origin) = 0; | 33 const HostPortPair& origin) = 0; |
35 }; | 34 }; |
36 | 35 |
37 HttpPipelinedHostPool(Delegate* delegate, | 36 HttpPipelinedHostPool(Delegate* delegate, |
38 HttpPipelinedHost::Factory* factory, | 37 HttpPipelinedHost::Factory* factory); |
39 HttpServerProperties* http_server_properties_); | |
40 virtual ~HttpPipelinedHostPool(); | 38 virtual ~HttpPipelinedHostPool(); |
41 | 39 |
42 // Returns true if pipelining might work for |origin|. Generally, this returns | 40 // Returns true if pipelining might work for |origin|. Generally, this returns |
43 // true, unless |origin| is known to have failed pipelining recently. | 41 // true, unless |origin| is known to have failed pipelining recently. |
44 bool IsHostEligibleForPipelining(const HostPortPair& origin); | 42 bool IsHostEligibleForPipelining(const HostPortPair& origin); |
45 | 43 |
46 // Constructs a new pipeline on |connection| and returns a new | 44 // Constructs a new pipeline on |connection| and returns a new |
47 // HttpPipelinedStream that uses it. | 45 // HttpPipelinedStream that uses it. |
48 HttpPipelinedStream* CreateStreamOnNewPipeline( | 46 HttpPipelinedStream* CreateStreamOnNewPipeline( |
49 const HostPortPair& origin, | 47 const HostPortPair& origin, |
(...skipping 12 matching lines...) Expand all Loading... |
62 // can accept new requests. | 60 // can accept new requests. |
63 bool IsExistingPipelineAvailableForOrigin(const HostPortPair& origin); | 61 bool IsExistingPipelineAvailableForOrigin(const HostPortPair& origin); |
64 | 62 |
65 // Callbacks for HttpPipelinedHost. | 63 // Callbacks for HttpPipelinedHost. |
66 virtual void OnHostIdle(HttpPipelinedHost* host) OVERRIDE; | 64 virtual void OnHostIdle(HttpPipelinedHost* host) OVERRIDE; |
67 | 65 |
68 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) OVERRIDE; | 66 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) OVERRIDE; |
69 | 67 |
70 virtual void OnHostDeterminedCapability( | 68 virtual void OnHostDeterminedCapability( |
71 HttpPipelinedHost* host, | 69 HttpPipelinedHost* host, |
72 HttpPipelinedHostCapability capability) OVERRIDE; | 70 HttpPipelinedHost::Capability capability) OVERRIDE; |
73 | 71 |
74 private: | 72 private: |
| 73 typedef base::MRUCache<HostPortPair, |
| 74 HttpPipelinedHost::Capability> CapabilityMap; |
75 typedef std::map<const HostPortPair, HttpPipelinedHost*> HostMap; | 75 typedef std::map<const HostPortPair, HttpPipelinedHost*> HostMap; |
76 | 76 |
77 HttpPipelinedHost* GetPipelinedHost(const HostPortPair& origin, | 77 HttpPipelinedHost* GetPipelinedHost(const HostPortPair& origin, |
78 bool create_if_not_found); | 78 bool create_if_not_found); |
79 | 79 |
| 80 HttpPipelinedHost::Capability GetHostCapability(const HostPortPair& origin); |
| 81 |
80 Delegate* delegate_; | 82 Delegate* delegate_; |
81 scoped_ptr<HttpPipelinedHost::Factory> factory_; | 83 scoped_ptr<HttpPipelinedHost::Factory> factory_; |
82 HostMap host_map_; | 84 HostMap host_map_; |
83 HttpServerProperties* http_server_properties_; | 85 CapabilityMap known_capability_map_; |
84 | 86 |
85 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool); | 87 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool); |
86 }; | 88 }; |
87 | 89 |
88 } // namespace net | 90 } // namespace net |
89 | 91 |
90 #endif // NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ | 92 #endif // NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_ |
OLD | NEW |