Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: net/http/http_stream_factory_impl.h

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_stream_factory.cc ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
31 // RequestStream may only be called if |for_websockets| is false. 35 // RequestStream may only be called if |for_websockets| is false.
32 // RequestWebSocketHandshakeStream may only be called if |for_websockets| 36 // RequestWebSocketHandshakeStream may only be called if |for_websockets|
33 // is true. 37 // is true.
34 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets); 38 HttpStreamFactoryImpl(HttpNetworkSession* session, bool for_websockets);
35 ~HttpStreamFactoryImpl() override; 39 ~HttpStreamFactoryImpl() override;
36 40
37 // HttpStreamFactory interface 41 // HttpStreamFactory interface
38 HttpStreamRequest* RequestStream(const HttpRequestInfo& info, 42 HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
39 RequestPriority priority, 43 RequestPriority priority,
40 const SSLConfig& server_ssl_config, 44 const SSLConfig& server_ssl_config,
(...skipping 14 matching lines...) Expand all
55 const HttpRequestInfo& info, 59 const HttpRequestInfo& info,
56 RequestPriority priority, 60 RequestPriority priority,
57 const SSLConfig& server_ssl_config, 61 const SSLConfig& server_ssl_config,
58 const SSLConfig& proxy_ssl_config, 62 const SSLConfig& proxy_ssl_config,
59 HttpStreamRequest::Delegate* delegate, 63 HttpStreamRequest::Delegate* delegate,
60 const BoundNetLog& net_log) override; 64 const BoundNetLog& net_log) override;
61 65
62 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override; 66 void PreconnectStreams(int num_streams, const HttpRequestInfo& info) override;
63 const HostMappingRules* GetHostMappingRules() const override; 67 const HostMappingRules* GetHostMappingRules() const override;
64 68
65 size_t num_orphaned_jobs() const { return orphaned_job_set_.size(); } 69 enum JobType {
70 MAIN,
71 ALTERNATIVE,
72 PRECONNECT,
73 };
66 74
67 private: 75 private:
68 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); 76 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority);
69 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 77 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
70 78
71 class NET_EXPORT_PRIVATE Request; 79 friend class HttpStreamFactoryImplPeer;
72 class NET_EXPORT_PRIVATE Job;
73 80
74 typedef std::set<Request*> RequestSet; 81 typedef std::set<Request*> RequestSet;
75 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap; 82 typedef std::map<SpdySessionKey, RequestSet> SpdySessionRequestMap;
83 typedef std::set<std::unique_ptr<JobController>> JobControllerSet;
76 84
77 // Values must not be changed or reused. Keep in sync with identically named 85 // Values must not be changed or reused. Keep in sync with identically named
78 // enum in histograms.xml. 86 // enum in histograms.xml.
79 enum AlternativeServiceType { 87 enum AlternativeServiceType {
80 NO_ALTERNATIVE_SERVICE = 0, 88 NO_ALTERNATIVE_SERVICE = 0,
81 QUIC_SAME_DESTINATION = 1, 89 QUIC_SAME_DESTINATION = 1,
82 QUIC_DIFFERENT_DESTINATION = 2, 90 QUIC_DIFFERENT_DESTINATION = 2,
83 NOT_QUIC_SAME_DESTINATION = 3, 91 NOT_QUIC_SAME_DESTINATION = 3,
84 NOT_QUIC_DIFFERENT_DESTINATION = 4, 92 NOT_QUIC_DIFFERENT_DESTINATION = 4,
85 MAX_ALTERNATIVE_SERVICE_TYPE 93 MAX_ALTERNATIVE_SERVICE_TYPE
86 }; 94 };
87 95
88 HttpStreamRequest* RequestStreamInternal( 96 HttpStreamRequest* RequestStreamInternal(
89 const HttpRequestInfo& info, 97 const HttpRequestInfo& info,
90 RequestPriority priority, 98 RequestPriority priority,
91 const SSLConfig& server_ssl_config, 99 const SSLConfig& server_ssl_config,
92 const SSLConfig& proxy_ssl_config, 100 const SSLConfig& proxy_ssl_config,
93 HttpStreamRequest::Delegate* delegate, 101 HttpStreamRequest::Delegate* delegate,
94 WebSocketHandshakeStreamBase::CreateHelper* create_helper, 102 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
95 HttpStreamRequest::StreamType stream_type, 103 HttpStreamRequest::StreamType stream_type,
96 const BoundNetLog& net_log); 104 const BoundNetLog& net_log);
97 105
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 106 // Called when a SpdySession is ready. It will find appropriate Requests and
112 // fulfill them. |direct| indicates whether or not |spdy_session| uses a 107 // fulfill them. |direct| indicates whether or not |spdy_session| uses a
113 // proxy. 108 // proxy.
114 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session, 109 void OnNewSpdySessionReady(const base::WeakPtr<SpdySession>& spdy_session,
115 bool direct, 110 bool direct,
116 const SSLConfig& used_ssl_config, 111 const SSLConfig& used_ssl_config,
117 const ProxyInfo& used_proxy_info, 112 const ProxyInfo& used_proxy_info,
118 bool was_npn_negotiated, 113 bool was_npn_negotiated,
119 NextProto protocol_negotiated, 114 NextProto protocol_negotiated,
120 bool using_spdy, 115 bool using_spdy,
121 const BoundNetLog& net_log); 116 const BoundNetLog& net_log);
122 117
123 // Called when the Job detects that the endpoint indicated by the 118 // Called when the Job detects that the endpoint indicated by the
124 // Alternate-Protocol does not work. Lets the factory update 119 // Alternate-Protocol does not work. Lets the factory update
125 // HttpAlternateProtocols with the failure and resets the SPDY session key. 120 // HttpAlternateProtocols with the failure and resets the SPDY session key.
126 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin); 121 void OnBrokenAlternateProtocol(const Job*, const HostPortPair& origin);
127 122
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. 123 // Called when the Preconnect completes. Used for testing.
135 virtual void OnPreconnectsCompleteInternal() {} 124 virtual void OnPreconnectsCompleteInternal() {}
136 125
137 // Returns true if QUIC is whitelisted for |host|. 126 // Called when the JobController finishes service. Delete the JobController
138 bool IsQuicWhitelistedForHost(const std::string& host); 127 // from |job_controller_set_|.
128 void OnJobControllerComplete(JobController* controller);
139 129
140 HttpNetworkSession* const session_; 130 HttpNetworkSession* const session_;
141 131
142 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl 132 // All Requests are handed out to clients. By the time HttpStreamFactoryImpl
143 // is destroyed, all Requests should be deleted (which should remove them from 133 // is destroyed, all Requests should be deleted (which should remove them from
144 // |request_map_|. The Requests will delete the corresponding job. 134 // |request_map_|. The Requests will delete the corresponding job.
145 std::map<const Job*, Request*> request_map_; 135 std::map<const Job*, Request*> request_map_;
146 136
137 // All Requests/Preconnects are assigned with a JobController to manage
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
144 // Factory used by job controllers for creating jobs.
145 std::unique_ptr<JobFactory> job_factory_;
146
147 SpdySessionRequestMap spdy_session_request_map_; 147 SpdySessionRequestMap spdy_session_request_map_;
148 148
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_; 149 const bool for_websockets_;
162 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); 150 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
163 }; 151 };
164 152
165 } // namespace net 153 } // namespace net
166 154
167 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_ 155 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_H_
OLDNEW
« no previous file with comments | « net/http/http_stream_factory.cc ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698