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_
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/http/http_pipelined_host.h"
14 #include "net/http/http_pipelined_host_capability.h"
23 class HttpPipelinedStream
;
24 class HttpServerProperties
;
26 // Manages all of the pipelining state for specific host with active pipelined
27 // HTTP requests. Manages connection jobs, constructs pipelined streams, and
28 // assigns requests to the least loaded pipelined connection.
29 class NET_EXPORT_PRIVATE HttpPipelinedHostPool
30 : public HttpPipelinedHost::Delegate
{
34 // Called when a HttpPipelinedHost has new capacity. Attempts to allocate
35 // any pending pipeline-capable requests to pipelines.
36 virtual void OnHttpPipelinedHostHasAdditionalCapacity(
37 HttpPipelinedHost
* host
) = 0;
40 HttpPipelinedHostPool(Delegate
* delegate
,
41 HttpPipelinedHost::Factory
* factory
,
42 HttpServerProperties
* http_server_properties_
,
43 bool force_pipelining
);
44 virtual ~HttpPipelinedHostPool();
46 // Returns true if pipelining might work for |key|. Generally, this returns
47 // true, unless |key| is known to have failed pipelining recently.
48 bool IsKeyEligibleForPipelining(const HttpPipelinedHost::Key
& key
);
50 // Constructs a new pipeline on |connection| and returns a new
51 // HttpPipelinedStream that uses it.
52 HttpPipelinedStream
* CreateStreamOnNewPipeline(
53 const HttpPipelinedHost::Key
& key
,
54 ClientSocketHandle
* connection
,
55 const SSLConfig
& used_ssl_config
,
56 const ProxyInfo
& used_proxy_info
,
57 const BoundNetLog
& net_log
,
58 bool was_npn_negotiated
,
59 NextProto protocol_negotiated
);
61 // Tries to find an existing pipeline with capacity for a new request. If
62 // successful, returns a new stream on that pipeline. Otherwise, returns NULL.
63 HttpPipelinedStream
* CreateStreamOnExistingPipeline(
64 const HttpPipelinedHost::Key
& key
);
66 // Returns true if a pipelined connection already exists for |key| and
67 // can accept new requests.
68 bool IsExistingPipelineAvailableForKey(const HttpPipelinedHost::Key
& key
);
70 // Callbacks for HttpPipelinedHost.
71 virtual void OnHostIdle(HttpPipelinedHost
* host
) OVERRIDE
;
73 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost
* host
) OVERRIDE
;
75 virtual void OnHostDeterminedCapability(
76 HttpPipelinedHost
* host
,
77 HttpPipelinedHostCapability capability
) OVERRIDE
;
79 // Creates a Value summary of this pool's |host_map_|. Caller assumes
80 // ownership of the returned Value.
81 base::Value
* PipelineInfoToValue() const;
84 typedef std::map
<HttpPipelinedHost::Key
, HttpPipelinedHost
*> HostMap
;
86 HttpPipelinedHost
* GetPipelinedHost(const HttpPipelinedHost::Key
& key
,
87 bool create_if_not_found
);
90 scoped_ptr
<HttpPipelinedHost::Factory
> factory_
;
92 HttpServerProperties
* http_server_properties_
;
93 bool force_pipelining_
;
95 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostPool
);
100 #endif // NET_HTTP_HTTP_PIPELINED_HOST_POOL_H_