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

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

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add JobFactory interface in JobController, remove JobControllerPeer 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
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_JOB_H_ 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
15 #include "net/base/net_export.h"
15 #include "net/base/request_priority.h" 16 #include "net/base/request_priority.h"
16 #include "net/http/http_auth.h" 17 #include "net/http/http_auth.h"
17 #include "net/http/http_auth_controller.h" 18 #include "net/http/http_auth_controller.h"
18 #include "net/http/http_request_info.h" 19 #include "net/http/http_request_info.h"
19 #include "net/http/http_stream_factory_impl.h" 20 #include "net/http/http_stream_factory_impl.h"
20 #include "net/log/net_log.h" 21 #include "net/log/net_log.h"
21 #include "net/proxy/proxy_service.h" 22 #include "net/proxy/proxy_service.h"
22 #include "net/quic/quic_stream_factory.h" 23 #include "net/quic/quic_stream_factory.h"
23 #include "net/socket/client_socket_handle.h" 24 #include "net/socket/client_socket_handle.h"
24 #include "net/socket/client_socket_pool_manager.h" 25 #include "net/socket/client_socket_pool_manager.h"
25 #include "net/socket/ssl_client_socket.h" 26 #include "net/socket/ssl_client_socket.h"
26 #include "net/spdy/spdy_session_key.h" 27 #include "net/spdy/spdy_session_key.h"
27 #include "net/ssl/ssl_config_service.h" 28 #include "net/ssl/ssl_config_service.h"
28 29
29 namespace net { 30 namespace net {
30 31
31 class BidirectionalStreamImpl; 32 class BidirectionalStreamImpl;
32 class ClientSocketHandle; 33 class ClientSocketHandle;
33 class HttpAuthController; 34 class HttpAuthController;
34 class HttpNetworkSession; 35 class HttpNetworkSession;
35 class HttpStream; 36 class HttpStream;
36 class SpdySessionPool; 37 class SpdySessionPool;
37 class QuicHttpStream; 38 class QuicHttpStream;
39 class TestJobControllerPeer;
38 40
39 // An HttpStreamRequestImpl exists for each stream which is in progress of being 41 // An HttpStreamRequestImpl exists for each stream which is in progress of being
40 // created for the StreamFactory. 42 // created for the StreamFactory.
41 class HttpStreamFactoryImpl::Job { 43 class HttpStreamFactoryImpl::Job {
42 public: 44 public:
45 class NET_EXPORT_PRIVATE Delegate {
46 public:
47 virtual ~Delegate() {}
48
49 virtual void OnStreamReady(Job* job,
50 const SSLConfig& used_ssl_config,
51 const ProxyInfo& used_proxy_info) = 0;
52
53 virtual void OnBidirectionalStreamImplReady(
54 Job* job,
55 const SSLConfig& used_ssl_config,
56 const ProxyInfo& used_proxy_info) = 0;
57 virtual void OnWebSocketHandshakeStreamReady(
58 Job* job,
59 const SSLConfig& used_ssl_config,
60 const ProxyInfo& used_proxy_info,
61 WebSocketHandshakeStreamBase* stream) = 0;
62
63 virtual void OnStreamFailed(Job* job,
64 int status,
65 const SSLConfig& used_ssl_config,
66 SSLFailureState ssl_failure_state) = 0;
67
68 virtual void OnCertificateError(Job* job,
69 int status,
70 const SSLConfig& used_ssl_config,
71 const SSLInfo& ssl_info) = 0;
72
73 virtual void OnHttpsProxyTunnelResponse(
74 Job* job,
75 const HttpResponseInfo& response_info,
76 const SSLConfig& used_ssl_config,
77 const ProxyInfo& used_proxy_info,
78 HttpStream* stream) = 0;
79
80 virtual void OnNeedsClientAuth(Job* job,
81 const SSLConfig& used_ssl_config,
82 SSLCertRequestInfo* cert_info) = 0;
83
84 virtual void OnNeedsProxyAuth(Job* job,
85 const HttpResponseInfo& proxy_response,
86 const SSLConfig& used_ssl_config,
87 const ProxyInfo& used_proxy_info,
88 HttpAuthController* auth_controller) = 0;
89
90 // Invoked to notify the Request and Factory of the readiness of new
91 // SPDY session.
92 virtual void OnNewSpdySessionReady(
93 Job* job,
94 const base::WeakPtr<SpdySession>& spdy_session,
95 bool direct) = 0;
96
97 // Invoked when the orphaned |job| finishes.
98 virtual void OnOrphanedJobComplete(const Job* job) = 0;
99
100 // Invoked when the |job| finishes pre-connecting sockets.
101 virtual void OnPreconnectsComplete(Job* job) = 0;
102
103 // Invoked to record connection attempts made by the socket layer to
104 // Request if |job| is associated with Request.
105 virtual void AddConnectionAttemptsToRequest(
106 Job* job,
107 const ConnectionAttempts& attempts) = 0;
108
109 // Called when |job| determines the appropriate |spdy_session_key| for the
110 // Request. Note that this does not mean that SPDY is necessarily supported
111 // for this SpdySessionKey, since we may need to wait for NPN to complete
112 // before knowing if SPDY is available.
113 virtual void SetSpdySessionKey(Job* job,
114 const SpdySessionKey& spdy_session_key) = 0;
115
116 // Remove session from the SpdySessionRequestMap.
117 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0;
118
119 virtual const BoundNetLog* GetNetLog(Job* job) const = 0;
120
121 virtual WebSocketHandshakeStreamBase::CreateHelper*
122 websocket_handshake_stream_create_helper() = 0;
123
124 virtual bool for_websockets() = 0;
125 };
126
43 // Constructor for non-alternative Job. 127 // Constructor for non-alternative Job.
44 Job(HttpStreamFactoryImpl* stream_factory, 128 // Job is owned by |delegate|, hence |delegate| is valid for the
129 // lifetime of the Job.
130 Job(Delegate* delegate,
131 JobType job_type,
45 HttpNetworkSession* session, 132 HttpNetworkSession* session,
46 const HttpRequestInfo& request_info, 133 const HttpRequestInfo& request_info,
47 RequestPriority priority, 134 RequestPriority priority,
48 const SSLConfig& server_ssl_config, 135 const SSLConfig& server_ssl_config,
49 const SSLConfig& proxy_ssl_config, 136 const SSLConfig& proxy_ssl_config,
50 HostPortPair destination, 137 HostPortPair destination,
51 GURL origin_url, 138 GURL origin_url,
52 NetLog* net_log); 139 NetLog* net_log);
140
53 // Constructor for alternative Job. 141 // Constructor for alternative Job.
54 Job(HttpStreamFactoryImpl* stream_factory, 142 // Job is owned by |delegate|, hence |delegate| is valid for the
143 // lifetime of the Job.
144 Job(Delegate* delegate,
145 JobType job_type,
55 HttpNetworkSession* session, 146 HttpNetworkSession* session,
56 const HttpRequestInfo& request_info, 147 const HttpRequestInfo& request_info,
57 RequestPriority priority, 148 RequestPriority priority,
58 const SSLConfig& server_ssl_config, 149 const SSLConfig& server_ssl_config,
59 const SSLConfig& proxy_ssl_config, 150 const SSLConfig& proxy_ssl_config,
60 HostPortPair destination, 151 HostPortPair destination,
61 GURL origin_url, 152 GURL origin_url,
62 AlternativeService alternative_service, 153 AlternativeService alternative_service,
63 NetLog* net_log); 154 NetLog* net_log);
64 ~Job(); 155 virtual ~Job();
65 156
66 // Start initiates the process of creating a new HttpStream. |request| will be 157 // Start initiates the process of creating a new HttpStream.
67 // notified upon completion if the Job has not been Orphan()'d. 158 // |delegate_| will be notified upon completion.
68 void Start(Request* request); 159 virtual void Start(HttpStreamRequest::StreamType stream_type);
69 160
70 // Preconnect will attempt to request |num_streams| sockets from the 161 // Preconnect will attempt to request |num_streams| sockets from the
71 // appropriate ClientSocketPool. 162 // appropriate ClientSocketPool.
72 int Preconnect(int num_streams); 163 int Preconnect(int num_streams);
73 164
74 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); 165 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials);
75 LoadState GetLoadState() const; 166 LoadState GetLoadState() const;
76 167
77 // Tells |this| to wait for |job| to resume it. 168 // Tells |this| to wait for |job| to resume it.
78 void WaitFor(Job* job); 169 void WaitFor(Job* job);
79 170
80 // Tells |this| that |job| has determined it still needs to continue 171 // Tells |this| that |job| has determined it still needs to continue
81 // connecting, so allow |this| to continue after the specified |delay|. If 172 // connecting, so allow |this| to continue after the specified |delay|. If
82 // this is not called, then |request_| is expected to cancel |this| by 173 // this is not called, then |request_| is expected to cancel |this| by
83 // deleting it. 174 // deleting it.
84 void Resume(Job* job, const base::TimeDelta& delay); 175 void Resume(Job* job, const base::TimeDelta& delay);
85 176
86 // Used to detach the Job from |request|. 177 // Called to detach |this| Job. May resume the other Job, will disconnect
87 void Orphan(const Request* request); 178 // the socket for |this| Job, and notify |delegate| upon completion.
179 void Orphan();
88 180
89 void SetPriority(RequestPriority priority); 181 void SetPriority(RequestPriority priority);
90 182
91 RequestPriority priority() const { return priority_; } 183 RequestPriority priority() const { return priority_; }
92 bool was_npn_negotiated() const; 184 bool was_npn_negotiated() const;
93 NextProto protocol_negotiated() const; 185 NextProto protocol_negotiated() const;
94 bool using_spdy() const; 186 bool using_spdy() const;
95 const BoundNetLog& net_log() const { return net_log_; } 187 const BoundNetLog& net_log() const { return net_log_; }
96 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 188 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
97 189
190 std::unique_ptr<HttpStream> GetStream() { return std::move(stream_); }
191
192 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); }
193
194 std::unique_ptr<BidirectionalStreamImpl> GetBidirectionalStream() {
195 return std::move(bidirectional_stream_impl_);
196 }
197
98 const SSLConfig& server_ssl_config() const; 198 const SSLConfig& server_ssl_config() const;
99 const SSLConfig& proxy_ssl_config() const; 199 const SSLConfig& proxy_ssl_config() const;
100 const ProxyInfo& proxy_info() const; 200 const ProxyInfo& proxy_info() const;
101 201
102 // Indicates whether or not this job is performing a preconnect.
103 bool IsPreconnecting() const;
104
105 // Indicates whether or not this Job has been orphaned by a Request.
106 bool IsOrphaned() const;
107
108 // Called to indicate that this job succeeded, and some other jobs 202 // Called to indicate that this job succeeded, and some other jobs
109 // will be orphaned. 203 // will be orphaned.
110 void ReportJobSucceededForRequest(); 204 void ReportJobSucceededForRequest();
111 205
112 // Marks that the other |job| has completed. 206 // Marks that the other |job| has completed.
113 void MarkOtherJobComplete(const Job& job); 207 virtual void MarkOtherJobComplete(const Job& job);
208
209 JobType job_type() const { return job_type_; }
114 210
115 private: 211 private:
116 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 212 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
117 213
118 enum State { 214 enum State {
119 STATE_START, 215 STATE_START,
120 STATE_RESOLVE_PROXY, 216 STATE_RESOLVE_PROXY,
121 STATE_RESOLVE_PROXY_COMPLETE, 217 STATE_RESOLVE_PROXY_COMPLETE,
122 218
123 // Note that when Alternate-Protocol says we can connect to an alternate 219 // Note that when Alternate-Protocol says we can connect to an alternate
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Invoked by the transport socket pool after host resolution is complete 407 // Invoked by the transport socket pool after host resolution is complete
312 // to allow the connection to be aborted, if a matching SPDY session can 408 // to allow the connection to be aborted, if a matching SPDY session can
313 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a 409 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a
314 // session is found, and OK otherwise. 410 // session is found, and OK otherwise.
315 static int OnHostResolution(SpdySessionPool* spdy_session_pool, 411 static int OnHostResolution(SpdySessionPool* spdy_session_pool,
316 const SpdySessionKey& spdy_session_key, 412 const SpdySessionKey& spdy_session_key,
317 const GURL& origin_url, 413 const GURL& origin_url,
318 const AddressList& addresses, 414 const AddressList& addresses,
319 const BoundNetLog& net_log); 415 const BoundNetLog& net_log);
320 416
321 Request* request_;
322
323 const HttpRequestInfo request_info_; 417 const HttpRequestInfo request_info_;
324 RequestPriority priority_; 418 RequestPriority priority_;
325 ProxyInfo proxy_info_; 419 ProxyInfo proxy_info_;
326 SSLConfig server_ssl_config_; 420 SSLConfig server_ssl_config_;
327 SSLConfig proxy_ssl_config_; 421 SSLConfig proxy_ssl_config_;
328 const BoundNetLog net_log_; 422 const BoundNetLog net_log_;
329 423
330 CompletionCallback io_callback_; 424 CompletionCallback io_callback_;
331 std::unique_ptr<ClientSocketHandle> connection_; 425 std::unique_ptr<ClientSocketHandle> connection_;
332 HttpNetworkSession* const session_; 426 HttpNetworkSession* const session_;
333 HttpStreamFactoryImpl* const stream_factory_;
334 State next_state_; 427 State next_state_;
335 ProxyService::PacRequest* pac_request_; 428 ProxyService::PacRequest* pac_request_;
336 SSLInfo ssl_info_; 429 SSLInfo ssl_info_;
337 430
338 // The server we are trying to reach, could be that of the origin or of the 431 // The server we are trying to reach, could be that of the origin or of the
339 // alternative service (after applying host mapping rules). 432 // alternative service (after applying host mapping rules).
340 HostPortPair destination_; 433 HostPortPair destination_;
341 434
342 // The origin url we're trying to reach. This url may be different from the 435 // The origin url we're trying to reach. This url may be different from the
343 // original request when host mapping rules are set-up. 436 // original request when host mapping rules are set-up.
344 GURL origin_url_; 437 GURL origin_url_;
345 438
346 // AlternativeService for this Job if this is an alternative Job. 439 // AlternativeService for this Job if this is an alternative Job.
347 const AlternativeService alternative_service_; 440 const AlternativeService alternative_service_;
348 441
349 // AlternativeService for the other Job if this is not an alternative Job. 442 // AlternativeService for the other Job if this is not an alternative Job.
350 AlternativeService other_job_alternative_service_; 443 AlternativeService other_job_alternative_service_;
351 444
445 // Unowned. |this| job is owned by |delegate_|.
446 Delegate* delegate_;
447
448 JobType job_type_;
449
352 // This is the Job we're dependent on. It will notify us if/when it's OK to 450 // This is the Job we're dependent on. It will notify us if/when it's OK to
353 // proceed. 451 // proceed.
354 Job* blocking_job_; 452 Job* blocking_job_;
355 453
356 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. 454 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection.
357 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to 455 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to
358 // proceed and then race the two Jobs. 456 // proceed and then race the two Jobs.
359 Job* waiting_job_; 457 Job* waiting_job_;
360 458
361 base::TimeDelta wait_time_; 459 base::TimeDelta wait_time_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 HttpStreamRequest::StreamType stream_type_; 517 HttpStreamRequest::StreamType stream_type_;
420 518
421 base::WeakPtrFactory<Job> ptr_factory_; 519 base::WeakPtrFactory<Job> ptr_factory_;
422 520
423 DISALLOW_COPY_AND_ASSIGN(Job); 521 DISALLOW_COPY_AND_ASSIGN(Job);
424 }; 522 };
425 523
426 } // namespace net 524 } // namespace net
427 525
428 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 526 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698