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

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

Issue 10754014: Wallpaper manager backend APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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) 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_fetcher_core.h" 5 #include "net/url_request/url_fetcher_core.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util_proxy.h" 8 #include "base/file_util_proxy.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 base::PassPlatformFile file_handle, 204 base::PassPlatformFile file_handle,
205 const FilePath& file_path) { 205 const FilePath& file_path) {
206 DidCreateFileInternal(file_path, error_code, file_handle); 206 DidCreateFileInternal(file_path, error_code, file_handle);
207 } 207 }
208 208
209 void URLFetcherCore::FileWriter::DidCreateFileInternal( 209 void URLFetcherCore::FileWriter::DidCreateFileInternal(
210 const FilePath& file_path, 210 const FilePath& file_path,
211 base::PlatformFileError error_code, 211 base::PlatformFileError error_code,
212 base::PassPlatformFile file_handle) { 212 base::PassPlatformFile file_handle) {
213 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); 213 DCHECK(core_->network_task_runner_->BelongsToCurrentThread());
214
215 if (base::PLATFORM_FILE_OK != error_code) { 214 if (base::PLATFORM_FILE_OK != error_code) {
216 error_code_ = error_code; 215 error_code_ = error_code;
217 RemoveFile(); 216 RemoveFile();
218 core_->delegate_task_runner_->PostTask( 217 core_->delegate_task_runner_->PostTask(
219 FROM_HERE, 218 FROM_HERE,
220 base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_)); 219 base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_));
221 return; 220 return;
222 } 221 }
223 222
224 file_path_ = file_path; 223 file_path_ = file_path;
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 618
620 switch (response_destination_) { 619 switch (response_destination_) {
621 case STRING: 620 case STRING:
622 StartURLRequestWhenAppropriate(); 621 StartURLRequestWhenAppropriate();
623 break; 622 break;
624 623
625 case PERMANENT_FILE: 624 case PERMANENT_FILE:
626 case TEMP_FILE: 625 case TEMP_FILE:
627 DCHECK(file_task_runner_.get()) 626 DCHECK(file_task_runner_.get())
628 << "Need to set the file task runner."; 627 << "Need to set the file task runner.";
629
630 file_writer_.reset(new FileWriter(this, file_task_runner_)); 628 file_writer_.reset(new FileWriter(this, file_task_runner_));
631 629
632 // If the file is successfully created, 630 // If the file is successfully created,
633 // URLFetcherCore::StartURLRequestWhenAppropriate() will be called. 631 // URLFetcherCore::StartURLRequestWhenAppropriate() will be called.
634 switch (response_destination_) { 632 switch (response_destination_) {
635 case PERMANENT_FILE: 633 case PERMANENT_FILE:
636 file_writer_->CreateFileAtPath(response_destination_file_path_); 634 file_writer_->CreateFileAtPath(response_destination_file_path_);
637 break; 635 break;
638 case TEMP_FILE: 636 case TEMP_FILE:
639 file_writer_->CreateTempFile(); 637 file_writer_->CreateTempFile();
640 break; 638 break;
641 default: 639 default:
642 NOTREACHED(); 640 NOTREACHED();
643 } 641 }
644 break; 642 break;
645 643
646 default: 644 default:
647 NOTREACHED(); 645 NOTREACHED();
648 } 646 }
649 } 647 }
650 648
651 void URLFetcherCore::StartURLRequest() { 649 void URLFetcherCore::StartURLRequest() {
652 DCHECK(network_task_runner_->BelongsToCurrentThread()); 650 DCHECK(network_task_runner_->BelongsToCurrentThread());
653
654 if (was_cancelled_) { 651 if (was_cancelled_) {
655 // Since StartURLRequest() is posted as a *delayed* task, it may 652 // Since StartURLRequest() is posted as a *delayed* task, it may
656 // run after the URLFetcher was already stopped. 653 // run after the URLFetcher was already stopped.
657 return; 654 return;
658 } 655 }
659 656
660 DCHECK(request_context_getter_); 657 DCHECK(request_context_getter_);
661 DCHECK(!request_.get()); 658 DCHECK(!request_.get());
662 659
663 g_registry.Get().AddURLFetcherCore(this); 660 g_registry.Get().AddURLFetcherCore(this);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 728
732 // If we are writing the response to a file, the only caller 729 // If we are writing the response to a file, the only caller
733 // of this function should have created it and not written yet. 730 // of this function should have created it and not written yet.
734 DCHECK(!file_writer_.get() || file_writer_->total_bytes_written() == 0); 731 DCHECK(!file_writer_.get() || file_writer_->total_bytes_written() == 0);
735 732
736 request_->Start(); 733 request_->Start();
737 } 734 }
738 735
739 void URLFetcherCore::StartURLRequestWhenAppropriate() { 736 void URLFetcherCore::StartURLRequestWhenAppropriate() {
740 DCHECK(network_task_runner_->BelongsToCurrentThread()); 737 DCHECK(network_task_runner_->BelongsToCurrentThread());
741
742 if (was_cancelled_) 738 if (was_cancelled_)
743 return; 739 return;
744 740
745 DCHECK(request_context_getter_); 741 DCHECK(request_context_getter_);
746 742
747 int64 delay = 0LL; 743 int64 delay = 0LL;
748 if (original_url_throttler_entry_ == NULL) { 744 if (original_url_throttler_entry_ == NULL) {
749 URLRequestThrottlerManager* manager = 745 URLRequestThrottlerManager* manager =
750 request_context_getter_->GetURLRequestContext()->throttler_manager(); 746 request_context_getter_->GetURLRequestContext()->throttler_manager();
751 if (manager) { 747 if (manager) {
(...skipping 10 matching lines...) Expand all
762 StartURLRequest(); 758 StartURLRequest();
763 } else { 759 } else {
764 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 760 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
765 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), 761 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this),
766 base::TimeDelta::FromMilliseconds(delay)); 762 base::TimeDelta::FromMilliseconds(delay));
767 } 763 }
768 } 764 }
769 765
770 void URLFetcherCore::CancelURLRequest() { 766 void URLFetcherCore::CancelURLRequest() {
771 DCHECK(network_task_runner_->BelongsToCurrentThread()); 767 DCHECK(network_task_runner_->BelongsToCurrentThread());
772
773 if (request_.get()) { 768 if (request_.get()) {
774 request_->Cancel(); 769 request_->Cancel();
775 ReleaseRequest(); 770 ReleaseRequest();
776 } 771 }
777 // Release the reference to the request context. There could be multiple 772 // Release the reference to the request context. There could be multiple
778 // references to URLFetcher::Core at this point so it may take a while to 773 // references to URLFetcher::Core at this point so it may take a while to
779 // delete the object, but we cannot delay the destruction of the request 774 // delete the object, but we cannot delay the destruction of the request
780 // context. 775 // context.
781 request_context_getter_ = NULL; 776 request_context_getter_ = NULL;
782 first_party_for_cookies_ = GURL(); 777 first_party_for_cookies_ = GURL();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } 992 }
998 993
999 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( 994 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread(
1000 scoped_ptr<std::string> download_data) { 995 scoped_ptr<std::string> download_data) {
1001 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 996 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
1002 if (delegate_) 997 if (delegate_)
1003 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); 998 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass());
1004 } 999 }
1005 1000
1006 } // namespace net 1001 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698