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

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: refine comments 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_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"
(...skipping 23 matching lines...) Expand all
34 class HttpNetworkSession; 34 class HttpNetworkSession;
35 class HttpStream; 35 class HttpStream;
36 class SpdySessionPool; 36 class SpdySessionPool;
37 class QuicHttpStream; 37 class QuicHttpStream;
38 38
39 // An HttpStreamRequestImpl exists for each stream which is in progress of being 39 // An HttpStreamRequestImpl exists for each stream which is in progress of being
40 // created for the StreamFactory. 40 // created for the StreamFactory.
41 class HttpStreamFactoryImpl::Job { 41 class HttpStreamFactoryImpl::Job {
42 public: 42 public:
43 // Constructor for non-alternative Job. 43 // Constructor for non-alternative Job.
44 Job(HttpStreamFactoryImpl* stream_factory, 44 // Job is owned by JobController, hence |job_controller| is valid for the
45 // lifetime of the Job.
46 Job(JobController* job_controller,
47 JobType job_type,
45 HttpNetworkSession* session, 48 HttpNetworkSession* session,
46 const HttpRequestInfo& request_info, 49 const HttpRequestInfo& request_info,
47 RequestPriority priority, 50 RequestPriority priority,
48 const SSLConfig& server_ssl_config, 51 const SSLConfig& server_ssl_config,
49 const SSLConfig& proxy_ssl_config, 52 const SSLConfig& proxy_ssl_config,
50 HostPortPair destination, 53 HostPortPair destination,
51 GURL origin_url, 54 GURL origin_url,
52 NetLog* net_log); 55 NetLog* net_log);
56
53 // Constructor for alternative Job. 57 // Constructor for alternative Job.
54 Job(HttpStreamFactoryImpl* stream_factory, 58 // Job is owned by JobController, hence |job_controller| is valid for the
59 // lifetime of the Job.
60 Job(JobController* job_controller,
61 JobType job_type,
55 HttpNetworkSession* session, 62 HttpNetworkSession* session,
56 const HttpRequestInfo& request_info, 63 const HttpRequestInfo& request_info,
57 RequestPriority priority, 64 RequestPriority priority,
58 const SSLConfig& server_ssl_config, 65 const SSLConfig& server_ssl_config,
59 const SSLConfig& proxy_ssl_config, 66 const SSLConfig& proxy_ssl_config,
60 HostPortPair destination, 67 HostPortPair destination,
61 GURL origin_url, 68 GURL origin_url,
62 AlternativeService alternative_service, 69 AlternativeService alternative_service,
63 NetLog* net_log); 70 NetLog* net_log);
64 ~Job(); 71 ~Job();
65 72
66 // Start initiates the process of creating a new HttpStream. |request| will be 73 // Start initiates the process of creating a new HttpStream.
67 // notified upon completion if the Job has not been Orphan()'d. 74 // |job_controller_| will be notified upon completion.
68 void Start(Request* request); 75 void Start(HttpStreamRequest::StreamType stream_type);
69 76
70 // Preconnect will attempt to request |num_streams| sockets from the 77 // Preconnect will attempt to request |num_streams| sockets from the
71 // appropriate ClientSocketPool. 78 // appropriate ClientSocketPool.
72 int Preconnect(int num_streams); 79 int Preconnect(int num_streams);
73 80
74 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); 81 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials);
75 LoadState GetLoadState() const; 82 LoadState GetLoadState() const;
76 83
77 // Tells |this| to wait for |job| to resume it. 84 // Tells |this| to wait for |job| to resume it.
78 void WaitFor(Job* job); 85 void WaitFor(Job* job);
79 86
80 // Tells |this| that |job| has determined it still needs to continue 87 // Tells |this| that |job| has determined it still needs to continue
81 // connecting, so allow |this| to continue after the specified |delay|. If 88 // connecting, so allow |this| to continue after the specified |delay|. If
82 // this is not called, then |request_| is expected to cancel |this| by 89 // this is not called, then |request_| is expected to cancel |this| by
83 // deleting it. 90 // deleting it.
84 void Resume(Job* job, const base::TimeDelta& delay); 91 void Resume(Job* job, const base::TimeDelta& delay);
85 92
86 // Used to detach the Job from |request|. 93 // Called to detach |this| Job. May resume the other Job, will disconnect
87 void Orphan(const Request* request); 94 // the socket for |this| Job, and notify JobController upon completion.
95 void Orphan();
88 96
89 void SetPriority(RequestPriority priority); 97 void SetPriority(RequestPriority priority);
90 98
91 RequestPriority priority() const { return priority_; } 99 RequestPriority priority() const { return priority_; }
92 bool was_npn_negotiated() const; 100 bool was_npn_negotiated() const;
93 NextProto protocol_negotiated() const; 101 NextProto protocol_negotiated() const;
94 bool using_spdy() const; 102 bool using_spdy() const;
95 const BoundNetLog& net_log() const { return net_log_; } 103 const BoundNetLog& net_log() const { return net_log_; }
96 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 104 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
97 105
106 std::unique_ptr<HttpStream> GetStream() { return std::move(stream_); }
tbansal1 2016/05/18 00:29:09 nit: These two functions should be defined in the
107
108 std::unique_ptr<BidirectionalStreamImpl> GetBidirectionalStream() {
109 return std::move(bidirectional_stream_impl_);
110 }
111
98 const SSLConfig& server_ssl_config() const; 112 const SSLConfig& server_ssl_config() const;
99 const SSLConfig& proxy_ssl_config() const; 113 const SSLConfig& proxy_ssl_config() const;
100 const ProxyInfo& proxy_info() const; 114 const ProxyInfo& proxy_info() const;
101 115
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 116 // Called to indicate that this job succeeded, and some other jobs
109 // will be orphaned. 117 // will be orphaned.
110 void ReportJobSucceededForRequest(); 118 void ReportJobSucceededForRequest();
111 119
112 // Marks that the other |job| has completed. 120 // Marks that the other |job| has completed.
113 void MarkOtherJobComplete(const Job& job); 121 void MarkOtherJobComplete(const Job& job);
114 122
123 JobType job_type() const { return job_type_; }
124
115 private: 125 private:
116 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 126 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
117 127
118 enum State { 128 enum State {
119 STATE_START, 129 STATE_START,
120 STATE_RESOLVE_PROXY, 130 STATE_RESOLVE_PROXY,
121 STATE_RESOLVE_PROXY_COMPLETE, 131 STATE_RESOLVE_PROXY_COMPLETE,
122 132
123 // Note that when Alternate-Protocol says we can connect to an alternate 133 // Note that when Alternate-Protocol says we can connect to an alternate
124 // port using a different protocol, we have the choice of communicating over 134 // port using a different protocol, we have the choice of communicating over
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Invoked by the transport socket pool after host resolution is complete 321 // 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 322 // 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 323 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a
314 // session is found, and OK otherwise. 324 // session is found, and OK otherwise.
315 static int OnHostResolution(SpdySessionPool* spdy_session_pool, 325 static int OnHostResolution(SpdySessionPool* spdy_session_pool,
316 const SpdySessionKey& spdy_session_key, 326 const SpdySessionKey& spdy_session_key,
317 const GURL& origin_url, 327 const GURL& origin_url,
318 const AddressList& addresses, 328 const AddressList& addresses,
319 const BoundNetLog& net_log); 329 const BoundNetLog& net_log);
320 330
321 Request* request_;
322
323 const HttpRequestInfo request_info_; 331 const HttpRequestInfo request_info_;
324 RequestPriority priority_; 332 RequestPriority priority_;
325 ProxyInfo proxy_info_; 333 ProxyInfo proxy_info_;
326 SSLConfig server_ssl_config_; 334 SSLConfig server_ssl_config_;
327 SSLConfig proxy_ssl_config_; 335 SSLConfig proxy_ssl_config_;
328 const BoundNetLog net_log_; 336 const BoundNetLog net_log_;
329 337
330 CompletionCallback io_callback_; 338 CompletionCallback io_callback_;
331 std::unique_ptr<ClientSocketHandle> connection_; 339 std::unique_ptr<ClientSocketHandle> connection_;
332 HttpNetworkSession* const session_; 340 HttpNetworkSession* const session_;
333 HttpStreamFactoryImpl* const stream_factory_;
334 State next_state_; 341 State next_state_;
335 ProxyService::PacRequest* pac_request_; 342 ProxyService::PacRequest* pac_request_;
336 SSLInfo ssl_info_; 343 SSLInfo ssl_info_;
337 344
338 // The server we are trying to reach, could be that of the origin or of the 345 // The server we are trying to reach, could be that of the origin or of the
339 // alternative service (after applying host mapping rules). 346 // alternative service (after applying host mapping rules).
340 HostPortPair destination_; 347 HostPortPair destination_;
341 348
342 // The origin url we're trying to reach. This url may be different from the 349 // 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. 350 // original request when host mapping rules are set-up.
344 GURL origin_url_; 351 GURL origin_url_;
345 352
346 // AlternativeService for this Job if this is an alternative Job. 353 // AlternativeService for this Job if this is an alternative Job.
347 const AlternativeService alternative_service_; 354 const AlternativeService alternative_service_;
348 355
349 // AlternativeService for the other Job if this is not an alternative Job. 356 // AlternativeService for the other Job if this is not an alternative Job.
350 AlternativeService other_job_alternative_service_; 357 AlternativeService other_job_alternative_service_;
351 358
359 // Unowned. |this| job is owned by |job_controller_|.
360 JobController* job_controller_;
361
362 JobType job_type_;
tbansal1 2016/05/18 00:29:09 This can be a const variable. Right?
363
352 // This is the Job we're dependent on. It will notify us if/when it's OK to 364 // This is the Job we're dependent on. It will notify us if/when it's OK to
353 // proceed. 365 // proceed.
354 Job* blocking_job_; 366 Job* blocking_job_;
355 367
356 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. 368 // |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 369 // 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. 370 // proceed and then race the two Jobs.
359 Job* waiting_job_; 371 Job* waiting_job_;
360 372
361 base::TimeDelta wait_time_; 373 base::TimeDelta wait_time_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 HttpStreamRequest::StreamType stream_type_; 431 HttpStreamRequest::StreamType stream_type_;
420 432
421 base::WeakPtrFactory<Job> ptr_factory_; 433 base::WeakPtrFactory<Job> ptr_factory_;
422 434
423 DISALLOW_COPY_AND_ASSIGN(Job); 435 DISALLOW_COPY_AND_ASSIGN(Job);
424 }; 436 };
425 437
426 } // namespace net 438 } // namespace net
427 439
428 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 440 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698