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_H_ | 5 #ifndef NET_HTTP_HTTP_PIPELINED_HOST_H_ |
6 #define NET_HTTP_HTTP_PIPELINED_HOST_H_ | 6 #define NET_HTTP_HTTP_PIPELINED_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
15 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
16 #include "net/http/http_pipelined_connection.h" | 11 #include "net/http/http_pipelined_connection.h" |
17 | 12 |
18 namespace net { | 13 namespace net { |
19 | 14 |
20 class BoundNetLog; | 15 class BoundNetLog; |
21 class ClientSocketHandle; | 16 class ClientSocketHandle; |
22 class HttpPipelinedStream; | 17 class HttpPipelinedStream; |
23 class ProxyInfo; | 18 class ProxyInfo; |
24 struct SSLConfig; | 19 struct SSLConfig; |
25 | 20 |
26 // Manages all of the pipelining state for specific host with active pipelined | 21 // Manages all of the pipelining state for specific host with active pipelined |
27 // HTTP requests. Manages connection jobs, constructs pipelined streams, and | 22 // HTTP requests. Manages connection jobs, constructs pipelined streams, and |
28 // assigns requests to the least loaded pipelined connection. | 23 // assigns requests to the least loaded pipelined connection. |
29 class NET_EXPORT_PRIVATE HttpPipelinedHost | 24 class NET_EXPORT_PRIVATE HttpPipelinedHost { |
30 : public HttpPipelinedConnection::Delegate { | |
31 public: | 25 public: |
26 enum Capability { | |
27 UNKNOWN, | |
28 INCAPABLE, | |
29 CAPABLE, | |
30 PROBABLY_CAPABLE, | |
mmenke
2011/12/01 17:22:48
Maybe add a comment that this is a state, where we
James Simonsen
2011/12/01 20:36:42
Done.
| |
31 }; | |
32 | |
32 class Delegate { | 33 class Delegate { |
33 public: | 34 public: |
34 // Called when a pipelined host has no outstanding requests on any of its | 35 // Called when a pipelined host has no outstanding requests on any of its |
35 // pipelined connections. | 36 // pipelined connections. |
36 virtual void OnHostIdle(HttpPipelinedHost* host) = 0; | 37 virtual void OnHostIdle(HttpPipelinedHost* host) = 0; |
37 | 38 |
38 // Called when a pipelined host has newly available pipeline capacity, like | 39 // Called when a pipelined host has newly available pipeline capacity, like |
39 // when a request completes. | 40 // when a request completes. |
40 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0; | 41 virtual void OnHostHasAdditionalCapacity(HttpPipelinedHost* host) = 0; |
42 | |
43 // Called when a host determines if pipelining can be used. | |
44 virtual void OnHostDeterminedCapability(HttpPipelinedHost* host, | |
45 Capability capability) = 0; | |
41 }; | 46 }; |
42 | 47 |
43 HttpPipelinedHost(Delegate* delegate, const HostPortPair& origin, | 48 class Factory { |
44 HttpPipelinedConnection::Factory* factory); | 49 public: |
45 virtual ~HttpPipelinedHost(); | 50 virtual ~Factory() {} |
51 | |
52 // Returns a new HttpPipelinedHost. | |
53 virtual HttpPipelinedHost* CreateNewHost( | |
54 Delegate* delegate, const HostPortPair& origin, | |
55 HttpPipelinedConnection::Factory* factory, | |
56 Capability capability) = 0; | |
57 }; | |
58 | |
59 virtual ~HttpPipelinedHost() {} | |
46 | 60 |
47 // Constructs a new pipeline on |connection| and returns a new | 61 // Constructs a new pipeline on |connection| and returns a new |
48 // HttpPipelinedStream that uses it. | 62 // HttpPipelinedStream that uses it. |
49 HttpPipelinedStream* CreateStreamOnNewPipeline( | 63 virtual HttpPipelinedStream* CreateStreamOnNewPipeline( |
50 ClientSocketHandle* connection, | 64 ClientSocketHandle* connection, |
51 const SSLConfig& used_ssl_config, | 65 const SSLConfig& used_ssl_config, |
52 const ProxyInfo& used_proxy_info, | 66 const ProxyInfo& used_proxy_info, |
53 const BoundNetLog& net_log, | 67 const BoundNetLog& net_log, |
54 bool was_npn_negotiated); | 68 bool was_npn_negotiated) = 0; |
55 | 69 |
56 // Tries to find an existing pipeline with capacity for a new request. If | 70 // Tries to find an existing pipeline with capacity for a new request. If |
57 // successful, returns a new stream on that pipeline. Otherwise, returns NULL. | 71 // successful, returns a new stream on that pipeline. Otherwise, returns NULL. |
58 HttpPipelinedStream* CreateStreamOnExistingPipeline(); | 72 virtual HttpPipelinedStream* CreateStreamOnExistingPipeline() = 0; |
59 | 73 |
60 // Returns true if we have a pipelined connection that can accept new | 74 // Returns true if we have a pipelined connection that can accept new |
61 // requests. | 75 // requests. |
62 bool IsExistingPipelineAvailable(); | 76 virtual bool IsExistingPipelineAvailable() const = 0; |
63 | 77 |
64 // Callbacks for HttpPipelinedConnection. | 78 // Returns the host and port associated with this class. |
65 | 79 virtual const HostPortPair& origin() const = 0; |
66 // Called when a pipelined connection completes a request. Adds a pending | |
67 // request to the pipeline if the pipeline is still usable. | |
68 virtual void OnPipelineHasCapacity( | |
69 HttpPipelinedConnection* pipeline) OVERRIDE; | |
70 | |
71 const HostPortPair& origin() const { return origin_; } | |
72 | |
73 private: | |
74 // Called when a pipeline is empty and there are no pending requests. Closes | |
75 // the connection. | |
76 void OnPipelineEmpty(HttpPipelinedConnection* pipeline); | |
77 | |
78 // Adds the next pending request to the pipeline if it's still usuable. | |
79 void AddRequestToPipeline(HttpPipelinedConnection* connection); | |
80 | |
81 int max_pipeline_depth() const { return 3; } | |
82 | |
83 Delegate* delegate_; | |
84 const HostPortPair origin_; | |
85 std::set<HttpPipelinedConnection*> pipelines_; | |
86 scoped_ptr<HttpPipelinedConnection::Factory> factory_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedHost); | |
89 }; | 80 }; |
90 | 81 |
91 } // namespace net | 82 } // namespace net |
92 | 83 |
93 #endif // NET_HTTP_HTTP_PIPELINED_HOST_H_ | 84 #endif // NET_HTTP_HTTP_PIPELINED_HOST_H_ |
OLD | NEW |