[email protected] | 7acf9829 | 2012-01-28 00:51:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| 6 | #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <set> |
[email protected] | 8005968 | 2012-03-03 00:42:31 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 11 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13 | #include "net/base/host_port_pair.h" |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 14 | #include "net/base/net_log.h" |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 15 | #include "net/http/http_pipelined_host_pool.h" |
| 16 | #include "net/http/http_stream_factory.h" |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 17 | #include "net/proxy/proxy_server.h" |
[email protected] | c30bcce | 2011-12-20 17:50:51 | [diff] [blame] | 18 | #include "net/socket/ssl_client_socket.h" |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame^] | 19 | #include "net/spdy/spdy_session_key.h" |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 20 | |
| 21 | namespace net { |
| 22 | |
| 23 | class HttpNetworkSession; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 24 | class HttpPipelinedHost; |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 25 | class SpdySession; |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 26 | |
[email protected] | 4b9f729 | 2011-12-01 22:20:06 | [diff] [blame] | 27 | class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : |
| 28 | public HttpStreamFactory, |
[email protected] | cb4bf8d | 2013-02-06 15:32:07 | [diff] [blame] | 29 | public HttpPipelinedHostPool::Delegate { |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 30 | public: |
| 31 | explicit HttpStreamFactoryImpl(HttpNetworkSession* session); |
| 32 | virtual ~HttpStreamFactoryImpl(); |
| 33 | |
[email protected] | 4b9f729 | 2011-12-01 22:20:06 | [diff] [blame] | 34 | // HttpStreamFactory interface |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 35 | virtual HttpStreamRequest* RequestStream( |
| 36 | const HttpRequestInfo& info, |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 37 | RequestPriority priority, |
[email protected] | 102957f | 2011-09-02 17:10:14 | [diff] [blame] | 38 | const SSLConfig& server_ssl_config, |
| 39 | const SSLConfig& proxy_ssl_config, |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 40 | HttpStreamRequest::Delegate* delegate, |
[email protected] | f2cbbc8 | 2011-11-16 01:10:29 | [diff] [blame] | 41 | const BoundNetLog& net_log) OVERRIDE; |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 42 | |
| 43 | virtual void PreconnectStreams(int num_streams, |
| 44 | const HttpRequestInfo& info, |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 45 | RequestPriority priority, |
[email protected] | 102957f | 2011-09-02 17:10:14 | [diff] [blame] | 46 | const SSLConfig& server_ssl_config, |
[email protected] | 7acf9829 | 2012-01-28 00:51:55 | [diff] [blame] | 47 | const SSLConfig& proxy_ssl_config) OVERRIDE; |
[email protected] | 837c4f5 | 2011-12-20 22:17:03 | [diff] [blame] | 48 | virtual base::Value* PipelineInfoToValue() const OVERRIDE; |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 49 | virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE; |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 50 | |
[email protected] | 4b9f729 | 2011-12-01 22:20:06 | [diff] [blame] | 51 | // HttpPipelinedHostPool::Delegate interface |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 52 | virtual void OnHttpPipelinedHostHasAdditionalCapacity( |
[email protected] | 5477d89 | 2012-03-01 21:31:31 | [diff] [blame] | 53 | HttpPipelinedHost* host) OVERRIDE; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 54 | |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 55 | private: |
| 56 | class Request; |
| 57 | class Job; |
| 58 | |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 59 | typedef std::set<Request*> RequestSet; |
[email protected] | 8005968 | 2012-03-03 00:42:31 | [diff] [blame] | 60 | typedef std::vector<Request*> RequestVector; |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame^] | 61 | typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; |
[email protected] | 8005968 | 2012-03-03 00:42:31 | [diff] [blame] | 62 | typedef std::map<HttpPipelinedHost::Key, |
| 63 | RequestVector> HttpPipeliningRequestMap; |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 64 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 65 | PortAlternateProtocolPair GetAlternateProtocolRequestFor( |
| 66 | const GURL& original_url, |
| 67 | GURL* alternate_url) const; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 68 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 69 | // Detaches |job| from |request|. |
| 70 | void OrphanJob(Job* job, const Request* request); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 71 | |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 72 | // Called when a SpdySession is ready. It will find appropriate Requests and |
| 73 | // fulfill them. |direct| indicates whether or not |spdy_session| uses a |
| 74 | // proxy. |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 75 | void OnSpdySessionReady(scoped_refptr<SpdySession> spdy_session, |
| 76 | bool direct, |
| 77 | const SSLConfig& used_ssl_config, |
| 78 | const ProxyInfo& used_proxy_info, |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 79 | bool was_npn_negotiated, |
[email protected] | 8e3c78cb | 2012-03-31 03:58:46 | [diff] [blame] | 80 | NextProto protocol_negotiated, |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 81 | bool using_spdy, |
[email protected] | 68697a4 | 2011-12-19 21:47:55 | [diff] [blame] | 82 | const BoundNetLog& net_log); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 83 | |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 84 | // Called when the Job detects that the endpoint indicated by the |
| 85 | // Alternate-Protocol does not work. Lets the factory update |
| 86 | // HttpAlternateProtocols with the failure and resets the SPDY session key. |
| 87 | void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); |
| 88 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 89 | // Invoked when an orphaned Job finishes. |
| 90 | void OnOrphanedJobComplete(const Job* job); |
| 91 | |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 92 | // Invoked when the Job finishes preconnecting sockets. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 93 | void OnPreconnectsComplete(const Job* job); |
| 94 | |
| 95 | // Called when the Preconnect completes. Used for testing. |
| 96 | virtual void OnPreconnectsCompleteInternal() {} |
| 97 | |
[email protected] | 5477d89 | 2012-03-01 21:31:31 | [diff] [blame] | 98 | void AbortPipelinedRequestsWithKey(const Job* job, |
| 99 | const HttpPipelinedHost::Key& key, |
| 100 | int status, |
| 101 | const SSLConfig& used_ssl_config); |
| 102 | |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 103 | HttpNetworkSession* const session_; |
| 104 | |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 105 | // All Requests are handed out to clients. By the time HttpStreamFactoryImpl |
| 106 | // is destroyed, all Requests should be deleted (which should remove them from |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 107 | // |request_map_|. The Requests will delete the corresponding job. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 108 | std::map<const Job*, Request*> request_map_; |
| 109 | |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 110 | SpdySessionRequestMap spdy_session_request_map_; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 111 | HttpPipeliningRequestMap http_pipelining_request_map_; |
| 112 | |
| 113 | HttpPipelinedHostPool http_pipelined_host_pool_; |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 114 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 115 | // These jobs correspond to jobs orphaned by Requests and now owned by |
| 116 | // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will |
| 117 | // not be canceled when Requests are canceled. Therefore, in |
| 118 | // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this |
| 119 | // set. Leftover jobs will be deleted when the factory is destroyed. |
| 120 | std::set<const Job*> orphaned_job_set_; |
| 121 | |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 122 | // These jobs correspond to preconnect requests and have no associated Request |
| 123 | // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be |
| 124 | // deleted when the factory is destroyed. |
| 125 | std::set<const Job*> preconnect_job_set_; |
| 126 | |
| 127 | DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); |
| 128 | }; |
| 129 | |
| 130 | } // namespace net |
| 131 | |
| 132 | #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |