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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 122453002: Allows deferral of a URLRequest just before talking to the network, at (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting nits Created 6 years, 11 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 #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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 done_(false), 183 done_(false),
184 bytes_observed_in_packets_(0), 184 bytes_observed_in_packets_(0),
185 request_time_snapshot_(), 185 request_time_snapshot_(),
186 final_packet_time_(), 186 final_packet_time_(),
187 filter_context_(new HttpFilterContext(this)), 187 filter_context_(new HttpFilterContext(this)),
188 weak_factory_(this), 188 weak_factory_(this),
189 on_headers_received_callback_( 189 on_headers_received_callback_(
190 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, 190 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback,
191 base::Unretained(this))), 191 base::Unretained(this))),
192 awaiting_callback_(false), 192 awaiting_callback_(false),
193 http_user_agent_settings_(http_user_agent_settings) { 193 http_user_agent_settings_(http_user_agent_settings),
194 request_(request) {
194 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); 195 URLRequestThrottlerManager* manager = request->context()->throttler_manager();
195 if (manager) 196 if (manager)
196 throttling_entry_ = manager->RegisterRequestUrl(request->url()); 197 throttling_entry_ = manager->RegisterRequestUrl(request->url());
197 198
198 ResetTimer(); 199 ResetTimer();
199 } 200 }
200 201
201 URLRequestHttpJob::~URLRequestHttpJob() { 202 URLRequestHttpJob::~URLRequestHttpJob() {
202 CHECK(!awaiting_callback_); 203 CHECK(!awaiting_callback_);
203 204
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 408
408 if (transaction_.get()) { 409 if (transaction_.get()) {
409 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); 410 rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_);
410 auth_credentials_ = AuthCredentials(); 411 auth_credentials_ = AuthCredentials();
411 } else { 412 } else {
412 DCHECK(request_->context()->http_transaction_factory()); 413 DCHECK(request_->context()->http_transaction_factory());
413 414
414 rv = request_->context()->http_transaction_factory()->CreateTransaction( 415 rv = request_->context()->http_transaction_factory()->CreateTransaction(
415 priority_, &transaction_); 416 priority_, &transaction_);
416 417
418 transaction_->SetBeforeNetworkStartCallback(
419 base::Bind(&URLRequestHttpJob::NotifyBeforeNetworkStart, this));
420
417 if (rv == OK && request_info_.url.SchemeIsWSOrWSS()) { 421 if (rv == OK && request_info_.url.SchemeIsWSOrWSS()) {
418 // TODO(ricea): Implement WebSocket throttling semantics as defined in 422 // TODO(ricea): Implement WebSocket throttling semantics as defined in
419 // RFC6455 Section 4.1. 423 // RFC6455 Section 4.1.
420 base::SupportsUserData::Data* data = request_->GetUserData( 424 base::SupportsUserData::Data* data = request_->GetUserData(
421 WebSocketHandshakeStreamBase::CreateHelper::DataKey()); 425 WebSocketHandshakeStreamBase::CreateHelper::DataKey());
422 if (data) { 426 if (data) {
423 transaction_->SetWebSocketHandshakeStreamCreateHelper( 427 transaction_->SetWebSocketHandshakeStreamCreateHelper(
424 static_cast<WebSocketHandshakeStreamBase::CreateHelper*>(data)); 428 static_cast<WebSocketHandshakeStreamBase::CreateHelper*>(data));
425 } else { 429 } else {
426 rv = ERR_DISALLOWED_URL_SCHEME; 430 rv = ERR_DISALLOWED_URL_SCHEME;
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 return; 1164 return;
1161 1165
1162 // The transaction started synchronously, but we need to notify the 1166 // The transaction started synchronously, but we need to notify the
1163 // URLRequest delegate via the message loop. 1167 // URLRequest delegate via the message loop.
1164 base::MessageLoop::current()->PostTask( 1168 base::MessageLoop::current()->PostTask(
1165 FROM_HERE, 1169 FROM_HERE,
1166 base::Bind(&URLRequestHttpJob::OnStartCompleted, 1170 base::Bind(&URLRequestHttpJob::OnStartCompleted,
1167 weak_factory_.GetWeakPtr(), rv)); 1171 weak_factory_.GetWeakPtr(), rv));
1168 } 1172 }
1169 1173
1174 void URLRequestHttpJob::ResumeNetworkStart() {
1175 DCHECK(transaction_.get());
1176 transaction_->ResumeNetworkStart();
1177 }
1178
1170 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { 1179 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const {
1171 // Some servers send the body compressed, but specify the content length as 1180 // Some servers send the body compressed, but specify the content length as
1172 // the uncompressed size. Although this violates the HTTP spec we want to 1181 // the uncompressed size. Although this violates the HTTP spec we want to
1173 // support it (as IE and FireFox do), but *only* for an exact match. 1182 // support it (as IE and FireFox do), but *only* for an exact match.
1174 // See http://crbug.com/79694. 1183 // See http://crbug.com/79694.
1175 if (rv == net::ERR_CONTENT_LENGTH_MISMATCH || 1184 if (rv == net::ERR_CONTENT_LENGTH_MISMATCH ||
1176 rv == net::ERR_INCOMPLETE_CHUNKED_ENCODING) { 1185 rv == net::ERR_INCOMPLETE_CHUNKED_ENCODING) {
1177 if (request_ && request_->response_headers()) { 1186 if (request_ && request_->response_headers()) {
1178 int64 expected_length = request_->response_headers()->GetContentLength(); 1187 int64 expected_length = request_->response_headers()->GetContentLength();
1179 VLOG(1) << __FUNCTION__ << "() " 1188 VLOG(1) << __FUNCTION__ << "() "
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 return override_response_headers_.get() ? 1455 return override_response_headers_.get() ?
1447 override_response_headers_.get() : 1456 override_response_headers_.get() :
1448 transaction_->GetResponseInfo()->headers.get(); 1457 transaction_->GetResponseInfo()->headers.get();
1449 } 1458 }
1450 1459
1451 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1460 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1452 awaiting_callback_ = false; 1461 awaiting_callback_ = false;
1453 } 1462 }
1454 1463
1455 } // namespace net 1464 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698