OLD | NEW |
---|---|
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/net_export.h" |
16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
17 #include "net/http/bidirectional_stream_impl.h" | 17 #include "net/http/bidirectional_stream_impl.h" |
18 #include "net/http/http_auth.h" | 18 #include "net/http/http_auth.h" |
19 #include "net/http/http_auth_controller.h" | 19 #include "net/http/http_auth_controller.h" |
20 #include "net/http/http_request_info.h" | 20 #include "net/http/http_request_info.h" |
21 #include "net/http/http_stream_factory_impl.h" | 21 #include "net/http/http_stream_factory_impl.h" |
22 #include "net/log/net_log.h" | 22 #include "net/log/net_log.h" |
23 #include "net/proxy/proxy_server.h" | |
23 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
24 #include "net/quic/chromium/quic_stream_factory.h" | 25 #include "net/quic/chromium/quic_stream_factory.h" |
25 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
26 #include "net/socket/client_socket_pool_manager.h" | 27 #include "net/socket/client_socket_pool_manager.h" |
27 #include "net/socket/ssl_client_socket.h" | 28 #include "net/socket/ssl_client_socket.h" |
28 #include "net/spdy/spdy_session_key.h" | 29 #include "net/spdy/spdy_session_key.h" |
29 #include "net/ssl/ssl_config_service.h" | 30 #include "net/ssl/ssl_config_service.h" |
30 | 31 |
31 namespace net { | 32 namespace net { |
32 | 33 |
33 class ClientSocketHandle; | 34 class ClientSocketHandle; |
34 class HttpAuthController; | 35 class HttpAuthController; |
35 class HttpNetworkSession; | 36 class HttpNetworkSession; |
36 class HttpStream; | 37 class HttpStream; |
37 class SpdySessionPool; | 38 class SpdySessionPool; |
39 struct SSLConfig; | |
38 class QuicHttpStream; | 40 class QuicHttpStream; |
39 | 41 |
40 // An HttpStreamRequestImpl exists for each stream which is in progress of being | 42 // An HttpStreamRequestImpl exists for each stream which is in progress of being |
41 // created for the StreamFactory. | 43 // created for the StreamFactory. |
42 class HttpStreamFactoryImpl::Job { | 44 class HttpStreamFactoryImpl::Job { |
43 public: | 45 public: |
44 // Delegate to report Job's status to Request and HttpStreamFactory. | 46 // Delegate to report Job's status to Request and HttpStreamFactory. |
45 class NET_EXPORT_PRIVATE Delegate { | 47 class NET_EXPORT_PRIVATE Delegate { |
46 public: | 48 public: |
47 virtual ~Delegate() {} | 49 virtual ~Delegate() {} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 const SSLConfig& used_ssl_config, | 91 const SSLConfig& used_ssl_config, |
90 SSLCertRequestInfo* cert_info) = 0; | 92 SSLCertRequestInfo* cert_info) = 0; |
91 | 93 |
92 // Invoked when |job| needs proxy authentication. | 94 // Invoked when |job| needs proxy authentication. |
93 virtual void OnNeedsProxyAuth(Job* job, | 95 virtual void OnNeedsProxyAuth(Job* job, |
94 const HttpResponseInfo& proxy_response, | 96 const HttpResponseInfo& proxy_response, |
95 const SSLConfig& used_ssl_config, | 97 const SSLConfig& used_ssl_config, |
96 const ProxyInfo& used_proxy_info, | 98 const ProxyInfo& used_proxy_info, |
97 HttpAuthController* auth_controller) = 0; | 99 HttpAuthController* auth_controller) = 0; |
98 | 100 |
101 // Invoked when |job| has completed proxy resolution. The delegate may | |
102 // create an alternative proxy server job to fetch the request. | |
103 virtual void OnResolveProxyComplete( | |
104 Job* job, | |
105 const HttpRequestInfo& request_info, | |
106 RequestPriority priority, | |
107 const SSLConfig& server_ssl_config, | |
108 const SSLConfig& proxy_ssl_config, | |
109 HttpStreamRequest::StreamType stream_type) = 0; | |
110 | |
99 // Invoked to notify the Request and Factory of the readiness of new | 111 // Invoked to notify the Request and Factory of the readiness of new |
100 // SPDY session. | 112 // SPDY session. |
101 virtual void OnNewSpdySessionReady( | 113 virtual void OnNewSpdySessionReady( |
102 Job* job, | 114 Job* job, |
103 const base::WeakPtr<SpdySession>& spdy_session, | 115 const base::WeakPtr<SpdySession>& spdy_session, |
104 bool direct) = 0; | 116 bool direct) = 0; |
105 | 117 |
106 // Invoked when the orphaned |job| finishes. | 118 // Invoked when the orphaned |job| finishes. |
107 virtual void OnOrphanedJobComplete(const Job* job) = 0; | 119 virtual void OnOrphanedJobComplete(const Job* job) = 0; |
108 | 120 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 JobType job_type, | 161 JobType job_type, |
150 HttpNetworkSession* session, | 162 HttpNetworkSession* session, |
151 const HttpRequestInfo& request_info, | 163 const HttpRequestInfo& request_info, |
152 RequestPriority priority, | 164 RequestPriority priority, |
153 const SSLConfig& server_ssl_config, | 165 const SSLConfig& server_ssl_config, |
154 const SSLConfig& proxy_ssl_config, | 166 const SSLConfig& proxy_ssl_config, |
155 HostPortPair destination, | 167 HostPortPair destination, |
156 GURL origin_url, | 168 GURL origin_url, |
157 NetLog* net_log); | 169 NetLog* net_log); |
158 | 170 |
159 // Constructor for alternative Job. | 171 // Constructor for alternative Job. The Job is owned by |delegate|, hence |
bengr
2016/08/26 17:34:11
for -> for the
tbansal1
2016/08/26 17:44:48
Done.
| |
160 // Job is owned by |delegate|, hence |delegate| is valid for the | 172 // |delegate| is valid for the lifetime of the Job. If |alternative_service| |
161 // lifetime of the Job. | 173 // is initialized, then the Job will use the alternative service. On the |
174 // other hand, if |alternative_proxy_server| is a valid proxy server, then the | |
175 // job will use that instead of using ProxyService for proxy resolution. | |
176 // Further, if |alternative_proxy_server| is valid but bad proxy, then | |
bengr
2016/08/26 17:34:10
is -> is a
tbansal1
2016/08/26 17:44:48
Done.
| |
177 // fallback proxies are not used. It is illegal to call this with an | |
178 // initialized |alternative_service|, and a valid |alternative_proxy_server|. | |
162 Job(Delegate* delegate, | 179 Job(Delegate* delegate, |
163 JobType job_type, | 180 JobType job_type, |
164 HttpNetworkSession* session, | 181 HttpNetworkSession* session, |
165 const HttpRequestInfo& request_info, | 182 const HttpRequestInfo& request_info, |
166 RequestPriority priority, | 183 RequestPriority priority, |
167 const SSLConfig& server_ssl_config, | 184 const SSLConfig& server_ssl_config, |
168 const SSLConfig& proxy_ssl_config, | 185 const SSLConfig& proxy_ssl_config, |
169 HostPortPair destination, | 186 HostPortPair destination, |
170 GURL origin_url, | 187 GURL origin_url, |
171 AlternativeService alternative_service, | 188 AlternativeService alternative_service, |
189 const ProxyServer& alternative_proxy_server, | |
172 NetLog* net_log); | 190 NetLog* net_log); |
173 virtual ~Job(); | 191 virtual ~Job(); |
174 | 192 |
175 // Start initiates the process of creating a new HttpStream. | 193 // Start initiates the process of creating a new HttpStream. |
176 // |delegate_| will be notified upon completion. | 194 // |delegate_| will be notified upon completion. |
177 void Start(HttpStreamRequest::StreamType stream_type); | 195 void Start(HttpStreamRequest::StreamType stream_type); |
178 | 196 |
179 // Preconnect will attempt to request |num_streams| sockets from the | 197 // Preconnect will attempt to request |num_streams| sockets from the |
180 // appropriate ClientSocketPool. | 198 // appropriate ClientSocketPool. |
181 int Preconnect(int num_streams); | 199 int Preconnect(int num_streams); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 int HandleCertificateRequest(int error); | 375 int HandleCertificateRequest(int error); |
358 | 376 |
359 // Moves this stream request into SPDY mode. | 377 // Moves this stream request into SPDY mode. |
360 void SwitchToSpdyMode(); | 378 void SwitchToSpdyMode(); |
361 | 379 |
362 // Should we force QUIC for this stream request. | 380 // Should we force QUIC for this stream request. |
363 bool ShouldForceQuic() const; | 381 bool ShouldForceQuic() const; |
364 | 382 |
365 void MaybeMarkAlternativeServiceBroken(); | 383 void MaybeMarkAlternativeServiceBroken(); |
366 | 384 |
385 // May notify proxy delegate that the alternative proxy server is broken. The | |
386 // alternative proxy server is considered as broken if the alternative proxy | |
387 // server job failed, but the main job was successful. | |
388 void MaybeNotifyAlternativeProxyServerBroken() const; | |
389 | |
367 ClientSocketPoolManager::SocketGroupType GetSocketGroup() const; | 390 ClientSocketPoolManager::SocketGroupType GetSocketGroup() const; |
368 | 391 |
369 void MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 392 void MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
370 | 393 |
371 // Record histograms of latency until Connect() completes. | 394 // Record histograms of latency until Connect() completes. |
372 static void LogHttpConnectedMetrics(const ClientSocketHandle& handle); | 395 static void LogHttpConnectedMetrics(const ClientSocketHandle& handle); |
373 | 396 |
374 // Invoked by the transport socket pool after host resolution is complete | 397 // Invoked by the transport socket pool after host resolution is complete |
375 // to allow the connection to be aborted, if a matching SPDY session can | 398 // to allow the connection to be aborted, if a matching SPDY session can |
376 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a | 399 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a |
(...skipping 28 matching lines...) Expand all Loading... | |
405 | 428 |
406 // AlternativeService for this Job if this is an alternative Job. | 429 // AlternativeService for this Job if this is an alternative Job. |
407 const AlternativeService alternative_service_; | 430 const AlternativeService alternative_service_; |
408 | 431 |
409 // AlternativeService for the other Job if this is not an alternative Job. | 432 // AlternativeService for the other Job if this is not an alternative Job. |
410 AlternativeService other_job_alternative_service_; | 433 AlternativeService other_job_alternative_service_; |
411 | 434 |
412 // Unowned. |this| job is owned by |delegate_|. | 435 // Unowned. |this| job is owned by |delegate_|. |
413 Delegate* delegate_; | 436 Delegate* delegate_; |
414 | 437 |
415 JobType job_type_; | 438 // Alternative proxy server that should be used by |this| to fetch the |
439 // request. | |
440 const ProxyServer alternative_proxy_server_; | |
441 | |
442 // Alternative proxy server for the other job. | |
443 ProxyServer other_job_alternative_proxy_server_; | |
444 | |
445 const JobType job_type_; | |
416 | 446 |
417 // True if handling a HTTPS request, or using SPDY with SSL | 447 // True if handling a HTTPS request, or using SPDY with SSL |
418 bool using_ssl_; | 448 bool using_ssl_; |
419 | 449 |
420 // True if this network transaction is using SPDY instead of HTTP. | 450 // True if this network transaction is using SPDY instead of HTTP. |
421 bool using_spdy_; | 451 bool using_spdy_; |
422 | 452 |
423 // True if this network transaction is using QUIC instead of HTTP. | 453 // True if this network transaction is using QUIC instead of HTTP. |
424 bool using_quic_; | 454 bool using_quic_; |
425 QuicStreamRequest quic_request_; | 455 QuicStreamRequest quic_request_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 base::WeakPtrFactory<Job> ptr_factory_; | 502 base::WeakPtrFactory<Job> ptr_factory_; |
473 | 503 |
474 DISALLOW_COPY_AND_ASSIGN(Job); | 504 DISALLOW_COPY_AND_ASSIGN(Job); |
475 }; | 505 }; |
476 | 506 |
477 // Factory for creating Jobs. | 507 // Factory for creating Jobs. |
478 class HttpStreamFactoryImpl::JobFactory { | 508 class HttpStreamFactoryImpl::JobFactory { |
479 public: | 509 public: |
480 virtual ~JobFactory() {} | 510 virtual ~JobFactory() {} |
481 | 511 |
482 // Creates an alternative Job. | 512 // Creates an alternative service Job. |
483 virtual HttpStreamFactoryImpl::Job* CreateJob( | 513 virtual HttpStreamFactoryImpl::Job* CreateJob( |
484 HttpStreamFactoryImpl::Job::Delegate* delegate, | 514 HttpStreamFactoryImpl::Job::Delegate* delegate, |
485 HttpStreamFactoryImpl::JobType job_type, | 515 HttpStreamFactoryImpl::JobType job_type, |
486 HttpNetworkSession* session, | 516 HttpNetworkSession* session, |
487 const HttpRequestInfo& request_info, | 517 const HttpRequestInfo& request_info, |
488 RequestPriority priority, | 518 RequestPriority priority, |
489 const SSLConfig& server_ssl_config, | 519 const SSLConfig& server_ssl_config, |
490 const SSLConfig& proxy_ssl_config, | 520 const SSLConfig& proxy_ssl_config, |
491 HostPortPair destination, | 521 HostPortPair destination, |
492 GURL origin_url, | 522 GURL origin_url, |
493 AlternativeService alternative_service, | 523 AlternativeService alternative_service, |
494 NetLog* net_log) = 0; | 524 NetLog* net_log) = 0; |
495 | 525 |
526 // Creates an alternative proxy server Job. | |
527 virtual HttpStreamFactoryImpl::Job* CreateJob( | |
528 HttpStreamFactoryImpl::Job::Delegate* delegate, | |
529 HttpStreamFactoryImpl::JobType job_type, | |
530 HttpNetworkSession* session, | |
531 const HttpRequestInfo& request_info, | |
532 RequestPriority priority, | |
533 const SSLConfig& server_ssl_config, | |
534 const SSLConfig& proxy_ssl_config, | |
535 HostPortPair destination, | |
536 GURL origin_url, | |
537 const ProxyServer& alternative_proxy_server, | |
538 NetLog* net_log) = 0; | |
539 | |
496 // Creates a non-alternative Job. | 540 // Creates a non-alternative Job. |
497 virtual HttpStreamFactoryImpl::Job* CreateJob( | 541 virtual HttpStreamFactoryImpl::Job* CreateJob( |
498 HttpStreamFactoryImpl::Job::Delegate* delegate, | 542 HttpStreamFactoryImpl::Job::Delegate* delegate, |
499 HttpStreamFactoryImpl::JobType job_type, | 543 HttpStreamFactoryImpl::JobType job_type, |
500 HttpNetworkSession* session, | 544 HttpNetworkSession* session, |
501 const HttpRequestInfo& request_info, | 545 const HttpRequestInfo& request_info, |
502 RequestPriority priority, | 546 RequestPriority priority, |
503 const SSLConfig& server_ssl_config, | 547 const SSLConfig& server_ssl_config, |
504 const SSLConfig& proxy_ssl_config, | 548 const SSLConfig& proxy_ssl_config, |
505 HostPortPair destination, | 549 HostPortPair destination, |
506 GURL origin_url, | 550 GURL origin_url, |
507 NetLog* net_log) = 0; | 551 NetLog* net_log) = 0; |
508 }; | 552 }; |
509 | 553 |
510 } // namespace net | 554 } // namespace net |
511 | 555 |
512 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 556 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
OLD | NEW |