| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "net/socket/ssl_client_socket.h" | 21 #include "net/socket/ssl_client_socket.h" |
| 22 #include "net/spdy/spdy_session_key.h" | 22 #include "net/spdy/spdy_session_key.h" |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 class HttpNetworkSession; | 26 class HttpNetworkSession; |
| 27 class SpdySession; | 27 class SpdySession; |
| 28 | 28 |
| 29 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory { | 29 class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory { |
| 30 public: | 30 public: |
| 31 class NET_EXPORT_PRIVATE Job; | |
| 32 class NET_EXPORT_PRIVATE JobController; | |
| 33 class NET_EXPORT_PRIVATE JobFactory; | |
| 34 class NET_EXPORT_PRIVATE Request; | |
| 35 // RequestStream may only be called if |for_websockets| is false. | 31 // RequestStream may only be called if |for_websockets| is false. |
| 36 // RequestWebSocketHandshakeStream may only be called if |for_websockets| | 32 // RequestWebSocketHandshakeStream may only be called if |for_websockets| |
| 37 // is true. | 33 // is true. |
| 38 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); | 34 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); |
| 39 ~HttpStreamFactoryImpl() override; | 35 ~HttpStreamFactoryImpl() override; |
| 40 | 36 |
| 41 // HttpStreamFactory interface | 37 // HttpStreamFactory interface |
| 42 HttpStreamRequest* RequestStream(const HttpRequestInfo& info, | 38 HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 43 RequestPriority priority, | 39 RequestPriority priority, |
| 44 const SSLConfig& server_ssl_config, | 40 const SSLConfig& server_ssl_config, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 const HttpRequestInfo& info, | 55 const HttpRequestInfo& info, |
| 60 RequestPriority priority, | 56 RequestPriority priority, |
| 61 const SSLConfig& server_ssl_config, | 57 const SSLConfig& server_ssl_config, |
| 62 const SSLConfig& proxy_ssl_config, | 58 const SSLConfig& proxy_ssl_config, |
| 63 HttpStreamRequest::Delegate* delegate, | 59 HttpStreamRequest::Delegate* delegate, |
| 64 const BoundNetLog& net_log) override; | 60 const BoundNetLog& net_log) override; |
| 65 | 61 |
| 66 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override; | 62 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override; |
| 67 const HostMappingRules* GetHostMappingRules() const override; | 63 const HostMappingRules* GetHostMappingRules() const override; |
| 68 | 64 |
| 69 enum JobType { | 65 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); } |
| 70 MAIN, | |
| 71 ALTERNATIVE, | |
| 72 PRECONNECT, | |
| 73 }; | |
| 74 | 66 |
| 75 private: | 67 private: |
| 76 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); | 68 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); |
| 77 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 69 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 78 | 70 |
| 79 friend class HttpStreamFactoryImplPeer; | 71 class NET_EXPORT_PRIVATE Request; |
| 72 class NET_EXPORT_PRIVATE Job; |
| 80 | 73 |
| 81 typedef std::set<Request*> RequestSet; | 74 typedef std::set<Request*> RequestSet; |
| 82 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; | 75 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; |
| 83 typedef std::set<std::unique_ptr<JobController>> JobControllerSet; | |
| 84 | 76 |
| 85 // Values must not be changed or reused. Keep in sync with identically named | 77 // Values must not be changed or reused. Keep in sync with identically named |
| 86 // enum in histograms.xml. | 78 // enum in histograms.xml. |
| 87 enum AlternativeServiceType { | 79 enum AlternativeServiceType { |
| 88 NO_ALTERNATIVE_SERVICE = 0, | 80 NO_ALTERNATIVE_SERVICE = 0, |
| 89 QUIC_SAME_DESTINATION = 1, | 81 QUIC_SAME_DESTINATION = 1, |
| 90 QUIC_DIFFERENT_DESTINATION = 2, | 82 QUIC_DIFFERENT_DESTINATION = 2, |
| 91 NOT_QUIC_SAME_DESTINATION = 3, | 83 NOT_QUIC_SAME_DESTINATION = 3, |
| 92 NOT_QUIC_DIFFERENT_DESTINATION = 4, | 84 NOT_QUIC_DIFFERENT_DESTINATION = 4, |
| 93 MAX_ALTERNATIVE_SERVICE_TYPE | 85 MAX_ALTERNATIVE_SERVICE_TYPE |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 HttpStreamRequest* RequestStreamInternal( | 88 HttpStreamRequest* RequestStreamInternal( |
| 97 const HttpRequestInfo& info, | 89 const HttpRequestInfo& info, |
| 98 RequestPriority priority, | 90 RequestPriority priority, |
| 99 const SSLConfig& server_ssl_config, | 91 const SSLConfig& server_ssl_config, |
| 100 const SSLConfig& proxy_ssl_config, | 92 const SSLConfig& proxy_ssl_config, |
| 101 HttpStreamRequest::Delegate* delegate, | 93 HttpStreamRequest::Delegate* delegate, |
| 102 WebSocketHandshakeStreamBase::CreateHelper* create_helper, | 94 WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
| 103 HttpStreamRequest::StreamType stream_type, | 95 HttpStreamRequest::StreamType stream_type, |
| 104 const BoundNetLog& net_log); | 96 const BoundNetLog& net_log); |
| 105 | 97 |
| 98 AlternativeService GetAlternativeServiceFor( |
| 99 const HttpRequestInfo& request_info, |
| 100 HttpStreamRequest::Delegate* delegate, |
| 101 HttpStreamRequest::StreamType stream_type); |
| 102 |
| 103 AlternativeService GetAlternativeServiceForInternal( |
| 104 const HttpRequestInfo& request_info, |
| 105 HttpStreamRequest::Delegate* delegate, |
| 106 HttpStreamRequest::StreamType stream_type); |
| 107 |
| 108 // Detaches |job| from |request|. |
| 109 void OrphanJob(Job* job, const Request* request); |
| 110 |
| 106 // Called when a SpdySession is ready. It will find appropriate Requests and | 111 // Called when a SpdySession is ready. It will find appropriate Requests and |
| 107 // fulfill them. |direct| indicates whether or not |spdy_session| uses a | 112 // fulfill them. |direct| indicates whether or not |spdy_session| uses a |
| 108 // proxy. | 113 // proxy. |
| 109 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session, | 114 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session, |
| 110 bool direct, | 115 bool direct, |
| 111 const SSLConfig& used_ssl_config, | 116 const SSLConfig& used_ssl_config, |
| 112 const ProxyInfo& used_proxy_info, | 117 const ProxyInfo& used_proxy_info, |
| 113 bool was_npn_negotiated, | 118 bool was_npn_negotiated, |
| 114 NextProto protocol_negotiated, | 119 NextProto protocol_negotiated, |
| 115 bool using_spdy, | 120 bool using_spdy, |
| 116 const BoundNetLog& net_log); | 121 const BoundNetLog& net_log); |
| 117 | 122 |
| 118 // Called when the Job detects that the endpoint indicated by the | 123 // Called when the Job detects that the endpoint indicated by the |
| 119 // Alternate-Protocol does not work. Lets the factory update | 124 // Alternate-Protocol does not work. Lets the factory update |
| 120 // HttpAlternateProtocols with the failure and resets the SPDY session key. | 125 // HttpAlternateProtocols with the failure and resets the SPDY session key. |
| 121 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); | 126 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); |
| 122 | 127 |
| 128 // Invoked when an orphaned Job finishes. |
| 129 void OnOrphanedJobComplete(const Job* job); |
| 130 |
| 131 // Invoked when the Job finishes preconnecting sockets. |
| 132 void OnPreconnectsComplete(const Job* job); |
| 133 |
| 123 // Called when the Preconnect completes. Used for testing. | 134 // Called when the Preconnect completes. Used for testing. |
| 124 virtual void OnPreconnectsCompleteInternal() {} | 135 virtual void OnPreconnectsCompleteInternal() {} |
| 125 | 136 |
| 126 // Called when the JobController finishes service. Delete the JobController | 137 // Returns true if QUIC is whitelisted for |host|. |
| 127 // from |job_controller_set_|. | 138 bool IsQuicWhitelistedForHost(const std::string& host); |
| 128 void OnJobControllerComplete(JobController* controller); | |
| 129 | 139 |
| 130 HttpNetworkSession* const session_; | 140 HttpNetworkSession* const session_; |
| 131 | 141 |
| 132 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl | 142 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl |
| 133 // is destroyed, all Requests should be deleted (which should remove them from | 143 // is destroyed, all Requests should be deleted (which should remove them from |
| 134 // |request_map_|. The Requests will delete the corresponding job. | 144 // |request_map_|. The Requests will delete the corresponding job. |
| 135 std::map<const Job*, Request*> request_map_; | 145 std::map<const Job*, Request*> request_map_; |
| 136 | 146 |
| 137 // All Requests/Preconnects are assigned with a JobController to manage | 147 SpdySessionRequestMap spdy_session_request_map_; |
| 138 // serving Job(s). JobController might outlive Request when Request | |
| 139 // is served while there's some working Job left. JobController will be | |
| 140 // deleted from |job_controller_set_| when it determines the completion of | |
| 141 // its work. | |
| 142 JobControllerSet job_controller_set_; | |
| 143 | 148 |
| 144 // Factory used by job controllers for creating jobs. | 149 // These jobs correspond to jobs orphaned by Requests and now owned by |
| 145 std::unique_ptr<JobFactory> job_factory_; | 150 // HttpStreamFactoryImpl. Since they are no longer tied to Requests, they will |
| 151 // not be canceled when Requests are canceled. Therefore, in |
| 152 // ~HttpStreamFactoryImpl, it is possible for some jobs to still exist in this |
| 153 // set. Leftover jobs will be deleted when the factory is destroyed. |
| 154 std::set<const Job*> orphaned_job_set_; |
| 146 | 155 |
| 147 SpdySessionRequestMap spdy_session_request_map_; | 156 // These jobs correspond to preconnect requests and have no associated Request |
| 157 // object. They're owned by HttpStreamFactoryImpl. Leftover jobs will be |
| 158 // deleted when the factory is destroyed. |
| 159 std::set<const Job*> preconnect_job_set_; |
| 148 | 160 |
| 149 const bool for_websockets_; | 161 const bool for_websockets_; |
| 150 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); | 162 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); |
| 151 }; | 163 }; |
| 152 | 164 |
| 153 } // namespace net | 165 } // namespace net |
| 154 | 166 |
| 155 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ | 167 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| OLD | NEW |