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