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

Side by Side Diff: content/browser/loader/resource_loader.cc

Issue 14335017: content: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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) 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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "content/browser/child_process_security_policy_impl.h" 10 #include "content/browser/child_process_security_policy_impl.h"
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 case DEFERRED_NONE: 430 case DEFERRED_NONE:
431 NOTREACHED(); 431 NOTREACHED();
432 break; 432 break;
433 case DEFERRED_START: 433 case DEFERRED_START:
434 StartRequestInternal(); 434 StartRequestInternal();
435 break; 435 break;
436 case DEFERRED_REDIRECT: 436 case DEFERRED_REDIRECT:
437 request_->FollowDeferredRedirect(); 437 request_->FollowDeferredRedirect();
438 break; 438 break;
439 case DEFERRED_READ: 439 case DEFERRED_READ:
440 MessageLoop::current()->PostTask( 440 base::MessageLoop::current()->PostTask(
441 FROM_HERE, 441 FROM_HERE,
442 base::Bind(&ResourceLoader::ResumeReading, 442 base::Bind(&ResourceLoader::ResumeReading,
443 weak_ptr_factory_.GetWeakPtr())); 443 weak_ptr_factory_.GetWeakPtr()));
444 break; 444 break;
445 case DEFERRED_FINISH: 445 case DEFERRED_FINISH:
446 // Delay self-destruction since we don't know how we were reached. 446 // Delay self-destruction since we don't know how we were reached.
447 MessageLoop::current()->PostTask( 447 base::MessageLoop::current()->PostTask(
448 FROM_HERE, 448 FROM_HERE,
449 base::Bind(&ResourceLoader::CallDidFinishLoading, 449 base::Bind(&ResourceLoader::CallDidFinishLoading,
450 weak_ptr_factory_.GetWeakPtr())); 450 weak_ptr_factory_.GetWeakPtr()));
451 break; 451 break;
452 } 452 }
453 } 453 }
454 454
455 void ResourceLoader::Cancel() { 455 void ResourceLoader::Cancel() {
456 CancelRequest(false); 456 CancelRequest(false);
457 } 457 }
(...skipping 28 matching lines...) Expand all
486 ssl_client_auth_handler_->OnRequestCancelled(); 486 ssl_client_auth_handler_->OnRequestCancelled();
487 ssl_client_auth_handler_ = NULL; 487 ssl_client_auth_handler_ = NULL;
488 } 488 }
489 489
490 request_->CancelWithError(error); 490 request_->CancelWithError(error);
491 491
492 if (!was_pending) { 492 if (!was_pending) {
493 // If the request isn't in flight, then we won't get an asynchronous 493 // If the request isn't in flight, then we won't get an asynchronous
494 // notification from the request, so we have to signal ourselves to finish 494 // notification from the request, so we have to signal ourselves to finish
495 // this request. 495 // this request.
496 MessageLoop::current()->PostTask( 496 base::MessageLoop::current()->PostTask(
497 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 497 FROM_HERE,
498 weak_ptr_factory_.GetWeakPtr())); 498 base::Bind(&ResourceLoader::ResponseCompleted,
499 weak_ptr_factory_.GetWeakPtr()));
499 } 500 }
500 } 501 }
501 502
502 void ResourceLoader::CompleteResponseStarted() { 503 void ResourceLoader::CompleteResponseStarted() {
503 ResourceRequestInfoImpl* info = GetRequestInfo(); 504 ResourceRequestInfoImpl* info = GetRequestInfo();
504 505
505 scoped_refptr<ResourceResponse> response(new ResourceResponse()); 506 scoped_refptr<ResourceResponse> response(new ResourceResponse());
506 PopulateResourceResponse(request_.get(), response); 507 PopulateResourceResponse(request_.get(), response);
507 508
508 // The --site-per-process flag enables an out-of-process iframes 509 // The --site-per-process flag enables an out-of-process iframes
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 566
566 // If IO is pending, wait for the URLRequest to call OnReadCompleted. 567 // If IO is pending, wait for the URLRequest to call OnReadCompleted.
567 if (request_->status().is_io_pending()) 568 if (request_->status().is_io_pending())
568 return; 569 return;
569 570
570 if (!is_continuation || bytes_read <= 0) { 571 if (!is_continuation || bytes_read <= 0) {
571 OnReadCompleted(request_.get(), bytes_read); 572 OnReadCompleted(request_.get(), bytes_read);
572 } else { 573 } else {
573 // Else, trigger OnReadCompleted asynchronously to avoid starving the IO 574 // Else, trigger OnReadCompleted asynchronously to avoid starving the IO
574 // thread in case the URLRequest can provide data synchronously. 575 // thread in case the URLRequest can provide data synchronously.
575 MessageLoop::current()->PostTask( 576 base::MessageLoop::current()->PostTask(
576 FROM_HERE, 577 FROM_HERE,
577 base::Bind(&ResourceLoader::OnReadCompleted, 578 base::Bind(&ResourceLoader::OnReadCompleted,
578 weak_ptr_factory_.GetWeakPtr(), 579 weak_ptr_factory_.GetWeakPtr(),
579 request_.get(), bytes_read)); 580 request_.get(),
581 bytes_read));
580 } 582 }
581 } 583 }
582 584
583 void ResourceLoader::ResumeReading() { 585 void ResourceLoader::ResumeReading() {
584 DCHECK(!is_deferred()); 586 DCHECK(!is_deferred());
585 587
586 if (request_->status().is_success()) { 588 if (request_->status().is_success()) {
587 StartReading(false); // Read the next chunk (OK to complete synchronously). 589 StartReading(false); // Read the next chunk (OK to complete synchronously).
588 } else { 590 } else {
589 ResponseCompleted(); 591 ResponseCompleted();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // we resume. 649 // we resume.
648 deferred_stage_ = DEFERRED_FINISH; 650 deferred_stage_ = DEFERRED_FINISH;
649 } 651 }
650 } 652 }
651 653
652 void ResourceLoader::CallDidFinishLoading() { 654 void ResourceLoader::CallDidFinishLoading() {
653 delegate_->DidFinishLoading(this); 655 delegate_->DidFinishLoading(this);
654 } 656 }
655 657
656 } // namespace content 658 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_unittest.cc ('k') | content/browser/loader/resource_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698