Move AsyncPolicyProvider, etc. to components/policy/.
[chromium-blink-merge.git] / net / http / http_pipelined_host_pool.h
blob45cb38cedf60d97a37ac0dc3a2c29227ddaf68b6
1 // Copyright (c) 2012 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.
5 #ifndef NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_
6 #define NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "net/http/http_pipelined_host.h"
15 #include "net/http/http_pipelined_host_capability.h"
17 namespace base {
18 class Value;
21 namespace net {
23 class HostPortPair;
24 class HttpPipelinedStream;
25 class HttpServerProperties;
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 HttpPipelinedHostPool
31 : public HttpPipelinedHost::Delegate {
32 public:
33 class Delegate {
34 public:
35 // Called when a HttpPipelinedHost has new capacity. Attempts to allocate
36 // any pending pipeline-capable requests to pipelines.
37 virtual void OnHttpPipelinedHostHasAdditionalCapacity(
38 HttpPipelinedHost* host) = 0;
41 HttpPipelinedHostPool(
42 Delegate* delegate,
43 HttpPipelinedHost::Factory* factory,
44 const base::WeakPtr<HttpServerProperties>& http_server_properties,
45 bool force_pipelining);
46 virtual ~HttpPipelinedHostPool();
48 // Returns true if pipelining might work for |key|. Generally, this returns
49 // true, unless |key| is known to have failed pipelining recently.
50 bool IsKeyEligibleForPipelining(const HttpPipelinedHost::Key& key);
52 // Constructs a new pipeline on |connection| and returns a new
53 // HttpPipelinedStream that uses it.
54 HttpPipelinedStream* CreateStreamOnNewPipeline(
55 const HttpPipelinedHost::Key& key,
56 ClientSocketHandle* connection,
57 const SSLConfig& used_ssl_config,
58 const ProxyInfo& used_proxy_info,
59 const BoundNetLog& net_log,
60 bool was_npn_negotiated,
61 NextProto protocol_negotiated);
63 // Tries to find an existing pipeline with capacity for a new request. If
64 // successful, returns a new stream on that pipeline. Otherwise, returns NULL.
65 HttpPipelinedStream* CreateStreamOnExistingPipeline(
66 const HttpPipelinedHost::Key& key);
68 // Returns true if a pipelined connection already exists for |key| and
69 // can accept new requests.
70 bool IsExistingPipelineAvailableForKey(const HttpPipelinedHost::Key& key);
72 // Callbacks for HttpPipelinedHost.
73 virtual void OnHostIdle(HttpPipelinedHost* host) OVERRIDE;
75 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) OVERRIDE;
77 virtual void OnHostDeterminedCapability(
78 HttpPipelinedHost* host,
79 HttpPipelinedHostCapability capability) OVERRIDE;
81 // Creates a Value summary of this pool's |host_map_|. Caller assumes
82 // ownership of the returned Value.
83 base::Value* PipelineInfoToValue() const;
85 private:
86 typedef std::map<HttpPipelinedHost::Key, HttpPipelinedHost*> HostMap;
88 HttpPipelinedHost* GetPipelinedHost(const HttpPipelinedHost::Key& key,
89 bool create_if_not_found);
91 Delegate* delegate_;
92 scoped_ptr<HttpPipelinedHost::Factory> factory_;
93 HostMap host_map_;
94 const base::WeakPtr<HttpServerProperties> http_server_properties_;
95 bool force_pipelining_;
97 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool);
100 } // namespace net
102 #endif // NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_