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 #include "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 73 |
74 private: | 74 private: |
75 URLRequestHttpJob* job_; | 75 URLRequestHttpJob* job_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 77 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
78 }; | 78 }; |
79 | 79 |
80 class URLRequestHttpJob::HttpTransactionDelegateImpl | 80 class URLRequestHttpJob::HttpTransactionDelegateImpl |
81 : public HttpTransactionDelegate { | 81 : public HttpTransactionDelegate { |
82 public: | 82 public: |
83 explicit HttpTransactionDelegateImpl(URLRequest* request) | 83 explicit HttpTransactionDelegateImpl( |
mmenke
2013/03/07 15:45:39
nit: Explicit no longer needed.
| |
84 URLRequest* request, NetworkDelegate* network_delegate) | |
84 : request_(request), | 85 : request_(request), |
85 network_delegate_(request->context()->network_delegate()), | 86 network_delegate_(network_delegate), |
86 cache_active_(false), | 87 cache_active_(false), |
87 network_active_(false) { | 88 network_active_(false) { |
88 } | 89 } |
89 virtual ~HttpTransactionDelegateImpl() { | 90 virtual ~HttpTransactionDelegateImpl() { |
90 OnDetachRequest(); | 91 OnDetachRequest(); |
91 } | 92 } |
92 void OnDetachRequest() { | 93 void OnDetachRequest() { |
93 if (request_ == NULL || network_delegate_ == NULL) | 94 if (request_ == NULL || network_delegate_ == NULL) |
94 return; | 95 return; |
95 network_delegate_->NotifyRequestWaitStateChange( | 96 network_delegate_->NotifyRequestWaitStateChange( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 bytes_observed_in_packets_(0), | 251 bytes_observed_in_packets_(0), |
251 request_time_snapshot_(), | 252 request_time_snapshot_(), |
252 final_packet_time_(), | 253 final_packet_time_(), |
253 ALLOW_THIS_IN_INITIALIZER_LIST( | 254 ALLOW_THIS_IN_INITIALIZER_LIST( |
254 filter_context_(new HttpFilterContext(this))), | 255 filter_context_(new HttpFilterContext(this))), |
255 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 256 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
256 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( | 257 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( |
257 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, | 258 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
258 base::Unretained(this)))), | 259 base::Unretained(this)))), |
259 awaiting_callback_(false), | 260 awaiting_callback_(false), |
260 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)), | 261 http_transaction_delegate_(new HttpTransactionDelegateImpl( |
262 request, network_delegate)), | |
261 http_user_agent_settings_(http_user_agent_settings) { | 263 http_user_agent_settings_(http_user_agent_settings) { |
262 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 264 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
263 if (manager) | 265 if (manager) |
264 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 266 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
265 | 267 |
266 ResetTimer(); | 268 ResetTimer(); |
267 } | 269 } |
268 | 270 |
269 void URLRequestHttpJob::NotifyHeadersComplete() { | 271 void URLRequestHttpJob::NotifyHeadersComplete() { |
270 DCHECK(!response_info_); | 272 DCHECK(!response_info_); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 | 330 |
329 void URLRequestHttpJob::DestroyTransaction() { | 331 void URLRequestHttpJob::DestroyTransaction() { |
330 DCHECK(transaction_.get()); | 332 DCHECK(transaction_.get()); |
331 | 333 |
332 DoneWithRequest(ABORTED); | 334 DoneWithRequest(ABORTED); |
333 transaction_.reset(); | 335 transaction_.reset(); |
334 response_info_ = NULL; | 336 response_info_ = NULL; |
335 } | 337 } |
336 | 338 |
337 void URLRequestHttpJob::StartTransaction() { | 339 void URLRequestHttpJob::StartTransaction() { |
338 if (request_->context()->network_delegate()) { | 340 if (network_delegate_) { |
339 int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders( | 341 int rv = network_delegate_->NotifyBeforeSendHeaders( |
340 request_, notify_before_headers_sent_callback_, | 342 request_, notify_before_headers_sent_callback_, |
341 &request_info_.extra_headers); | 343 &request_info_.extra_headers); |
342 // If an extension blocks the request, we rely on the callback to | 344 // If an extension blocks the request, we rely on the callback to |
343 // MaybeStartTransactionInternal(). | 345 // MaybeStartTransactionInternal(). |
344 if (rv == ERR_IO_PENDING) { | 346 if (rv == ERR_IO_PENDING) { |
345 SetBlockedOnDelegate(); | 347 SetBlockedOnDelegate(); |
346 return; | 348 return; |
347 } | 349 } |
348 MaybeStartTransactionInternal(rv); | 350 MaybeStartTransactionInternal(rv); |
349 return; | 351 return; |
(...skipping 23 matching lines...) Expand all Loading... | |
373 } | 375 } |
374 | 376 |
375 void URLRequestHttpJob::StartTransactionInternal() { | 377 void URLRequestHttpJob::StartTransactionInternal() { |
376 // NOTE: This method assumes that request_info_ is already setup properly. | 378 // NOTE: This method assumes that request_info_ is already setup properly. |
377 | 379 |
378 // If we already have a transaction, then we should restart the transaction | 380 // If we already have a transaction, then we should restart the transaction |
379 // with auth provided by auth_credentials_. | 381 // with auth provided by auth_credentials_. |
380 | 382 |
381 int rv; | 383 int rv; |
382 | 384 |
383 if (request_->context()->network_delegate()) { | 385 if (network_delegate_) |
384 request_->context()->network_delegate()->NotifySendHeaders( | 386 network_delegate_->NotifySendHeaders(request_, request_info_.extra_headers); |
385 request_, request_info_.extra_headers); | |
386 } | |
387 | 387 |
388 if (transaction_.get()) { | 388 if (transaction_.get()) { |
389 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); | 389 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
390 auth_credentials_ = AuthCredentials(); | 390 auth_credentials_ = AuthCredentials(); |
391 } else { | 391 } else { |
392 DCHECK(request_->context()->http_transaction_factory()); | 392 DCHECK(request_->context()->http_transaction_factory()); |
393 | 393 |
394 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 394 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
395 &transaction_, http_transaction_delegate_.get()); | 395 &transaction_, http_transaction_delegate_.get()); |
396 if (rv == OK) { | 396 if (rv == OK) { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 bool sni_available = SSLConfigService::IsSNIAvailable( | 755 bool sni_available = SSLConfigService::IsSNIAvailable( |
756 context->ssl_config_service()); | 756 context->ssl_config_service()); |
757 const std::string& host = request_->url().host(); | 757 const std::string& host = request_->url().host(); |
758 | 758 |
759 reporter->SendReport(host, ssl_info, sni_available); | 759 reporter->SendReport(host, ssl_info, sni_available); |
760 } | 760 } |
761 } | 761 } |
762 | 762 |
763 if (result == OK) { | 763 if (result == OK) { |
764 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); | 764 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
765 if (context->network_delegate()) { | 765 if (network_delegate_) { |
766 // Note that |this| may not be deleted until | 766 // Note that |this| may not be deleted until |
767 // |on_headers_received_callback_| or | 767 // |on_headers_received_callback_| or |
768 // |NetworkDelegate::URLRequestDestroyed()| has been called. | 768 // |NetworkDelegate::URLRequestDestroyed()| has been called. |
769 int error = context->network_delegate()-> | 769 int error = network_delegate_->NotifyHeadersReceived( |
770 NotifyHeadersReceived(request_, on_headers_received_callback_, | 770 request_, on_headers_received_callback_, |
771 headers, &override_response_headers_); | 771 headers, &override_response_headers_); |
772 if (error != net::OK) { | 772 if (error != net::OK) { |
773 if (error == net::ERR_IO_PENDING) { | 773 if (error == net::ERR_IO_PENDING) { |
774 awaiting_callback_ = true; | 774 awaiting_callback_ = true; |
775 SetBlockedOnDelegate(); | 775 SetBlockedOnDelegate(); |
776 } else { | 776 } else { |
777 std::string source("delegate"); | 777 std::string source("delegate"); |
778 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, | 778 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
779 NetLog::StringCallback("source", | 779 NetLog::StringCallback("source", |
780 &source)); | 780 &source)); |
781 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); | 781 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1574 | 1574 |
1575 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1575 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1576 awaiting_callback_ = false; | 1576 awaiting_callback_ = false; |
1577 } | 1577 } |
1578 | 1578 |
1579 void URLRequestHttpJob::OnDetachRequest() { | 1579 void URLRequestHttpJob::OnDetachRequest() { |
1580 http_transaction_delegate_->OnDetachRequest(); | 1580 http_transaction_delegate_->OnDetachRequest(); |
1581 } | 1581 } |
1582 | 1582 |
1583 } // namespace net | 1583 } // namespace net |
OLD | NEW |