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