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