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

Side by Side Diff: content/common/net/url_fetcher.cc

Issue 8370022: Convert the non-debug logging in chrome/common to debug logging. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 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
Property Changes:
Deleted: svn:mergeinfo
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/net/url_fetcher.h" 5 #include "content/common/net/url_fetcher.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 file_message_loop_proxy_(file_message_loop_proxy), 325 file_message_loop_proxy_(file_message_loop_proxy),
326 temp_file_handle_(base::kInvalidPlatformFileValue) { 326 temp_file_handle_(base::kInvalidPlatformFileValue) {
327 } 327 }
328 328
329 URLFetcher::Core::TempFileWriter::~TempFileWriter() { 329 URLFetcher::Core::TempFileWriter::~TempFileWriter() {
330 RemoveTempFile(); 330 RemoveTempFile();
331 } 331 }
332 332
333 void URLFetcher::Core::TempFileWriter::CreateTempFile() { 333 void URLFetcher::Core::TempFileWriter::CreateTempFile() {
334 DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread()); 334 DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread());
335 CHECK(file_message_loop_proxy_.get()); 335 DCHECK(file_message_loop_proxy_.get());
336 base::FileUtilProxy::CreateTemporary( 336 base::FileUtilProxy::CreateTemporary(
337 file_message_loop_proxy_, 337 file_message_loop_proxy_,
338 0, // No additional file flags. 338 0, // No additional file flags.
339 base::Bind(&URLFetcher::Core::TempFileWriter::DidCreateTempFile, 339 base::Bind(&URLFetcher::Core::TempFileWriter::DidCreateTempFile,
340 weak_factory_.GetWeakPtr())); 340 weak_factory_.GetWeakPtr()));
341 } 341 }
342 342
343 void URLFetcher::Core::TempFileWriter::DidCreateTempFile( 343 void URLFetcher::Core::TempFileWriter::DidCreateTempFile(
344 base::PlatformFileError error_code, 344 base::PlatformFileError error_code,
345 base::PassPlatformFile file_handle, 345 base::PassPlatformFile file_handle,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 541 }
542 542
543 URLFetcher::Core::~Core() { 543 URLFetcher::Core::~Core() {
544 // |request_| should be NULL. If not, it's unsafe to delete it here since we 544 // |request_| should be NULL. If not, it's unsafe to delete it here since we
545 // may not be on the IO thread. 545 // may not be on the IO thread.
546 DCHECK(!request_.get()); 546 DCHECK(!request_.get());
547 } 547 }
548 548
549 void URLFetcher::Core::Start() { 549 void URLFetcher::Core::Start() {
550 DCHECK(delegate_loop_proxy_); 550 DCHECK(delegate_loop_proxy_);
551 CHECK(request_context_getter_) << "We need an URLRequestContext!"; 551 DCHECK(request_context_getter_) << "We need an URLRequestContext!";
552 if (io_message_loop_proxy_) { 552 if (io_message_loop_proxy_) {
553 DCHECK_EQ(io_message_loop_proxy_, 553 DCHECK_EQ(io_message_loop_proxy_,
554 request_context_getter_->GetIOMessageLoopProxy()); 554 request_context_getter_->GetIOMessageLoopProxy());
555 } else { 555 } else {
556 io_message_loop_proxy_ = request_context_getter_->GetIOMessageLoopProxy(); 556 io_message_loop_proxy_ = request_context_getter_->GetIOMessageLoopProxy();
557 } 557 }
558 CHECK(io_message_loop_proxy_.get()) << "We need an IO message loop proxy"; 558 DCHECK(io_message_loop_proxy_.get()) << "We need an IO message loop proxy";
559 559
560 io_message_loop_proxy_->PostTask( 560 io_message_loop_proxy_->PostTask(
561 FROM_HERE, base::Bind(&Core::StartOnIOThread, this)); 561 FROM_HERE, base::Bind(&Core::StartOnIOThread, this));
562 } 562 }
563 563
564 void URLFetcher::Core::StartOnIOThread() { 564 void URLFetcher::Core::StartOnIOThread() {
565 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 565 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
566 566
567 switch (response_destination_) { 567 switch (response_destination_) {
568 case STRING: 568 case STRING:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 DCHECK(request_.get()); 627 DCHECK(request_.get());
628 DCHECK(!content.empty()); 628 DCHECK(!content.empty());
629 request_->AppendChunkToUpload(content.data(), 629 request_->AppendChunkToUpload(content.data(),
630 static_cast<int>(content.length()), 630 static_cast<int>(content.length()),
631 is_last_chunk); 631 is_last_chunk);
632 } 632 }
633 633
634 void URLFetcher::Core::AppendChunkToUpload(const std::string& content, 634 void URLFetcher::Core::AppendChunkToUpload(const std::string& content,
635 bool is_last_chunk) { 635 bool is_last_chunk) {
636 DCHECK(delegate_loop_proxy_); 636 DCHECK(delegate_loop_proxy_);
637 CHECK(io_message_loop_proxy_.get()); 637 DCHECK(io_message_loop_proxy_.get());
638 io_message_loop_proxy_->PostTask( 638 io_message_loop_proxy_->PostTask(
639 FROM_HERE, 639 FROM_HERE,
640 base::Bind(&Core::CompleteAddingUploadDataChunk, this, content, 640 base::Bind(&Core::CompleteAddingUploadDataChunk, this, content,
641 is_last_chunk)); 641 is_last_chunk));
642 } 642 }
643 643
644 // Return true if the write was done and reading may continue. 644 // Return true if the write was done and reading may continue.
645 // Return false if the write is pending, and the next read will 645 // Return false if the write is pending, and the next read will
646 // be done later. 646 // be done later.
647 bool URLFetcher::Core::WriteBuffer(int num_bytes) { 647 bool URLFetcher::Core::WriteBuffer(int num_bytes) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 763
764 void URLFetcher::Core::StartURLRequest() { 764 void URLFetcher::Core::StartURLRequest() {
765 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 765 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
766 766
767 if (was_cancelled_) { 767 if (was_cancelled_) {
768 // Since StartURLRequest() is posted as a *delayed* task, it may 768 // Since StartURLRequest() is posted as a *delayed* task, it may
769 // run after the URLFetcher was already stopped. 769 // run after the URLFetcher was already stopped.
770 return; 770 return;
771 } 771 }
772 772
773 CHECK(request_context_getter_); 773 DCHECK(request_context_getter_);
774 DCHECK(!request_.get()); 774 DCHECK(!request_.get());
775 775
776 g_registry.Get().AddURLFetcherCore(this); 776 g_registry.Get().AddURLFetcherCore(this);
777 request_.reset(new net::URLRequest(original_url_, this)); 777 request_.reset(new net::URLRequest(original_url_, this));
778 int flags = request_->load_flags() | load_flags_; 778 int flags = request_->load_flags() | load_flags_;
779 if (!g_interception_enabled) { 779 if (!g_interception_enabled) {
780 flags = flags | net::LOAD_DISABLE_INTERCEPT; 780 flags = flags | net::LOAD_DISABLE_INTERCEPT;
781 } 781 }
782 if (is_chunked_upload_) 782 if (is_chunked_upload_)
783 request_->EnableChunkedUpload(); 783 request_->EnableChunkedUpload();
(...skipping 27 matching lines...) Expand all
811 } 811 }
812 812
813 if (!extra_request_headers_.IsEmpty()) 813 if (!extra_request_headers_.IsEmpty())
814 request_->SetExtraRequestHeaders(extra_request_headers_); 814 request_->SetExtraRequestHeaders(extra_request_headers_);
815 815
816 // There might be data left over from a previous request attempt. 816 // There might be data left over from a previous request attempt.
817 data_.clear(); 817 data_.clear();
818 818
819 // If we are writing the response to a file, the only caller 819 // If we are writing the response to a file, the only caller
820 // of this function should have created it and not written yet. 820 // of this function should have created it and not written yet.
821 CHECK(!temp_file_writer_.get() || 821 DCHECK(!temp_file_writer_.get() ||
822 temp_file_writer_->total_bytes_written() == 0); 822 temp_file_writer_->total_bytes_written() == 0);
823 823
824 request_->Start(); 824 request_->Start();
825 } 825 }
826 826
827 void URLFetcher::Core::StartURLRequestWhenAppropriate() { 827 void URLFetcher::Core::StartURLRequestWhenAppropriate() {
828 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 828 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
829 829
830 if (was_cancelled_) 830 if (was_cancelled_)
831 return; 831 return;
832 832
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 867 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
868 868
869 // Save the status and backoff_delay so that delegates can read it. 869 // Save the status and backoff_delay so that delegates can read it.
870 if (delegate_) { 870 if (delegate_) {
871 backoff_delay_ = backoff_delay; 871 backoff_delay_ = backoff_delay;
872 InformDelegateFetchIsComplete(); 872 InformDelegateFetchIsComplete();
873 } 873 }
874 } 874 }
875 875
876 void URLFetcher::Core::InformDelegateFetchIsComplete() { 876 void URLFetcher::Core::InformDelegateFetchIsComplete() {
877 CHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 877 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
878 if (delegate_) { 878 if (delegate_) {
879 delegate_->OnURLFetchComplete(fetcher_); 879 delegate_->OnURLFetchComplete(fetcher_);
880 } 880 }
881 } 881 }
882 882
883 void URLFetcher::Core::NotifyMalformedContent() { 883 void URLFetcher::Core::NotifyMalformedContent() {
884 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 884 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
885 if (url_throttler_entry_ != NULL) { 885 if (url_throttler_entry_ != NULL) {
886 int status_code = response_code_; 886 int status_code = response_code_;
887 if (status_code == kInvalidHttpResponseCode) { 887 if (status_code == kInvalidHttpResponseCode) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 1075
1076 bool URLFetcher::GetResponseAsString(std::string* out_response_string) const { 1076 bool URLFetcher::GetResponseAsString(std::string* out_response_string) const {
1077 if (core_->response_destination_ != STRING) 1077 if (core_->response_destination_ != STRING)
1078 return false; 1078 return false;
1079 1079
1080 *out_response_string = core_->data_; 1080 *out_response_string = core_->data_;
1081 return true; 1081 return true;
1082 } 1082 }
1083 1083
1084 const std::string& URLFetcher::GetResponseStringRef() const { 1084 const std::string& URLFetcher::GetResponseStringRef() const {
1085 CHECK(core_->response_destination_ == STRING); 1085 DCHECK(core_->response_destination_ == STRING);
1086 return core_->data_; 1086 return core_->data_;
1087 } 1087 }
1088 1088
1089 void URLFetcher::SetResponseDestinationForTesting( 1089 void URLFetcher::SetResponseDestinationForTesting(
1090 ResponseDestinationType value) { 1090 ResponseDestinationType value) {
1091 core_->response_destination_ = value; 1091 core_->response_destination_ = value;
1092 } 1092 }
1093 1093
1094 URLFetcher::ResponseDestinationType 1094 URLFetcher::ResponseDestinationType
1095 URLFetcher::GetResponseDestinationForTesting() const { 1095 URLFetcher::GetResponseDestinationForTesting() const {
(...skipping 22 matching lines...) Expand all
1118 } 1118 }
1119 1119
1120 // static 1120 // static
1121 int URLFetcher::GetNumFetcherCores() { 1121 int URLFetcher::GetNumFetcherCores() {
1122 return Core::g_registry.Get().size(); 1122 return Core::g_registry.Get().size();
1123 } 1123 }
1124 1124
1125 URLFetcher::Delegate* URLFetcher::delegate() const { 1125 URLFetcher::Delegate* URLFetcher::delegate() const {
1126 return core_->delegate(); 1126 return core_->delegate();
1127 } 1127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698