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

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

Issue 155897: Add support to URLRequest for deferring redirects.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/process_util.h" 8 #include "base/process_util.h"
9 #include "base/singleton.h" 9 #include "base/singleton.h"
10 #include "base/stats_counters.h" 10 #include "base/stats_counters.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 DCHECK(!is_pending_); 245 DCHECK(!is_pending_);
246 DCHECK(!job_); 246 DCHECK(!job_);
247 247
248 job_ = job; 248 job_ = job;
249 job_->SetExtraRequestHeaders(extra_request_headers_); 249 job_->SetExtraRequestHeaders(extra_request_headers_);
250 250
251 if (upload_.get()) 251 if (upload_.get())
252 job_->SetUpload(upload_.get()); 252 job_->SetUpload(upload_.get());
253 253
254 is_pending_ = true; 254 is_pending_ = true;
255
255 response_info_.request_time = Time::Now(); 256 response_info_.request_time = Time::Now();
256 response_info_.was_cached = false; 257 response_info_.was_cached = false;
257 258
258 // Don't allow errors to be sent from within Start(). 259 // Don't allow errors to be sent from within Start().
259 // TODO(brettw) this may cause NotifyDone to be sent synchronously, 260 // TODO(brettw) this may cause NotifyDone to be sent synchronously,
260 // we probably don't want this: they should be sent asynchronously so 261 // we probably don't want this: they should be sent asynchronously so
261 // the caller does not get reentered. 262 // the caller does not get reentered.
262 job_->Start(); 263 job_->Start();
263 } 264 }
264 265
265 void URLRequest::Restart() { 266 void URLRequest::Restart() {
266 // Should only be called if the original job didn't make any progress. 267 // Should only be called if the original job didn't make any progress.
267 DCHECK(job_ && !job_->has_response_started()); 268 DCHECK(job_ && !job_->has_response_started());
268 RestartWithJob(GetJobManager()->CreateJob(this)); 269 RestartWithJob(GetJobManager()->CreateJob(this));
269 } 270 }
270 271
271 void URLRequest::RestartWithJob(URLRequestJob *job) { 272 void URLRequest::RestartWithJob(URLRequestJob *job) {
272 DCHECK(job->request() == this); 273 DCHECK(job->request() == this);
274 job_->Kill();
273 OrphanJob(); 275 OrphanJob();
274 status_ = URLRequestStatus(); 276 status_ = URLRequestStatus();
275 is_pending_ = false; 277 is_pending_ = false;
276 StartJob(job); 278 StartJob(job);
277 } 279 }
278 280
279 void URLRequest::Cancel() { 281 void URLRequest::Cancel() {
280 DoCancel(net::ERR_ABORTED, net::SSLInfo()); 282 DoCancel(net::ERR_ABORTED, net::SSLInfo());
281 } 283 }
282 284
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 330
329 // Once the request fails or is cancelled, read will just return 0 bytes 331 // Once the request fails or is cancelled, read will just return 0 bytes
330 // to indicate end of stream. 332 // to indicate end of stream.
331 if (!status_.is_success()) { 333 if (!status_.is_success()) {
332 return true; 334 return true;
333 } 335 }
334 336
335 return job_->Read(dest, dest_size, bytes_read); 337 return job_->Read(dest, dest_size, bytes_read);
336 } 338 }
337 339
338 void URLRequest::ReceivedRedirect(const GURL& location) { 340 void URLRequest::ReceivedRedirect(const GURL& location, bool* defer_redirect) {
339 URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location); 341 URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location);
340 if (job) { 342 if (job) {
341 RestartWithJob(job); 343 RestartWithJob(job);
342 } else if (delegate_) { 344 } else if (delegate_) {
343 delegate_->OnReceivedRedirect(this, location); 345 delegate_->OnReceivedRedirect(this, location, defer_redirect);
344 } 346 }
345 } 347 }
346 348
347 void URLRequest::ResponseStarted() { 349 void URLRequest::ResponseStarted() {
348 URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this); 350 URLRequestJob* job = GetJobManager()->MaybeInterceptResponse(this);
349 if (job) { 351 if (job) {
350 RestartWithJob(job); 352 RestartWithJob(job);
351 } else if (delegate_) { 353 } else if (delegate_) {
352 delegate_->OnResponseStarted(this); 354 delegate_->OnResponseStarted(this);
353 } 355 }
354 } 356 }
355 357
358 void URLRequest::FollowDeferredRedirect() {
359 DCHECK(job_);
360
361 job_->FollowDeferredRedirect();
362 }
363
356 void URLRequest::SetAuth(const wstring& username, const wstring& password) { 364 void URLRequest::SetAuth(const wstring& username, const wstring& password) {
357 DCHECK(job_); 365 DCHECK(job_);
358 DCHECK(job_->NeedsAuth()); 366 DCHECK(job_->NeedsAuth());
359 367
360 job_->SetAuth(username, password); 368 job_->SetAuth(username, password);
361 } 369 }
362 370
363 void URLRequest::CancelAuth() { 371 void URLRequest::CancelAuth() {
364 DCHECK(job_); 372 DCHECK(job_);
365 DCHECK(job_->NeedsAuth()); 373 DCHECK(job_->NeedsAuth());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // following a 302 redirect, normal browsers don't do that. Instead, they 424 // following a 302 redirect, normal browsers don't do that. Instead, they
417 // all convert a POST into a GET in response to a 302 and so shall we. For 425 // all convert a POST into a GET in response to a 302 and so shall we. For
418 // 307 redirects, browsers preserve the method. The RFC says to prompt the 426 // 307 redirects, browsers preserve the method. The RFC says to prompt the
419 // user to confirm the generation of a new POST request, but IE omits this 427 // user to confirm the generation of a new POST request, but IE omits this
420 // prompt and so shall we. 428 // prompt and so shall we.
421 strip_post_specific_headers = method_ == "POST"; 429 strip_post_specific_headers = method_ == "POST";
422 method_ = "GET"; 430 method_ = "GET";
423 } 431 }
424 url_ = location; 432 url_ = location;
425 upload_ = NULL; 433 upload_ = NULL;
426 status_ = URLRequestStatus();
427 --redirect_limit_; 434 --redirect_limit_;
428 435
429 if (strip_post_specific_headers) { 436 if (strip_post_specific_headers) {
430 // If being switched from POST to GET, must remove headers that were 437 // If being switched from POST to GET, must remove headers that were
431 // specific to the POST and don't have meaning in GET. For example 438 // specific to the POST and don't have meaning in GET. For example
432 // the inclusion of a multipart Content-Type header in GET can cause 439 // the inclusion of a multipart Content-Type header in GET can cause
433 // problems with some servers: 440 // problems with some servers:
434 // http://code.google.com/p/chromium/issues/detail?id=843 441 // http://code.google.com/p/chromium/issues/detail?id=843
435 // 442 //
436 // TODO(eroman): It would be better if this data was structured into 443 // TODO(eroman): It would be better if this data was structured into
437 // specific fields/flags, rather than a stew of extra headers. 444 // specific fields/flags, rather than a stew of extra headers.
438 extra_request_headers_ = StripPostSpecificHeaders(extra_request_headers_); 445 extra_request_headers_ = StripPostSpecificHeaders(extra_request_headers_);
439 } 446 }
440 447
441 if (!final_upload_progress_) { 448 if (!final_upload_progress_) {
442 final_upload_progress_ = job_->GetUploadProgress(); 449 final_upload_progress_ = job_->GetUploadProgress();
443 } 450 }
444 451
452 job_->Kill();
445 OrphanJob(); 453 OrphanJob();
446 454
455 status_ = URLRequestStatus();
447 is_pending_ = false; 456 is_pending_ = false;
448 Start(); 457 Start();
449 return net::OK; 458 return net::OK;
450 } 459 }
451 460
452 URLRequestContext* URLRequest::context() { 461 URLRequestContext* URLRequest::context() {
453 return context_.get(); 462 return context_.get();
454 } 463 }
455 464
456 void URLRequest::set_context(URLRequestContext* context) { 465 void URLRequest::set_context(URLRequestContext* context) {
(...skipping 20 matching lines...) Expand all
477 } 486 }
478 487
479 #ifndef NDEBUG 488 #ifndef NDEBUG
480 489
481 URLRequestMetrics::~URLRequestMetrics() { 490 URLRequestMetrics::~URLRequestMetrics() {
482 DLOG_IF(WARNING, object_count != 0) << 491 DLOG_IF(WARNING, object_count != 0) <<
483 "Leaking " << object_count << " URLRequest object(s)"; 492 "Leaking " << object_count << " URLRequest object(s)";
484 } 493 }
485 494
486 #endif 495 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698