| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_STREAM_FACTORY_IMPL_H_ | 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ | 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 16 #include "net/http/http_pipelined_host_pool.h" | |
| 17 #include "net/http/http_stream_factory.h" | 16 #include "net/http/http_stream_factory.h" |
| 18 #include "net/proxy/proxy_server.h" | 17 #include "net/proxy/proxy_server.h" |
| 19 #include "net/socket/ssl_client_socket.h" | 18 #include "net/socket/ssl_client_socket.h" |
| 20 #include "net/spdy/spdy_session_key.h" | 19 #include "net/spdy/spdy_session_key.h" |
| 21 | 20 |
| 22 namespace net { | 21 namespace net { |
| 23 | 22 |
| 24 class HttpNetworkSession; | 23 class HttpNetworkSession; |
| 25 class HttpPipelinedHost; | |
| 26 class SpdySession; | 24 class SpdySession; |
| 27 | 25 |
| 28 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : | 26 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory { |
| 29 public HttpStreamFactory, | |
| 30 public HttpPipelinedHostPool::Delegate { | |
| 31 public: | 27 public: |
| 32 // RequestStream may only be called if |for_websockets| is false. | 28 // RequestStream may only be called if |for_websockets| is false. |
| 33 // RequestWebSocketHandshakeStream may only be called if |for_websockets| | 29 // RequestWebSocketHandshakeStream may only be called if |for_websockets| |
| 34 // is true. | 30 // is true. |
| 35 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); | 31 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); |
| 36 virtual ~HttpStreamFactoryImpl(); | 32 virtual ~HttpStreamFactoryImpl(); |
| 37 | 33 |
| 38 // HttpStreamFactory interface | 34 // HttpStreamFactory interface |
| 39 virtual HttpStreamRequest* RequestStream( | 35 virtual HttpStreamRequest* RequestStream( |
| 40 const HttpRequestInfo& info, | 36 const HttpRequestInfo& info, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 const SSLConfig& proxy_ssl_config, | 47 const SSLConfig& proxy_ssl_config, |
| 52 HttpStreamRequest::Delegate* delegate, | 48 HttpStreamRequest::Delegate* delegate, |
| 53 WebSocketHandshakeStreamBase::CreateHelper* create_helper, | 49 WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
| 54 const BoundNetLog& net_log) OVERRIDE; | 50 const BoundNetLog& net_log) OVERRIDE; |
| 55 | 51 |
| 56 virtual void PreconnectStreams(int num_streams, | 52 virtual void PreconnectStreams(int num_streams, |
| 57 const HttpRequestInfo& info, | 53 const HttpRequestInfo& info, |
| 58 RequestPriority priority, | 54 RequestPriority priority, |
| 59 const SSLConfig& server_ssl_config, | 55 const SSLConfig& server_ssl_config, |
| 60 const SSLConfig& proxy_ssl_config) OVERRIDE; | 56 const SSLConfig& proxy_ssl_config) OVERRIDE; |
| 61 virtual base::Value* PipelineInfoToValue() const OVERRIDE; | |
| 62 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE; | 57 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE; |
| 63 | 58 |
| 64 // HttpPipelinedHostPool::Delegate interface | |
| 65 virtual void OnHttpPipelinedHostHasAdditionalCapacity( | |
| 66 HttpPipelinedHost* host) OVERRIDE; | |
| 67 | |
| 68 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); } | 59 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); } |
| 69 | 60 |
| 70 private: | 61 private: |
| 71 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); | 62 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); |
| 72 | 63 |
| 73 class NET_EXPORT_PRIVATE Request; | 64 class NET_EXPORT_PRIVATE Request; |
| 74 class NET_EXPORT_PRIVATE Job; | 65 class NET_EXPORT_PRIVATE Job; |
| 75 | 66 |
| 76 typedef std::set<Request*> RequestSet; | 67 typedef std::set<Request*> RequestSet; |
| 77 typedef std::vector<Request*> RequestVector; | |
| 78 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; | 68 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; |
| 79 typedef std::map<HttpPipelinedHost::Key, | |
| 80 RequestVector> HttpPipeliningRequestMap; | |
| 81 | 69 |
| 82 HttpStreamRequest* RequestStreamInternal( | 70 HttpStreamRequest* RequestStreamInternal( |
| 83 const HttpRequestInfo& info, | 71 const HttpRequestInfo& info, |
| 84 RequestPriority priority, | 72 RequestPriority priority, |
| 85 const SSLConfig& server_ssl_config, | 73 const SSLConfig& server_ssl_config, |
| 86 const SSLConfig& proxy_ssl_config, | 74 const SSLConfig& proxy_ssl_config, |
| 87 HttpStreamRequest::Delegate* delegate, | 75 HttpStreamRequest::Delegate* delegate, |
| 88 WebSocketHandshakeStreamBase::CreateHelper* create_helper, | 76 WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
| 89 const BoundNetLog& net_log); | 77 const BoundNetLog& net_log); |
| 90 | 78 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 114 | 102 |
| 115 // Invoked when an orphaned Job finishes. | 103 // Invoked when an orphaned Job finishes. |
| 116 void OnOrphanedJobComplete(const Job* job); | 104 void OnOrphanedJobComplete(const Job* job); |
| 117 | 105 |
| 118 // Invoked when the Job finishes preconnecting sockets. | 106 // Invoked when the Job finishes preconnecting sockets. |
| 119 void OnPreconnectsComplete(const Job* job); | 107 void OnPreconnectsComplete(const Job* job); |
| 120 | 108 |
| 121 // Called when the Preconnect completes. Used for testing. | 109 // Called when the Preconnect completes. Used for testing. |
| 122 virtual void OnPreconnectsCompleteInternal() {} | 110 virtual void OnPreconnectsCompleteInternal() {} |
| 123 | 111 |
| 124 void AbortPipelinedRequestsWithKey(const Job* job, | |
| 125 const HttpPipelinedHost::Key& key, | |
| 126 int status, | |
| 127 const SSLConfig& used_ssl_config); | |
| 128 | |
| 129 HttpNetworkSession* const session_; | 112 HttpNetworkSession* const session_; |
| 130 | 113 |
| 131 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl | 114 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl |
| 132 // is destroyed, all Requests should be deleted (which should remove them from | 115 // is destroyed, all Requests should be deleted (which should remove them from |
| 133 // |request_map_|. The Requests will delete the corresponding job. | 116 // |request_map_|. The Requests will delete the corresponding job. |
| 134 std::map<const Job*, Request*> request_map_; | 117 std::map<const Job*, Request*> request_map_; |
| 135 | 118 |
| 136 SpdySessionRequestMap spdy_session_request_map_; | 119 SpdySessionRequestMap spdy_session_request_map_; |
| 137 HttpPipeliningRequestMap http_pipelining_request_map_; | |
| 138 | |
| 139 HttpPipelinedHostPool http_pipelined_host_pool_; | |
| 140 | 120 |
| 141 // These jobs correspond to jobs orphaned by Requests and now owned by | 121 // These jobs correspond to jobs orphaned by Requests and now owned by |
| 142 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will | 122 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will |
| 143 // not be canceled when Requests are canceled. Therefore, in | 123 // not be canceled when Requests are canceled. Therefore, in |
| 144 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this | 124 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this |
| 145 // set. Leftover jobs will be deleted when the factory is destroyed. | 125 // set. Leftover jobs will be deleted when the factory is destroyed. |
| 146 std::set<const Job*> orphaned_job_set_; | 126 std::set<const Job*> orphaned_job_set_; |
| 147 | 127 |
| 148 // These jobs correspond to preconnect requests and have no associated Request | 128 // These jobs correspond to preconnect requests and have no associated Request |
| 149 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be | 129 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be |
| 150 // deleted when the factory is destroyed. | 130 // deleted when the factory is destroyed. |
| 151 std::set<const Job*> preconnect_job_set_; | 131 std::set<const Job*> preconnect_job_set_; |
| 152 | 132 |
| 153 const bool for_websockets_; | 133 const bool for_websockets_; |
| 154 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); | 134 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); |
| 155 }; | 135 }; |
| 156 | 136 |
| 157 } // namespace net | 137 } // namespace net |
| 158 | 138 |
| 159 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ | 139 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| OLD | NEW |