Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 const HttpRequestInfo& info, | 55 const HttpRequestInfo& info, |
| 56 RequestPriority priority, | 56 RequestPriority priority, |
| 57 const SSLConfig& server_ssl_config, | 57 const SSLConfig& server_ssl_config, |
| 58 const SSLConfig& proxy_ssl_config, | 58 const SSLConfig& proxy_ssl_config, |
| 59 HttpStreamRequest::Delegate* delegate, | 59 HttpStreamRequest::Delegate* delegate, |
| 60 const BoundNetLog& net_log) override; | 60 const BoundNetLog& net_log) override; |
| 61 | 61 |
| 62 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override; | 62 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override; |
| 63 const HostMappingRules* GetHostMappingRules() const override; | 63 const HostMappingRules* GetHostMappingRules() const override; |
| 64 | 64 |
| 65 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); } | 65 enum JobType { |
| 66 MAIN, | |
| 67 ALTERNATIVE, | |
| 68 PRECONNECT, | |
| 69 }; | |
| 66 | 70 |
| 67 private: | 71 private: |
| 68 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); | 72 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); |
| 69 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 73 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 70 | 74 |
| 75 friend class HttpStreamFactoryImplJobControllerTest; | |
| 76 friend class TestHttpStreamFactoryImplJob; | |
| 77 friend class TestJobFactory; | |
|
Ryan Hamilton
2016/06/13 19:25:26
Let's talk about how to get rid of all these frien
Zhongyi Shi
2016/06/14 22:20:57
Most of the friend class can be removed by changin
| |
| 78 | |
| 71 class NET_EXPORT_PRIVATE Request; | 79 class NET_EXPORT_PRIVATE Request; |
| 72 class NET_EXPORT_PRIVATE Job; | 80 class NET_EXPORT_PRIVATE Job; |
| 81 class NET_EXPORT_PRIVATE JobController; | |
| 82 class NET_EXPORT_PRIVATE JobFactoryImpl; | |
| 73 | 83 |
| 74 typedef std::set<Request*> RequestSet; | 84 typedef std::set<Request*> RequestSet; |
| 75 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; | 85 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; |
| 86 typedef std::set<std::unique_ptr<JobController>> JobControllerSet; | |
| 76 | 87 |
| 77 // Values must not be changed or reused. Keep in sync with identically named | 88 // Values must not be changed or reused. Keep in sync with identically named |
| 78 // enum in histograms.xml. | 89 // enum in histograms.xml. |
| 79 enum AlternativeServiceType { | 90 enum AlternativeServiceType { |
| 80 NO_ALTERNATIVE_SERVICE = 0, | 91 NO_ALTERNATIVE_SERVICE = 0, |
| 81 QUIC_SAME_DESTINATION = 1, | 92 QUIC_SAME_DESTINATION = 1, |
| 82 QUIC_DIFFERENT_DESTINATION = 2, | 93 QUIC_DIFFERENT_DESTINATION = 2, |
| 83 NOT_QUIC_SAME_DESTINATION = 3, | 94 NOT_QUIC_SAME_DESTINATION = 3, |
| 84 NOT_QUIC_DIFFERENT_DESTINATION = 4, | 95 NOT_QUIC_DIFFERENT_DESTINATION = 4, |
| 85 MAX_ALTERNATIVE_SERVICE_TYPE | 96 MAX_ALTERNATIVE_SERVICE_TYPE |
| 86 }; | 97 }; |
| 87 | 98 |
| 88 HttpStreamRequest* RequestStreamInternal( | 99 HttpStreamRequest* RequestStreamInternal( |
| 89 const HttpRequestInfo& info, | 100 const HttpRequestInfo& info, |
| 90 RequestPriority priority, | 101 RequestPriority priority, |
| 91 const SSLConfig& server_ssl_config, | 102 const SSLConfig& server_ssl_config, |
| 92 const SSLConfig& proxy_ssl_config, | 103 const SSLConfig& proxy_ssl_config, |
| 93 HttpStreamRequest::Delegate* delegate, | 104 HttpStreamRequest::Delegate* delegate, |
| 94 WebSocketHandshakeStreamBase::CreateHelper* create_helper, | 105 WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
| 95 HttpStreamRequest::StreamType stream_type, | 106 HttpStreamRequest::StreamType stream_type, |
| 96 const BoundNetLog& net_log); | 107 const BoundNetLog& net_log); |
| 97 | 108 |
| 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 | |
| 111 // Called when a SpdySession is ready. It will find appropriate Requests and | 109 // Called when a SpdySession is ready. It will find appropriate Requests and |
| 112 // fulfill them. |direct| indicates whether or not |spdy_session| uses a | 110 // fulfill them. |direct| indicates whether or not |spdy_session| uses a |
| 113 // proxy. | 111 // proxy. |
| 114 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session, | 112 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session, |
| 115 bool direct, | 113 bool direct, |
| 116 const SSLConfig& used_ssl_config, | 114 const SSLConfig& used_ssl_config, |
| 117 const ProxyInfo& used_proxy_info, | 115 const ProxyInfo& used_proxy_info, |
| 118 bool was_npn_negotiated, | 116 bool was_npn_negotiated, |
| 119 NextProto protocol_negotiated, | 117 NextProto protocol_negotiated, |
| 120 bool using_spdy, | 118 bool using_spdy, |
| 121 const BoundNetLog& net_log); | 119 const BoundNetLog& net_log); |
| 122 | 120 |
| 123 // Called when the Job detects that the endpoint indicated by the | 121 // Called when the Job detects that the endpoint indicated by the |
| 124 // Alternate-Protocol does not work. Lets the factory update | 122 // Alternate-Protocol does not work. Lets the factory update |
| 125 // HttpAlternateProtocols with the failure and resets the SPDY session key. | 123 // HttpAlternateProtocols with the failure and resets the SPDY session key. |
| 126 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); | 124 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); |
| 127 | 125 |
| 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 | |
| 134 // Called when the Preconnect completes. Used for testing. | 126 // Called when the Preconnect completes. Used for testing. |
| 135 virtual void OnPreconnectsCompleteInternal() {} | 127 virtual void OnPreconnectsCompleteInternal() {} |
| 136 | 128 |
| 137 // Returns true if QUIC is whitelisted for |host|. | 129 // Called when the JobController finishes service. Delete the JobController |
| 138 bool IsQuicWhitelistedForHost(const std::string& host); | 130 // from |job_controller_set_|. |
| 131 void OnJobControllerComplete(JobController* controller); | |
| 139 | 132 |
| 140 HttpNetworkSession* const session_; | 133 HttpNetworkSession* const session_; |
| 141 | 134 |
| 142 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl | 135 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl |
| 143 // is destroyed, all Requests should be deleted (which should remove them from | 136 // is destroyed, all Requests should be deleted (which should remove them from |
| 144 // |request_map_|. The Requests will delete the corresponding job. | 137 // |request_map_|. The Requests will delete the corresponding job. |
| 145 std::map<const Job*, Request*> request_map_; | 138 std::map<const Job*, Request*> request_map_; |
| 146 | 139 |
| 140 // All Requests/Preconnects are assigned with a JobController to manage | |
| 141 // serving Job(s). JobController might outlive Request when Request | |
| 142 // is served while there's some working Job left. JobController will be | |
| 143 // deleted from |job_controller_set_| when it determines the completion of | |
| 144 // its work. | |
| 145 JobControllerSet job_controller_set_; | |
| 146 | |
| 147 // Owned by this. Reference will be passed to JobContoller to help create | |
| 148 // Jobs. | |
| 149 std::unique_ptr<JobFactoryImpl> job_factory_; | |
| 150 | |
| 147 SpdySessionRequestMap spdy_session_request_map_; | 151 SpdySessionRequestMap spdy_session_request_map_; |
| 148 | 152 |
| 149 // These jobs correspond to jobs orphaned by Requests and now owned by | |
| 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_; | |
| 155 | |
| 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_; | |
| 160 | |
| 161 const bool for_websockets_; | 153 const bool for_websockets_; |
| 162 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); | 154 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); |
| 163 }; | 155 }; |
| 164 | 156 |
| 165 } // namespace net | 157 } // namespace net |
| 166 | 158 |
| 167 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ | 159 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ |
| OLD | NEW |