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

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

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_REQUEST_H_ 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "net/http/http_stream_factory_impl.h" 12 #include "net/http/http_stream_factory_impl.h"
13 #include "net/log/net_log.h" 13 #include "net/log/net_log.h"
14 #include "net/socket/connection_attempts.h" 14 #include "net/socket/connection_attempts.h"
15 #include "net/socket/ssl_client_socket.h" 15 #include "net/socket/ssl_client_socket.h"
16 #include "net/spdy/spdy_session_key.h" 16 #include "net/spdy/spdy_session_key.h"
17 #include "net/ssl/ssl_failure_state.h" 17 #include "net/ssl/ssl_failure_state.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 class BidirectionalStreamImpl; 22 class BidirectionalStreamImpl;
23 class ClientSocketHandle; 23 class ClientSocketHandle;
24 class HttpStream; 24 class HttpStream;
25 class SpdySession; 25 class SpdySession;
26 26
27 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { 27 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
28 public: 28 public:
29 Request(const GURL& url, 29 Request(const GURL& url,
30 HttpStreamFactoryImpl* factory, 30 JobController* job_controller,
Randy Smith (Not in Mondays) 2016/05/09 20:42:18 Same reflex for documentation: Why can this class
Zhongyi Shi 2016/05/12 07:26:24 Done.
31 HttpStreamRequest::Delegate* delegate, 31 HttpStreamRequest::Delegate* delegate,
32 WebSocketHandshakeStreamBase::CreateHelper* 32 WebSocketHandshakeStreamBase::CreateHelper*
33 websocket_handshake_stream_create_helper, 33 websocket_handshake_stream_create_helper,
34 const BoundNetLog& net_log, 34 const BoundNetLog& net_log,
35 StreamType stream_type); 35 StreamType stream_type);
36 36
37 ~Request() override; 37 ~Request() override;
38 38
39 // The GURL from the HttpRequestInfo the started the Request. 39 // The GURL from the HttpRequestInfo the started the Request.
40 const GURL& url() const { return url_; } 40 const GURL& url() const { return url_; }
41 41
42 const BoundNetLog& net_log() const { return net_log_; } 42 const BoundNetLog& net_log() const { return net_log_; }
43 43
44 // Called when the Job determines the appropriate |spdy_session_key| for the 44 // Called when the JobController determines the appropriate |spdy_session_key|
45 // Request. Note that this does not mean that SPDY is necessarily supported 45 // for the Request. Note that this does not mean that SPDY is necessarily
46 // for this SpdySessionKey, since we may need to wait for NPN to complete 46 // supported for this SpdySessionKey, since we may need to wait for NPN to
47 // before knowing if SPDY is available. 47 // complete before knowing if SPDY is available.
48 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); 48 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key);
49 bool HasSpdySessionKey() const; 49 bool HasSpdySessionKey() const;
50 50
51 // Attaches |job| to this request. Does not mean that Request will use |job|,
52 // but Request will own |job|.
53 void AttachJob(HttpStreamFactoryImpl::Job* job);
54
55 // Marks completion of the request. Must be called before OnStreamReady(). 51 // Marks completion of the request. Must be called before OnStreamReady().
56 void Complete(bool was_npn_negotiated, 52 void Complete(bool was_npn_negotiated,
57 NextProto protocol_negotiated, 53 NextProto protocol_negotiated,
58 bool using_spdy); 54 bool using_spdy);
59 55
60 // If this Request has a |spdy_session_key_|, remove this session from the 56 // If this Request has a |spdy_session_key_|, remove this session from the
61 // SpdySessionRequestMap. 57 // SpdySessionRequestMap.
62 void RemoveRequestFromSpdySessionRequestMap(); 58 void RemoveRequestFromSpdySessionRequestMap();
63 59
64 // Called by an attached Job if it sets up a SpdySession. 60 // Called by JobController if it sets up a SpdySession.
65 // |stream| is null when |stream_type| is HttpStreamRequest::HTTP_STREAM. 61 // |stream| is null when |stream_type| is HttpStreamRequest::HTTP_STREAM.
66 // |bidirectional_stream_spdy_impl| is null when |stream_type| is 62 // |bidirectional_stream_spdy_impl| is null when |stream_type| is
67 // HttpStreamRequest::BIDIRECTIONAL_STREAM. 63 // HttpStreamRequest::BIDIRECTIONAL_STREAM.
68 void OnNewSpdySessionReady( 64 void OnNewSpdySessionReady(
69 Job* job,
70 std::unique_ptr<HttpStream> stream, 65 std::unique_ptr<HttpStream> stream,
71 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_spdy_impl, 66 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_spdy_impl,
72 const base::WeakPtr<SpdySession>& spdy_session, 67 const base::WeakPtr<SpdySession>& spdy_session,
68 const SSLConfig& used_ssl_config,
69 const ProxyInfo& used_proxy_info,
70 bool was_npn_negotiated,
71 const NextProto& protocol_negotiated,
72 bool using_spdy,
73 const BoundNetLog& net_log,
73 bool direct); 74 bool direct);
74 75
75 // Called by an attached Job to record connection attempts made by the socket 76 // Called by JobController to record connection attempts made by the socket
76 // layer for this stream request. 77 // layer in an attached Job for this stream request.
77 void AddConnectionAttempts(const ConnectionAttempts& attempts); 78 void AddConnectionAttempts(const ConnectionAttempts& attempts);
78 79
79 WebSocketHandshakeStreamBase::CreateHelper* 80 WebSocketHandshakeStreamBase::CreateHelper*
80 websocket_handshake_stream_create_helper() { 81 websocket_handshake_stream_create_helper() {
81 return websocket_handshake_stream_create_helper_; 82 return websocket_handshake_stream_create_helper_;
82 } 83 }
83 84
84 // HttpStreamRequest::Delegate methods which we implement. Note we don't 85 // HttpStreamRequest::Delegate methods which we implement. Note we don't
85 // actually subclass HttpStreamRequest::Delegate. 86 // actually subclass HttpStreamRequest::Delegate.
86 87
87 void OnStreamReady(Job* job, 88 void OnStreamReady(const SSLConfig& used_ssl_config,
88 const SSLConfig& used_ssl_config,
89 const ProxyInfo& used_proxy_info, 89 const ProxyInfo& used_proxy_info,
90 HttpStream* stream); 90 HttpStream* stream);
91 void OnBidirectionalStreamImplReady(Job* job, 91 void OnBidirectionalStreamImplReady(const SSLConfig& used_ssl_config,
92 const SSLConfig& used_ssl_config,
93 const ProxyInfo& used_proxy_info, 92 const ProxyInfo& used_proxy_info,
94 BidirectionalStreamImpl* stream); 93 BidirectionalStreamImpl* stream);
95 94
96 void OnWebSocketHandshakeStreamReady(Job* job, 95 void OnWebSocketHandshakeStreamReady(const SSLConfig& used_ssl_config,
97 const SSLConfig& used_ssl_config,
98 const ProxyInfo& used_proxy_info, 96 const ProxyInfo& used_proxy_info,
99 WebSocketHandshakeStreamBase* stream); 97 WebSocketHandshakeStreamBase* stream);
100 void OnStreamFailed(Job* job, 98 void OnStreamFailed(int status,
101 int status,
102 const SSLConfig& used_ssl_config, 99 const SSLConfig& used_ssl_config,
103 SSLFailureState ssl_failure_state); 100 SSLFailureState ssl_failure_state);
104 void OnCertificateError(Job* job, 101 void OnCertificateError(int status,
105 int status,
106 const SSLConfig& used_ssl_config, 102 const SSLConfig& used_ssl_config,
107 const SSLInfo& ssl_info); 103 const SSLInfo& ssl_info);
108 void OnNeedsProxyAuth(Job* job, 104 void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
109 const HttpResponseInfo& proxy_response,
110 const SSLConfig& used_ssl_config, 105 const SSLConfig& used_ssl_config,
111 const ProxyInfo& used_proxy_info, 106 const ProxyInfo& used_proxy_info,
112 HttpAuthController* auth_controller); 107 HttpAuthController* auth_controller);
113 void OnNeedsClientAuth(Job* job, 108 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
114 const SSLConfig& used_ssl_config,
115 SSLCertRequestInfo* cert_info); 109 SSLCertRequestInfo* cert_info);
116 void OnHttpsProxyTunnelResponse( 110 void OnHttpsProxyTunnelResponse(
117 Job *job,
118 const HttpResponseInfo& response_info, 111 const HttpResponseInfo& response_info,
119 const SSLConfig& used_ssl_config, 112 const SSLConfig& used_ssl_config,
120 const ProxyInfo& used_proxy_info, 113 const ProxyInfo& used_proxy_info,
121 HttpStream* stream); 114 HttpStream* stream);
122 115
123 // HttpStreamRequest methods. 116 // HttpStreamRequest methods.
124 117
125 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; 118 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override;
126 void SetPriority(RequestPriority priority) override; 119 void SetPriority(RequestPriority priority) override;
127 LoadState GetLoadState() const override; 120 LoadState GetLoadState() const override;
128 bool was_npn_negotiated() const override; 121 bool was_npn_negotiated() const override;
129 NextProto protocol_negotiated() const override; 122 NextProto protocol_negotiated() const override;
130 bool using_spdy() const override; 123 bool using_spdy() const override;
131 const ConnectionAttempts& connection_attempts() const override; 124 const ConnectionAttempts& connection_attempts() const override;
132 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 125 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
133 126
134 private: 127 private:
135 // Used to bind |job| to the request and orphan all other jobs in |jobs_|.
136 void BindJob(Job* job);
137
138 // Used to orphan all jobs in |jobs_|.
139 void OrphanJobs();
140
141 // Used to cancel all jobs in |jobs_|.
142 void CancelJobs();
143
144 // Called when a Job succeeds.
145 void OnJobSucceeded(Job* job);
146 128
147 const GURL url_; 129 const GURL url_;
148 HttpStreamFactoryImpl* const factory_; 130 JobController* const job_controller_;
Ryan Hamilton 2016/05/06 20:49:02 nit: comment on ownership. // Unowned.
Randy Smith (Not in Mondays) 2016/05/09 21:42:10 And why it's safe; i.e. that the Request doesn't o
Zhongyi Shi 2016/05/12 07:26:24 Done.
131
149 WebSocketHandshakeStreamBase::CreateHelper* const 132 WebSocketHandshakeStreamBase::CreateHelper* const
150 websocket_handshake_stream_create_helper_; 133 websocket_handshake_stream_create_helper_;
151 HttpStreamRequest::Delegate* const delegate_; 134 HttpStreamRequest::Delegate* const delegate_;
152 const BoundNetLog net_log_; 135 const BoundNetLog net_log_;
153 136
154 // At the point where Job is irrevocably tied to the Request, we set this.
155 std::unique_ptr<Job> bound_job_;
156 std::set<HttpStreamFactoryImpl::Job*> jobs_;
157 std::unique_ptr<const SpdySessionKey> spdy_session_key_; 137 std::unique_ptr<const SpdySessionKey> spdy_session_key_;
158 138
159 bool completed_; 139 bool completed_;
160 bool was_npn_negotiated_; 140 bool was_npn_negotiated_;
161 // Protocol negotiated with the server. 141 // Protocol negotiated with the server.
162 NextProto protocol_negotiated_; 142 NextProto protocol_negotiated_;
163 bool using_spdy_; 143 bool using_spdy_;
164 ConnectionAttempts connection_attempts_; 144 ConnectionAttempts connection_attempts_;
165 145
166 const HttpStreamRequest::StreamType stream_type_; 146 const HttpStreamRequest::StreamType stream_type_;
167 DISALLOW_COPY_AND_ASSIGN(Request); 147 DISALLOW_COPY_AND_ASSIGN(Request);
168 }; 148 };
169 149
170 } // namespace net 150 } // namespace net
171 151
172 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ 152 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698