Chromium Code Reviews| 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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 14 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
| 15 #include "net/http/http_pipelined_host_pool.h" | 15 #include "net/http/http_pipelined_host_pool.h" |
| 16 #include "net/http/http_stream_factory.h" | 16 #include "net/http/http_stream_factory.h" |
| 17 #include "net/proxy/proxy_server.h" | 17 #include "net/proxy/proxy_server.h" |
| 18 #include "net/socket/client_socket_pool_manager.h" | |
| 18 #include "net/socket/ssl_client_socket.h" | 19 #include "net/socket/ssl_client_socket.h" |
| 19 #include "net/spdy/spdy_session_key.h" | 20 #include "net/spdy/spdy_session_key.h" |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 class HttpNetworkSession; | 24 class HttpNetworkSession; |
| 24 class HttpPipelinedHost; | 25 class HttpPipelinedHost; |
| 25 class SpdySession; | 26 class SpdySession; |
| 26 | 27 |
| 27 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : | 28 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : |
| 28 public HttpStreamFactory, | 29 public HttpStreamFactory, |
| 29 public HttpPipelinedHostPool::Delegate { | 30 public HttpPipelinedHostPool::Delegate { |
| 30 public: | 31 public: |
| 31 explicit HttpStreamFactoryImpl(HttpNetworkSession* session); | 32 // RequestStream may only be called if |for_websockets| is false. |
| 33 // RequestWebSocketStream may only be called if |for_websockets| is true. | |
| 34 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); | |
| 32 virtual ~HttpStreamFactoryImpl(); | 35 virtual ~HttpStreamFactoryImpl(); |
| 33 | 36 |
| 34 // HttpStreamFactory interface | 37 // HttpStreamFactory interface |
| 35 virtual HttpStreamRequest* RequestStream( | 38 virtual HttpStreamRequest* RequestStream( |
| 36 const HttpRequestInfo& info, | 39 const HttpRequestInfo& info, |
| 37 RequestPriority priority, | 40 RequestPriority priority, |
| 38 const SSLConfig& server_ssl_config, | 41 const SSLConfig& server_ssl_config, |
| 39 const SSLConfig& proxy_ssl_config, | 42 const SSLConfig& proxy_ssl_config, |
| 40 HttpStreamRequest::Delegate* delegate, | 43 HttpStreamRequest::Delegate* delegate, |
| 41 const BoundNetLog& net_log) OVERRIDE; | 44 const BoundNetLog& net_log) OVERRIDE; |
| 42 | 45 |
| 46 virtual HttpStreamRequest* RequestWebSocketStream( | |
| 47 const HttpRequestInfo& info, | |
| 48 RequestPriority priority, | |
| 49 const SSLConfig& server_ssl_config, | |
| 50 const SSLConfig& proxy_ssl_config, | |
| 51 HttpStreamRequest::Delegate* delegate, | |
| 52 WebSocketStreamBase::Factory* factory, | |
| 53 const BoundNetLog& net_log) OVERRIDE; | |
| 54 | |
| 43 virtual void PreconnectStreams(int num_streams, | 55 virtual void PreconnectStreams(int num_streams, |
| 44 const HttpRequestInfo& info, | 56 const HttpRequestInfo& info, |
| 45 RequestPriority priority, | 57 RequestPriority priority, |
| 46 const SSLConfig& server_ssl_config, | 58 const SSLConfig& server_ssl_config, |
| 47 const SSLConfig& proxy_ssl_config) OVERRIDE; | 59 const SSLConfig& proxy_ssl_config) OVERRIDE; |
| 48 virtual base::Value* PipelineInfoToValue() const OVERRIDE; | 60 virtual base::Value* PipelineInfoToValue() const OVERRIDE; |
| 49 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE; | 61 virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE; |
| 50 | 62 |
| 51 // HttpPipelinedHostPool::Delegate interface | 63 // HttpPipelinedHostPool::Delegate interface |
| 52 virtual void OnHttpPipelinedHostHasAdditionalCapacity( | 64 virtual void OnHttpPipelinedHostHasAdditionalCapacity( |
| 53 HttpPipelinedHost* host) OVERRIDE; | 65 HttpPipelinedHost* host) OVERRIDE; |
| 54 | 66 |
| 67 // For testing purpose | |
|
mmenke
2013/05/28 21:22:37
nit: Add period. Also should be "purposes".
yhirano
2013/05/30 04:44:32
Deleted.
| |
| 68 virtual int InitSocketHandleForHttpRequest( | |
|
mmenke
2013/05/28 21:22:37
This should be protected.
yhirano
2013/05/30 04:44:32
Deleted.
| |
| 69 const GURL& request_url, | |
| 70 const HttpRequestInfo& request_info, | |
| 71 RequestPriority request_priority, | |
| 72 const ProxyInfo& proxy_info, | |
| 73 bool force_spdy_over_ssl, | |
| 74 bool want_spdy_over_npn, | |
| 75 const SSLConfig& ssl_config_for_origin, | |
| 76 const SSLConfig& ssl_config_for_proxy, | |
| 77 const BoundNetLog& net_log, | |
| 78 ClientSocketHandle* socket_handle, | |
| 79 const OnHostResolutionCallback& resolution_callback, | |
| 80 const CompletionCallback& callback); | |
| 81 | |
| 55 private: | 82 private: |
| 56 class Request; | 83 class Request; |
| 57 class Job; | 84 class Job; |
| 58 | 85 |
| 59 typedef std::set<Request*> RequestSet; | 86 typedef std::set<Request*> RequestSet; |
| 60 typedef std::vector<Request*> RequestVector; | 87 typedef std::vector<Request*> RequestVector; |
| 61 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; | 88 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; |
| 62 typedef std::map<HttpPipelinedHost::Key, | 89 typedef std::map<HttpPipelinedHost::Key, |
| 63 RequestVector> HttpPipeliningRequestMap; | 90 RequestVector> HttpPipeliningRequestMap; |
| 64 | 91 |
| 92 HttpStreamRequest* RequestStreamInternal( | |
| 93 const HttpRequestInfo& info, | |
| 94 RequestPriority priority, | |
| 95 const SSLConfig& server_ssl_config, | |
| 96 const SSLConfig& proxy_ssl_config, | |
| 97 HttpStreamRequest::Delegate* delegate, | |
| 98 WebSocketStreamBase::Factory* factory, | |
| 99 const BoundNetLog& net_log); | |
| 100 | |
| 65 PortAlternateProtocolPair GetAlternateProtocolRequestFor( | 101 PortAlternateProtocolPair GetAlternateProtocolRequestFor( |
| 66 const GURL& original_url, | 102 const GURL& original_url, |
| 67 GURL* alternate_url) const; | 103 GURL* alternate_url) const; |
| 68 | 104 |
| 69 // Detaches |job| from |request|. | 105 // Detaches |job| from |request|. |
| 70 void OrphanJob(Job* job, const Request* request); | 106 void OrphanJob(Job* job, const Request* request); |
| 71 | 107 |
| 72 // Called when a SpdySession is ready. It will find appropriate Requests and | 108 // Called when a SpdySession is ready. It will find appropriate Requests and |
| 73 // fulfill them. |direct| indicates whether or not |spdy_session| uses a | 109 // fulfill them. |direct| indicates whether or not |spdy_session| uses a |
| 74 // proxy. | 110 // proxy. |
| 75 void OnSpdySessionReady(scoped_refptr<SpdySession> spdy_session, | 111 void OnNewSpdySessionReady(scoped_refptr<SpdySession> spdy_session, |
| 76 bool direct, | 112 bool direct, |
| 77 const SSLConfig& used_ssl_config, | 113 const SSLConfig& used_ssl_config, |
| 78 const ProxyInfo& used_proxy_info, | 114 const ProxyInfo& used_proxy_info, |
| 79 bool was_npn_negotiated, | 115 bool was_npn_negotiated, |
| 80 NextProto protocol_negotiated, | 116 NextProto protocol_negotiated, |
| 81 bool using_spdy, | 117 bool using_spdy, |
| 82 const BoundNetLog& net_log); | 118 const BoundNetLog& net_log); |
| 83 | 119 |
| 84 // Called when the Job detects that the endpoint indicated by the | 120 // Called when the Job detects that the endpoint indicated by the |
| 85 // Alternate-Protocol does not work. Lets the factory update | 121 // Alternate-Protocol does not work. Lets the factory update |
| 86 // HttpAlternateProtocols with the failure and resets the SPDY session key. | 122 // HttpAlternateProtocols with the failure and resets the SPDY session key. |
| 87 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); | 123 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); |
| 88 | 124 |
| 89 // Invoked when an orphaned Job finishes. | 125 // Invoked when an orphaned Job finishes. |
| 90 void OnOrphanedJobComplete(const Job* job); | 126 void OnOrphanedJobComplete(const Job* job); |
| 91 | 127 |
| 92 // Invoked when the Job finishes preconnecting sockets. | 128 // Invoked when the Job finishes preconnecting sockets. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 117 // not be canceled when Requests are canceled. Therefore, in | 153 // not be canceled when Requests are canceled. Therefore, in |
| 118 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this | 154 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this |
| 119 // set. Leftover jobs will be deleted when the factory is destroyed. | 155 // set. Leftover jobs will be deleted when the factory is destroyed. |
| 120 std::set<const Job*> orphaned_job_set_; | 156 std::set<const Job*> orphaned_job_set_; |
| 121 | 157 |
| 122 // These jobs correspond to preconnect requests and have no associated Request | 158 // These jobs correspond to preconnect requests and have no associated Request |
| 123 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be | 159 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be |
| 124 // deleted when the factory is destroyed. | 160 // deleted when the factory is destroyed. |
| 125 std::set<const Job*> preconnect_job_set_; | 161 std::set<const Job*> preconnect_job_set_; |
| 126 | 162 |
| 163 const bool for_websockets_; | |
| 127 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); | 164 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); |
| 128 }; | 165 }; |
| 129 | 166 |
| 130 } // namespace net | 167 } // namespace net |
| 131 | 168 |
| 132 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ | 169 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| OLD | NEW |