| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 virtual void OnNeedsProxyAuth(Job* job, | 95 virtual void OnNeedsProxyAuth(Job* job, |
| 96 const HttpResponseInfo& proxy_response, | 96 const HttpResponseInfo& proxy_response, |
| 97 const SSLConfig& used_ssl_config, | 97 const SSLConfig& used_ssl_config, |
| 98 const ProxyInfo& used_proxy_info, | 98 const ProxyInfo& used_proxy_info, |
| 99 HttpAuthController* auth_controller) = 0; | 99 HttpAuthController* auth_controller) = 0; |
| 100 | 100 |
| 101 // Returns true if the connection initialization to the proxy server | 101 // Returns true if the connection initialization to the proxy server |
| 102 // contained in |proxy_info| can be skipped. | 102 // contained in |proxy_info| can be skipped. |
| 103 virtual bool OnInitConnection(const ProxyInfo& proxy_info) = 0; | 103 virtual bool OnInitConnection(const ProxyInfo& proxy_info) = 0; |
| 104 | 104 |
| 105 // Invoked when |job| has completed proxy resolution. The delegate may | |
| 106 // create an alternative proxy server job to fetch the request. | |
| 107 virtual void OnResolveProxyComplete( | |
| 108 Job* job, | |
| 109 const HttpRequestInfo& request_info, | |
| 110 RequestPriority priority, | |
| 111 const SSLConfig& server_ssl_config, | |
| 112 const SSLConfig& proxy_ssl_config, | |
| 113 HttpStreamRequest::StreamType stream_type) = 0; | |
| 114 | |
| 115 // Invoked to notify the Request and Factory of the readiness of new | 105 // Invoked to notify the Request and Factory of the readiness of new |
| 116 // SPDY session. | 106 // SPDY session. |
| 117 virtual void OnNewSpdySessionReady( | 107 virtual void OnNewSpdySessionReady( |
| 118 Job* job, | 108 Job* job, |
| 119 const base::WeakPtr<SpdySession>& spdy_session, | 109 const base::WeakPtr<SpdySession>& spdy_session, |
| 120 bool direct) = 0; | 110 bool direct) = 0; |
| 121 | 111 |
| 122 // Invoked when the |job| finishes pre-connecting sockets. | 112 // Invoked when the |job| finishes pre-connecting sockets. |
| 123 virtual void OnPreconnectsComplete(Job* job) = 0; | 113 virtual void OnPreconnectsComplete(Job* job) = 0; |
| 124 | 114 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 }; | 146 }; |
| 157 | 147 |
| 158 // Constructor for non-alternative Job. | 148 // Constructor for non-alternative Job. |
| 159 // Job is owned by |delegate|, hence |delegate| is valid for the | 149 // Job is owned by |delegate|, hence |delegate| is valid for the |
| 160 // lifetime of the Job. | 150 // lifetime of the Job. |
| 161 Job(Delegate* delegate, | 151 Job(Delegate* delegate, |
| 162 JobType job_type, | 152 JobType job_type, |
| 163 HttpNetworkSession* session, | 153 HttpNetworkSession* session, |
| 164 const HttpRequestInfo& request_info, | 154 const HttpRequestInfo& request_info, |
| 165 RequestPriority priority, | 155 RequestPriority priority, |
| 156 const ProxyInfo& proxy_info, |
| 166 const SSLConfig& server_ssl_config, | 157 const SSLConfig& server_ssl_config, |
| 167 const SSLConfig& proxy_ssl_config, | 158 const SSLConfig& proxy_ssl_config, |
| 168 HostPortPair destination, | 159 HostPortPair destination, |
| 169 GURL origin_url, | 160 GURL origin_url, |
| 170 bool enable_ip_based_pooling, | 161 bool enable_ip_based_pooling, |
| 171 NetLog* net_log); | 162 NetLog* net_log); |
| 172 | 163 |
| 173 // Constructor for the alternative Job. The Job is owned by |delegate|, hence | 164 // Constructor for the alternative Job. The Job is owned by |delegate|, hence |
| 174 // |delegate| is valid for the lifetime of the Job. If |alternative_service| | 165 // |delegate| is valid for the lifetime of the Job. If |alternative_service| |
| 175 // is initialized, then the Job will use the alternative service. On the | 166 // is initialized, then the Job will use the alternative service. On the |
| 176 // other hand, if |alternative_proxy_server| is a valid proxy server, then the | 167 // other hand, if |alternative_proxy_server| is a valid proxy server, then the |
| 177 // job will use that instead of using ProxyService for proxy resolution. | 168 // job will use that instead of using ProxyService for proxy resolution. |
| 178 // Further, if |alternative_proxy_server| is a valid but bad proxy, then | 169 // Further, if |alternative_proxy_server| is a valid but bad proxy, then |
| 179 // fallback proxies are not used. It is illegal to call this with an | 170 // fallback proxies are not used. It is illegal to call this with an |
| 180 // initialized |alternative_service|, and a valid |alternative_proxy_server|. | 171 // initialized |alternative_service|, and a valid |alternative_proxy_server|. |
| 181 Job(Delegate* delegate, | 172 Job(Delegate* delegate, |
| 182 JobType job_type, | 173 JobType job_type, |
| 183 HttpNetworkSession* session, | 174 HttpNetworkSession* session, |
| 184 const HttpRequestInfo& request_info, | 175 const HttpRequestInfo& request_info, |
| 185 RequestPriority priority, | 176 RequestPriority priority, |
| 177 const ProxyInfo& proxy_info, |
| 186 const SSLConfig& server_ssl_config, | 178 const SSLConfig& server_ssl_config, |
| 187 const SSLConfig& proxy_ssl_config, | 179 const SSLConfig& proxy_ssl_config, |
| 188 HostPortPair destination, | 180 HostPortPair destination, |
| 189 GURL origin_url, | 181 GURL origin_url, |
| 190 AlternativeService alternative_service, | 182 AlternativeService alternative_service, |
| 191 const ProxyServer& alternative_proxy_server, | 183 const ProxyServer& alternative_proxy_server, |
| 192 bool enable_ip_based_pooling, | 184 bool enable_ip_based_pooling, |
| 193 NetLog* net_log); | 185 NetLog* net_log); |
| 194 virtual ~Job(); | 186 virtual ~Job(); |
| 195 | 187 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 236 } |
| 245 | 237 |
| 246 const ProxyServer alternative_proxy_server() const { | 238 const ProxyServer alternative_proxy_server() const { |
| 247 return alternative_proxy_server_; | 239 return alternative_proxy_server_; |
| 248 } | 240 } |
| 249 | 241 |
| 250 bool using_existing_quic_session() const { | 242 bool using_existing_quic_session() const { |
| 251 return using_existing_quic_session_; | 243 return using_existing_quic_session_; |
| 252 } | 244 } |
| 253 | 245 |
| 246 bool should_reconsider_proxy() const { return should_reconsider_proxy_; } |
| 247 |
| 254 // TODO(xunjieli): Added to investigate crbug.com/711721. Remove when no | 248 // TODO(xunjieli): Added to investigate crbug.com/711721. Remove when no |
| 255 // longer needed. | 249 // longer needed. |
| 256 void LogHistograms() const; | 250 void LogHistograms() const; |
| 257 | 251 |
| 258 private: | 252 private: |
| 259 friend class HttpStreamFactoryImplJobPeer; | 253 friend class HttpStreamFactoryImplJobPeer; |
| 260 | 254 |
| 261 enum State { | 255 enum State { |
| 262 STATE_START, | 256 STATE_START, |
| 263 STATE_RESOLVE_PROXY, | |
| 264 STATE_RESOLVE_PROXY_COMPLETE, | |
| 265 | |
| 266 // The main and alternative jobs are started in parallel. The main job | 257 // The main and alternative jobs are started in parallel. The main job |
| 267 // waits after it finishes proxy resolution. The alternative job never | 258 // can wait if it's paused. The alternative job never waits. |
| 268 // waits. | |
| 269 // | 259 // |
| 270 // An HTTP/2 alternative job notifies the JobController in DoInitConnection | 260 // An HTTP/2 alternative job notifies the JobController in DoInitConnection |
| 271 // unless it can pool to an existing SpdySession. JobController, in turn, | 261 // unless it can pool to an existing SpdySession. JobController, in turn, |
| 272 // resumes the main job. | 262 // resumes the main job. |
| 273 // | 263 // |
| 274 // A QUIC alternative job notifies the JobController in DoInitConnection | 264 // A QUIC alternative job notifies the JobController in DoInitConnection |
| 275 // regardless of whether it pools to an existing QUIC session, but the main | 265 // regardless of whether it pools to an existing QUIC session, but the main |
| 276 // job is only resumed after some delay. | 266 // job is only resumed after some delay. |
| 277 // | 267 // |
| 278 // If the main job is resumed, then it races the alternative job. | 268 // If the main job is resumed, then it races the alternative job. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void RunLoop(int result); | 304 void RunLoop(int result); |
| 315 int DoLoop(int result); | 305 int DoLoop(int result); |
| 316 int StartInternal(); | 306 int StartInternal(); |
| 317 int DoInitConnectionImpl(); | 307 int DoInitConnectionImpl(); |
| 318 | 308 |
| 319 // Each of these methods corresponds to a State value. Those with an input | 309 // Each of these methods corresponds to a State value. Those with an input |
| 320 // argument receive the result from the previous state. If a method returns | 310 // argument receive the result from the previous state. If a method returns |
| 321 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the | 311 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the |
| 322 // next state method as the result arg. | 312 // next state method as the result arg. |
| 323 int DoStart(); | 313 int DoStart(); |
| 324 int DoResolveProxy(); | |
| 325 int DoResolveProxyComplete(int result); | |
| 326 int DoWait(); | 314 int DoWait(); |
| 327 int DoWaitComplete(int result); | 315 int DoWaitComplete(int result); |
| 328 int DoInitConnection(); | 316 int DoInitConnection(); |
| 329 int DoInitConnectionComplete(int result); | 317 int DoInitConnectionComplete(int result); |
| 330 int DoWaitingUserAction(int result); | 318 int DoWaitingUserAction(int result); |
| 331 int DoCreateStream(); | 319 int DoCreateStream(); |
| 332 int DoCreateStreamComplete(int result); | 320 int DoCreateStreamComplete(int result); |
| 333 int DoRestartTunnelAuth(); | 321 int DoRestartTunnelAuth(); |
| 334 int DoRestartTunnelAuthComplete(int result); | 322 int DoRestartTunnelAuthComplete(int result); |
| 335 | 323 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // session is found, and OK otherwise. | 386 // session is found, and OK otherwise. |
| 399 static int OnHostResolution(SpdySessionPool* spdy_session_pool, | 387 static int OnHostResolution(SpdySessionPool* spdy_session_pool, |
| 400 const SpdySessionKey& spdy_session_key, | 388 const SpdySessionKey& spdy_session_key, |
| 401 const GURL& origin_url, | 389 const GURL& origin_url, |
| 402 bool enable_ip_based_pooling, | 390 bool enable_ip_based_pooling, |
| 403 const AddressList& addresses, | 391 const AddressList& addresses, |
| 404 const NetLogWithSource& net_log); | 392 const NetLogWithSource& net_log); |
| 405 | 393 |
| 406 const HttpRequestInfo request_info_; | 394 const HttpRequestInfo request_info_; |
| 407 RequestPriority priority_; | 395 RequestPriority priority_; |
| 408 ProxyInfo proxy_info_; | 396 const ProxyInfo proxy_info_; |
| 409 SSLConfig server_ssl_config_; | 397 SSLConfig server_ssl_config_; |
| 410 SSLConfig proxy_ssl_config_; | 398 SSLConfig proxy_ssl_config_; |
| 411 const NetLogWithSource net_log_; | 399 const NetLogWithSource net_log_; |
| 412 | 400 |
| 413 CompletionCallback io_callback_; | 401 CompletionCallback io_callback_; |
| 414 std::unique_ptr<ClientSocketHandle> connection_; | 402 std::unique_ptr<ClientSocketHandle> connection_; |
| 415 HttpNetworkSession* const session_; | 403 HttpNetworkSession* const session_; |
| 416 | 404 |
| 417 // |state_| is only used for LogHistograms(). | 405 // |state_| is only used for LogHistograms(). |
| 418 State state_; | 406 State state_; |
| 419 | 407 |
| 420 State next_state_; | 408 State next_state_; |
| 421 ProxyService::PacRequest* pac_request_; | |
| 422 SSLInfo ssl_info_; | 409 SSLInfo ssl_info_; |
| 423 | 410 |
| 424 // The server we are trying to reach, could be that of the origin or of the | 411 // The server we are trying to reach, could be that of the origin or of the |
| 425 // alternative service (after applying host mapping rules). | 412 // alternative service (after applying host mapping rules). |
| 426 const HostPortPair destination_; | 413 const HostPortPair destination_; |
| 427 | 414 |
| 428 // The origin url we're trying to reach. This url may be different from the | 415 // The origin url we're trying to reach. This url may be different from the |
| 429 // original request when host mapping rules are set-up. | 416 // original request when host mapping rules are set-up. |
| 430 const GURL origin_url_; | 417 const GURL origin_url_; |
| 431 | 418 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 446 const JobType job_type_; | 433 const JobType job_type_; |
| 447 | 434 |
| 448 // True if handling a HTTPS request. | 435 // True if handling a HTTPS request. |
| 449 const bool using_ssl_; | 436 const bool using_ssl_; |
| 450 | 437 |
| 451 // True if this network transaction is using SPDY instead of HTTP. | 438 // True if this network transaction is using SPDY instead of HTTP. |
| 452 bool using_spdy_; | 439 bool using_spdy_; |
| 453 | 440 |
| 454 // True if this network transaction is using QUIC instead of HTTP. | 441 // True if this network transaction is using QUIC instead of HTTP. |
| 455 bool using_quic_; | 442 bool using_quic_; |
| 443 |
| 444 // True if this job might succeed with a different proxy config. |
| 445 bool should_reconsider_proxy_; |
| 446 |
| 456 QuicStreamRequest quic_request_; | 447 QuicStreamRequest quic_request_; |
| 457 | 448 |
| 458 // True if this job used an existing QUIC session. | 449 // True if this job used an existing QUIC session. |
| 459 bool using_existing_quic_session_; | 450 bool using_existing_quic_session_; |
| 460 | 451 |
| 461 // True when the tunnel is in the process of being established - we can't | 452 // True when the tunnel is in the process of being established - we can't |
| 462 // read from the socket until the tunnel is done. | 453 // read from the socket until the tunnel is done. |
| 463 bool establishing_tunnel_; | 454 bool establishing_tunnel_; |
| 464 | 455 |
| 465 std::unique_ptr<HttpStream> stream_; | 456 std::unique_ptr<HttpStream> stream_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 491 HttpStreamRequest::StreamType stream_type_; | 482 HttpStreamRequest::StreamType stream_type_; |
| 492 | 483 |
| 493 base::WeakPtrFactory<Job> ptr_factory_; | 484 base::WeakPtrFactory<Job> ptr_factory_; |
| 494 | 485 |
| 495 DISALLOW_COPY_AND_ASSIGN(Job); | 486 DISALLOW_COPY_AND_ASSIGN(Job); |
| 496 }; | 487 }; |
| 497 | 488 |
| 498 // Factory for creating Jobs. | 489 // Factory for creating Jobs. |
| 499 class HttpStreamFactoryImpl::JobFactory { | 490 class HttpStreamFactoryImpl::JobFactory { |
| 500 public: | 491 public: |
| 501 virtual ~JobFactory() {} | 492 JobFactory(); |
| 502 | 493 |
| 503 // Creates an alternative service Job. | 494 virtual ~JobFactory(); |
| 504 virtual HttpStreamFactoryImpl::Job* CreateJob( | 495 |
| 496 virtual std::unique_ptr<HttpStreamFactoryImpl::Job> CreateMainJob( |
| 505 HttpStreamFactoryImpl::Job::Delegate* delegate, | 497 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 506 HttpStreamFactoryImpl::JobType job_type, | 498 HttpStreamFactoryImpl::JobType job_type, |
| 507 HttpNetworkSession* session, | 499 HttpNetworkSession* session, |
| 508 const HttpRequestInfo& request_info, | 500 const HttpRequestInfo& request_info, |
| 509 RequestPriority priority, | 501 RequestPriority priority, |
| 502 const ProxyInfo& proxy_info, |
| 503 const SSLConfig& server_ssl_config, |
| 504 const SSLConfig& proxy_ssl_config, |
| 505 HostPortPair destination, |
| 506 GURL origin_url, |
| 507 bool enable_ip_based_pooling, |
| 508 NetLog* net_log); |
| 509 |
| 510 virtual std::unique_ptr<HttpStreamFactoryImpl::Job> CreateAltSvcJob( |
| 511 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 512 HttpStreamFactoryImpl::JobType job_type, |
| 513 HttpNetworkSession* session, |
| 514 const HttpRequestInfo& request_info, |
| 515 RequestPriority priority, |
| 516 const ProxyInfo& proxy_info, |
| 510 const SSLConfig& server_ssl_config, | 517 const SSLConfig& server_ssl_config, |
| 511 const SSLConfig& proxy_ssl_config, | 518 const SSLConfig& proxy_ssl_config, |
| 512 HostPortPair destination, | 519 HostPortPair destination, |
| 513 GURL origin_url, | 520 GURL origin_url, |
| 514 AlternativeService alternative_service, | 521 AlternativeService alternative_service, |
| 515 bool enable_ip_based_pooling, | 522 bool enable_ip_based_pooling, |
| 516 NetLog* net_log) = 0; | 523 NetLog* net_log); |
| 517 | 524 |
| 518 // Creates an alternative proxy server Job. | 525 virtual std::unique_ptr<HttpStreamFactoryImpl::Job> CreateAltProxyJob( |
| 519 virtual HttpStreamFactoryImpl::Job* CreateJob( | |
| 520 HttpStreamFactoryImpl::Job::Delegate* delegate, | 526 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 521 HttpStreamFactoryImpl::JobType job_type, | 527 HttpStreamFactoryImpl::JobType job_type, |
| 522 HttpNetworkSession* session, | 528 HttpNetworkSession* session, |
| 523 const HttpRequestInfo& request_info, | 529 const HttpRequestInfo& request_info, |
| 524 RequestPriority priority, | 530 RequestPriority priority, |
| 531 const ProxyInfo& proxy_info, |
| 525 const SSLConfig& server_ssl_config, | 532 const SSLConfig& server_ssl_config, |
| 526 const SSLConfig& proxy_ssl_config, | 533 const SSLConfig& proxy_ssl_config, |
| 527 HostPortPair destination, | 534 HostPortPair destination, |
| 528 GURL origin_url, | 535 GURL origin_url, |
| 529 const ProxyServer& alternative_proxy_server, | 536 const ProxyServer& alternative_proxy_server, |
| 530 bool enable_ip_based_pooling, | 537 bool enable_ip_based_pooling, |
| 531 NetLog* net_log) = 0; | 538 NetLog* net_log); |
| 532 | |
| 533 // Creates a non-alternative Job. | |
| 534 virtual HttpStreamFactoryImpl::Job* CreateJob( | |
| 535 HttpStreamFactoryImpl::Job::Delegate* delegate, | |
| 536 HttpStreamFactoryImpl::JobType job_type, | |
| 537 HttpNetworkSession* session, | |
| 538 const HttpRequestInfo& request_info, | |
| 539 RequestPriority priority, | |
| 540 const SSLConfig& server_ssl_config, | |
| 541 const SSLConfig& proxy_ssl_config, | |
| 542 HostPortPair destination, | |
| 543 GURL origin_url, | |
| 544 bool enable_ip_based_pooling, | |
| 545 NetLog* net_log) = 0; | |
| 546 }; | 539 }; |
| 547 | 540 |
| 548 } // namespace net | 541 } // namespace net |
| 549 | 542 |
| 550 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 543 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |