Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | |
| 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | |
| 7 | |
| 8 #include "net/http/http_stream_factory_impl.h" | |
| 9 | |
| 10 namespace net { | |
| 11 | |
| 12 // HttpStreamFactoryImpl::JobController manages Request and Jobs. | |
| 13 class HttpStreamFactoryImpl::JobController { | |
| 14 public: | |
| 15 JobController(HttpStreamFactoryImpl* factory); | |
| 16 ~JobController(); | |
| 17 | |
| 18 Request* CreatRequest(const HttpRequestInfo& request_info, | |
|
Randy Smith (Not in Mondays)
2016/05/09 20:42:18
Would you be willing to add some documenting comme
Zhongyi Shi
2016/05/12 07:26:24
Comments added. CreateRequest(renamed as Start())
| |
| 19 HttpStreamRequest::Delegate* delegate, | |
| 20 WebSocketHandshakeStreamBase::CreateHelper* | |
| 21 websocket_handshake_stream_create_helper, | |
| 22 const BoundNetLog& net_log, | |
| 23 HttpStreamRequest::StreamType stream_type); | |
| 24 | |
| 25 void Start(HttpNetworkSession* session, | |
| 26 const HttpRequestInfo& request_info, | |
| 27 RequestPriority priority, | |
| 28 const SSLConfig& server_ssl_config, | |
| 29 const SSLConfig& proxy_ssl_config, | |
| 30 HttpStreamRequest::Delegate* delegate, | |
| 31 HttpStreamRequest::StreamType stream_type, | |
| 32 const BoundNetLog& net_log); | |
| 33 | |
| 34 void Preconnect(int num_streams, | |
| 35 HttpNetworkSession* session, | |
| 36 const HttpRequestInfo& request_info, | |
| 37 const SSLConfig& server_ssl_config, | |
| 38 const SSLConfig& proxy_ssl_config); | |
| 39 | |
| 40 LoadState GetLoadState() const; | |
| 41 | |
| 42 void SetPriority(RequestPriority priority); | |
| 43 | |
| 44 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | |
| 45 | |
| 46 // Used to bind |job| to the |request_| and orphan all other jobs in |jobs_|. | |
| 47 void BindJob(Job* job); | |
| 48 | |
| 49 // Used to orphan all jobs in |jobs_|. | |
|
Randy Smith (Not in Mondays)
2016/05/09 21:42:09
nit, suggestion: When you talk about "orphaning" j
| |
| 50 void OrphanJobs(); | |
| 51 | |
| 52 // Called when a Job succeeds. | |
|
Randy Smith (Not in Mondays)
2016/05/09 21:42:09
I think this is an inaccurate comment; at least, i
| |
| 53 void CancelJobs(); | |
| 54 | |
| 55 // Called when a Job succeeds. | |
| 56 void OnJobSucceeded(Job* job); | |
|
Randy Smith (Not in Mondays)
2016/05/09 21:42:09
Why is this public? I think it's only called from
| |
| 57 | |
| 58 void OnRequestFinish(); | |
| 59 | |
| 60 // Marks completion of the |request_|. Must be called before OnStreamReady(). | |
|
Randy Smith (Not in Mondays)
2016/05/09 21:42:09
Suggestion: I wonder if it's worthwhile separating
| |
| 61 void MarkRequestComplete(bool was_npn_negotiated, | |
| 62 NextProto protocol_negotiated, | |
| 63 bool using_spdy); | |
| 64 | |
| 65 void OnStreamReady(Job* job, | |
| 66 const SSLConfig& used_ssl_config, | |
| 67 const ProxyInfo& used_proxy_info, | |
| 68 HttpStream* stream); | |
| 69 | |
| 70 void OnBidirectionalStreamImplReady(Job* job, | |
| 71 const SSLConfig& used_ssl_config, | |
| 72 const ProxyInfo& used_proxy_info, | |
| 73 BidirectionalStreamImpl* stream); | |
| 74 | |
| 75 void OnWebSocketHandshakeStreamReady(Job* job, | |
| 76 const SSLConfig& used_ssl_config, | |
| 77 const ProxyInfo& used_proxy_info, | |
| 78 WebSocketHandshakeStreamBase* stream); | |
| 79 | |
| 80 void OnStreamFailed(Job* job, | |
| 81 int status, | |
| 82 const SSLConfig& used_ssl_config, | |
| 83 SSLFailureState ssl_failure_state); | |
| 84 | |
| 85 void OnCertificateError(Job* job, | |
| 86 int status, | |
| 87 const SSLConfig& used_ssl_config, | |
| 88 const SSLInfo& ssl_info); | |
| 89 | |
| 90 void OnNeedsProxyAuth(Job* job, | |
| 91 const HttpResponseInfo& proxy_response, | |
| 92 const SSLConfig& used_ssl_config, | |
| 93 const ProxyInfo& used_proxy_info, | |
| 94 HttpAuthController* auth_controller); | |
| 95 | |
| 96 void OnNeedsClientAuth(Job* job, | |
| 97 const SSLConfig& used_ssl_config, | |
| 98 SSLCertRequestInfo* cert_info); | |
| 99 | |
| 100 void OnHttpsProxyTunnelResponse(Job* job, | |
| 101 const HttpResponseInfo& response_info, | |
| 102 const SSLConfig& used_ssl_config, | |
| 103 const ProxyInfo& used_proxy_info, | |
| 104 HttpStream* stream); | |
| 105 | |
| 106 // Notify the |request_| and |factoy_| of the readiness of new SPDY session. | |
|
Randy Smith (Not in Mondays)
2016/05/09 21:42:09
nit: factory_
Zhongyi Shi
2016/05/12 07:26:23
Done.
| |
| 107 void OnNewSpdySessionReady( | |
| 108 Job* job, | |
| 109 std::unique_ptr<HttpStream> stream, | |
| 110 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_impl, | |
| 111 const base::WeakPtr<SpdySession>& spdy_session, | |
| 112 bool direct); | |
| 113 | |
| 114 // Invoked when the Job finishes pre-connecting sockets. | |
| 115 void OnPreconnectsComplete(Job* job); | |
| 116 | |
| 117 // Invoked when an orphaned Job finishes. | |
| 118 void OnOrphanedJobComplete(const Job* job); | |
| 119 | |
| 120 // Called by an attached Job to record connection attempts made by the socket | |
| 121 // layer to |request_|. | |
| 122 void AddConnectionAttemptsToRequest(const ConnectionAttempts& attempts); | |
| 123 | |
| 124 // Called when Job determines the appropriate |spdy_session_key| for the | |
| 125 // Request. Note that this does not mean that SPDY is necessarily supported | |
| 126 // for this SpdySessionKey, since we may need to wait for NPN to complete | |
| 127 // before knowing if SPDY is available. | |
| 128 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); | |
| 129 | |
| 130 // Remove session from the SpdySessionRequestMap. | |
| 131 void RemoveRequestFromSpdySessionRequestMap(); | |
| 132 | |
| 133 void MaybeNotifyFactoryOfCompletion(); | |
|
Randy Smith (Not in Mondays)
2016/05/09 21:42:09
As above, why not private? (You should do your ow
| |
| 134 | |
| 135 const BoundNetLog& GetNetLogFromRequest() const; | |
| 136 | |
| 137 SpdySessionRequestMap& GetSpdySessionRequestMap() { | |
| 138 return factory_->spdy_session_request_map_; | |
| 139 } | |
| 140 | |
| 141 bool for_websockets() { return factory_->for_websockets_; } | |
| 142 | |
| 143 WebSocketHandshakeStreamBase::CreateHelper* | |
| 144 websocket_handshake_stream_create_helper(); | |
| 145 | |
| 146 private: | |
| 147 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); | |
| 148 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | |
| 149 | |
| 150 // Creates Job(s) for |request_|. Jobs will be owned by |this|. | |
| 151 void CreateJobs(); | |
| 152 | |
| 153 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. | |
| 154 void AttachJob(Job* job); | |
| 155 | |
| 156 HttpStreamFactoryImpl* factory_; | |
| 157 | |
| 158 // Request will be handed out to factory once created. This just keeps an | |
| 159 // reference. It will be set to NULL once the request is completed. | |
| 160 Request* request_; | |
|
Randy Smith (Not in Mondays)
2016/05/09 20:42:18
This naively strikes me as fairly dangerous becaus
Zhongyi Shi
2016/05/12 07:26:23
Done.
| |
| 161 | |
| 162 std::set<Job*> jobs_; | |
|
Ryan Hamilton
2016/05/06 20:49:02
These jobs are owned by this, right? If so, perhap
Zhongyi Shi
2016/05/12 07:26:23
Acknowledged.
| |
| 163 | |
| 164 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a | |
| 165 // connection. If |alternative_job_| is unable to do so, |this| will notify | |
| 166 // |main_job_| to proceed and then race the two jobs. | |
| 167 Job* main_job_; | |
| 168 Job* alternative_job_; | |
| 169 | |
| 170 // At the point where a Job is irrevocably tied to |request_|, we set this. | |
| 171 std::unique_ptr<Job> bound_job_; | |
| 172 | |
| 173 // These jobs correspond to jobs orphaned by |request_|. Since they are no | |
| 174 // longer tied to Requests, they will not be canceled when |request_| is | |
| 175 // canceled. Therefore, in ~JobController, it is possible for some jobs to | |
| 176 // still exist in this set. Leftover jobs will be deleted when the | |
| 177 // JobController is destroyed. | |
| 178 std::set<const Job*> orphaned_job_set_; | |
|
Ryan Hamilton
2016/05/06 20:49:02
Just an observation, there are quite a few differe
Zhongyi Shi
2016/05/12 07:26:24
Done.
| |
| 179 }; | |
| 180 | |
| 181 } // namespace net | |
| 182 | |
| 183 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | |
| OLD | NEW |