[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 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> |
| 10 | #include <string> |
| 11 | |
| 12 | #include "net/http/http_stream_factory.h" |
| 13 | |
| 14 | namespace net { |
| 15 | |
| 16 | class HttpNetworkSession; |
| 17 | |
| 18 | class HttpStreamFactoryImpl : public HttpStreamFactory { |
| 19 | public: |
| 20 | explicit HttpStreamFactoryImpl(HttpNetworkSession* session); |
| 21 | virtual ~HttpStreamFactoryImpl(); |
| 22 | |
| 23 | // HttpStreamFactory Interface |
| 24 | virtual HttpStreamRequest* RequestStream( |
| 25 | const HttpRequestInfo& info, |
| 26 | const SSLConfig& ssl_config, |
| 27 | HttpStreamRequest::Delegate* delegate, |
| 28 | const BoundNetLog& net_log); |
| 29 | |
| 30 | virtual void PreconnectStreams(int num_streams, |
| 31 | const HttpRequestInfo& info, |
| 32 | const SSLConfig& ssl_config, |
| 33 | const BoundNetLog& net_log); |
| 34 | virtual void AddTLSIntolerantServer(const GURL& url); |
| 35 | virtual bool IsTLSIntolerantServer(const GURL& url) const; |
| 36 | |
| 37 | private: |
| 38 | class Request; |
| 39 | class Job; |
| 40 | |
| 41 | LoadState GetLoadState(const Request& request) const; |
| 42 | |
| 43 | void OnStreamReady(const Job* job, |
| 44 | const SSLConfig& ssl_config, |
| 45 | const ProxyInfo& proxy_info, |
| 46 | HttpStream* stream); |
| 47 | void OnStreamFailed(const Job* job, int result, const SSLConfig& ssl_config); |
| 48 | void OnCertificateError(const Job* job, |
| 49 | int result, |
| 50 | const SSLConfig& ssl_config, |
| 51 | const SSLInfo& ssl_info); |
| 52 | void OnNeedsProxyAuth(const Job* job, |
| 53 | const HttpResponseInfo& response_info, |
| 54 | const SSLConfig& ssl_config, |
| 55 | const ProxyInfo& proxy_info, |
| 56 | HttpAuthController* auth_controller); |
| 57 | void OnNeedsClientAuth(const Job* job, |
| 58 | const SSLConfig& ssl_config, |
| 59 | SSLCertRequestInfo* cert_info); |
| 60 | void OnHttpsProxyTunnelResponse(const Job* job, |
| 61 | const HttpResponseInfo& response_info, |
| 62 | const SSLConfig& ssl_config, |
| 63 | const ProxyInfo& proxy_info, |
| 64 | HttpStream* stream); |
| 65 | |
| 66 | void OnPreconnectsComplete(const Job* job); |
| 67 | |
| 68 | // Called when the Preconnect completes. Used for testing. |
| 69 | virtual void OnPreconnectsCompleteInternal() {} |
| 70 | |
| 71 | HttpNetworkSession* const session_; |
| 72 | |
| 73 | std::set<std::string> tls_intolerant_servers_; |
| 74 | |
| 75 | // All Requests are handed out to clients. By the time HttpStreamFactoryImpl |
| 76 | // is destroyed, all Requests should be deleted (which should remove them from |
| 77 | // |request_map_|. |
| 78 | // TODO(willchan): Change to a different key when we enable late binding. This |
| 79 | // is the key part that keeps things tightly bound. |
| 80 | // Note that currently the Request assumes ownership of the Job. We will break |
| 81 | // this with late binding, and the factory will own the Job. |
| 82 | std::map<const Job*, Request*> request_map_; |
| 83 | |
| 84 | // These jobs correspond to preconnect requests and have no associated Request |
| 85 | // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be |
| 86 | // deleted when the factory is destroyed. |
| 87 | std::set<const Job*> preconnect_job_set_; |
| 88 | |
| 89 | DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); |
| 90 | }; |
| 91 | |
| 92 | } // namespace net |
| 93 | |
| 94 | #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |