Update include paths in miscellaneous content/ directories for base/process changes.
[chromium-blink-merge.git] / net / http / http_pipelined_host_impl.h
blobe2e53c93c3798c1bc039a52dcea04de85ed719b2
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_IMPL_H_
6 #define NET_HTTP_HTTP_PIPELINED_HOST_IMPL_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/host_port_pair.h"
14 #include "net/base/net_export.h"
15 #include "net/http/http_pipelined_connection.h"
16 #include "net/http/http_pipelined_host.h"
17 #include "net/http/http_pipelined_host_capability.h"
19 namespace base {
20 class Value;
23 namespace net {
25 class BoundNetLog;
26 class ClientSocketHandle;
27 class HttpPipelinedStream;
28 class ProxyInfo;
29 struct SSLConfig;
31 // Manages all of the pipelining state for specific host with active pipelined
32 // HTTP requests. Manages connection jobs, constructs pipelined streams, and
33 // assigns requests to the least loaded pipelined connection.
34 class NET_EXPORT_PRIVATE HttpPipelinedHostImpl
35 : public HttpPipelinedHost,
36 public HttpPipelinedConnection::Delegate {
37 public:
38 HttpPipelinedHostImpl(HttpPipelinedHost::Delegate* delegate,
39 const HttpPipelinedHost::Key& key,
40 HttpPipelinedConnection::Factory* factory,
41 HttpPipelinedHostCapability capability);
42 virtual ~HttpPipelinedHostImpl();
44 // HttpPipelinedHost interface
45 virtual HttpPipelinedStream* CreateStreamOnNewPipeline(
46 ClientSocketHandle* connection,
47 const SSLConfig& used_ssl_config,
48 const ProxyInfo& used_proxy_info,
49 const BoundNetLog& net_log,
50 bool was_npn_negotiated,
51 NextProto protocol_negotiated) OVERRIDE;
53 virtual HttpPipelinedStream* CreateStreamOnExistingPipeline() OVERRIDE;
55 virtual bool IsExistingPipelineAvailable() const OVERRIDE;
57 // HttpPipelinedConnection::Delegate interface
59 // Called when a pipelined connection completes a request. Adds a pending
60 // request to the pipeline if the pipeline is still usable.
61 virtual void OnPipelineHasCapacity(
62 HttpPipelinedConnection* pipeline) OVERRIDE;
64 virtual void OnPipelineFeedback(
65 HttpPipelinedConnection* pipeline,
66 HttpPipelinedConnection::Feedback feedback) OVERRIDE;
68 virtual const Key& GetKey() const OVERRIDE;
70 // Creates a Value summary of this host's |pipelines_|. Caller assumes
71 // ownership of the returned Value.
72 virtual base::Value* PipelineInfoToValue() const OVERRIDE;
74 // Returns the maximum number of in-flight pipelined requests we'll allow on a
75 // single connection.
76 static int max_pipeline_depth() { return 3; }
78 private:
79 struct PipelineInfo {
80 PipelineInfo();
82 int num_successes;
84 typedef std::map<HttpPipelinedConnection*, PipelineInfo> PipelineInfoMap;
86 // Called when a pipeline is empty and there are no pending requests. Closes
87 // the connection.
88 void OnPipelineEmpty(HttpPipelinedConnection* pipeline);
90 // Adds the next pending request to the pipeline if it's still usuable.
91 void AddRequestToPipeline(HttpPipelinedConnection* pipeline);
93 // Returns the current pipeline capacity based on |capability_|. This should
94 // not be called if |capability_| is INCAPABLE.
95 int GetPipelineCapacity() const;
97 // Returns true if |pipeline| can handle a new request. This is true if the
98 // |pipeline| is active, usable, has capacity, and |capability_| is
99 // sufficient.
100 bool CanPipelineAcceptRequests(HttpPipelinedConnection* pipeline) const;
102 // Called when |this| moves from UNKNOWN |capability_| to PROBABLY_CAPABLE.
103 // Causes all pipelines to increase capacity to start pipelining.
104 void NotifyAllPipelinesHaveCapacity();
106 HttpPipelinedHost::Delegate* delegate_;
107 const Key key_;
108 PipelineInfoMap pipelines_;
109 scoped_ptr<HttpPipelinedConnection::Factory> factory_;
110 HttpPipelinedHostCapability capability_;
112 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHostImpl);
115 } // namespace net
117 #endif // NET_HTTP_HTTP_PIPELINED_HOST_IMPL_H_