Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 if (network_task_runner_->RunsTasksOnCurrentThread()) { | 331 if (network_task_runner_->RunsTasksOnCurrentThread()) { |
| 332 CancelURLRequest(); | 332 CancelURLRequest(); |
| 333 } else { | 333 } else { |
| 334 network_task_runner_->PostTask( | 334 network_task_runner_->PostTask( |
| 335 FROM_HERE, base::Bind(&URLFetcherCore::CancelURLRequest, this)); | 335 FROM_HERE, base::Bind(&URLFetcherCore::CancelURLRequest, this)); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 void URLFetcherCore::SetUploadData(const std::string& upload_content_type, | 339 void URLFetcherCore::SetUploadData(const std::string& upload_content_type, |
| 340 const std::string& upload_content) { | 340 const std::string& upload_content) { |
| 341 scoped_ptr<UploadElementReader> reader( | |
| 342 UploadOwnedBytesElementReader::CreateWithString(upload_content)); | |
| 343 SetUploadDataStream( | |
| 344 upload_content_type, | |
| 345 make_scoped_ptr(UploadDataStream::CreateWithReader(reader.Pass(), 0))); | |
| 346 } | |
| 347 | |
| 348 void URLFetcherCore::SetUploadDataStream( | |
| 349 const std::string& upload_content_type, | |
| 350 scoped_ptr<UploadDataStream> upload_content) { | |
| 341 DCHECK(!is_chunked_upload_); | 351 DCHECK(!is_chunked_upload_); |
|
mmenke
2013/01/11 16:25:40
DCHECK(!upload_content);
Also maybe DCHECK(upload
mattm
2013/01/11 21:42:02
Done.
| |
| 342 upload_content_type_ = upload_content_type; | 352 upload_content_type_ = upload_content_type; |
| 343 upload_content_ = upload_content; | 353 upload_content_ = upload_content.Pass(); |
| 344 } | 354 } |
| 345 | 355 |
| 346 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { | 356 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { |
| 347 DCHECK(is_chunked_upload_ || | 357 DCHECK(is_chunked_upload_ || |
| 348 (upload_content_type_.empty() && | 358 (upload_content_type_.empty() && |
| 349 upload_content_.empty())); | 359 !upload_content_)); |
| 350 upload_content_type_ = content_type; | 360 upload_content_type_ = content_type; |
| 351 upload_content_.clear(); | 361 upload_content_.reset(); |
| 352 is_chunked_upload_ = true; | 362 is_chunked_upload_ = true; |
| 353 } | 363 } |
| 354 | 364 |
| 355 void URLFetcherCore::AppendChunkToUpload(const std::string& content, | 365 void URLFetcherCore::AppendChunkToUpload(const std::string& content, |
| 356 bool is_last_chunk) { | 366 bool is_last_chunk) { |
| 357 DCHECK(delegate_task_runner_); | 367 DCHECK(delegate_task_runner_); |
| 358 DCHECK(network_task_runner_.get()); | 368 DCHECK(network_task_runner_.get()); |
| 359 network_task_runner_->PostTask( | 369 network_task_runner_->PostTask( |
| 360 FROM_HERE, | 370 FROM_HERE, |
| 361 base::Bind(&URLFetcherCore::CompleteAddingUploadDataChunk, this, content, | 371 base::Bind(&URLFetcherCore::CompleteAddingUploadDataChunk, this, content, |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 break; | 741 break; |
| 732 | 742 |
| 733 case URLFetcher::POST: | 743 case URLFetcher::POST: |
| 734 case URLFetcher::PUT: | 744 case URLFetcher::PUT: |
| 735 DCHECK(!upload_content_type_.empty()); | 745 DCHECK(!upload_content_type_.empty()); |
| 736 | 746 |
| 737 request_->set_method( | 747 request_->set_method( |
| 738 request_type_ == URLFetcher::POST ? "POST" : "PUT"); | 748 request_type_ == URLFetcher::POST ? "POST" : "PUT"); |
| 739 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, | 749 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, |
| 740 upload_content_type_); | 750 upload_content_type_); |
| 741 if (!upload_content_.empty()) { | 751 if (upload_content_) |
| 742 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( | 752 request_->set_upload(upload_content_.Pass()); |
| 743 upload_content_.data(), upload_content_.size())); | |
| 744 request_->set_upload(make_scoped_ptr( | |
| 745 UploadDataStream::CreateWithReader(reader.Pass(), 0))); | |
| 746 } | |
| 747 | |
| 748 current_upload_bytes_ = -1; | 753 current_upload_bytes_ = -1; |
| 749 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the | 754 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the |
| 750 // layer and avoid using timer here. | 755 // layer and avoid using timer here. |
| 751 upload_progress_checker_timer_.reset( | 756 upload_progress_checker_timer_.reset( |
| 752 new base::RepeatingTimer<URLFetcherCore>()); | 757 new base::RepeatingTimer<URLFetcherCore>()); |
| 753 upload_progress_checker_timer_->Start( | 758 upload_progress_checker_timer_->Start( |
| 754 FROM_HERE, | 759 FROM_HERE, |
| 755 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), | 760 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), |
| 756 this, | 761 this, |
| 757 &URLFetcherCore::InformDelegateUploadProgress); | 762 &URLFetcherCore::InformDelegateUploadProgress); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 OnReadCompleted(request_.get(), bytes_read); | 1010 OnReadCompleted(request_.get(), bytes_read); |
| 1006 } | 1011 } |
| 1007 | 1012 |
| 1008 void URLFetcherCore::DisownFile() { | 1013 void URLFetcherCore::DisownFile() { |
| 1009 file_writer_->DisownFile(); | 1014 file_writer_->DisownFile(); |
| 1010 } | 1015 } |
| 1011 | 1016 |
| 1012 void URLFetcherCore::InformDelegateUploadProgress() { | 1017 void URLFetcherCore::InformDelegateUploadProgress() { |
| 1013 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 1018 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 1014 if (request_.get()) { | 1019 if (request_.get()) { |
| 1015 int64 current = request_->GetUploadProgress().position(); | 1020 int64 current = request_->GetUploadProgress().position(); |
|
hashimoto
2013/01/11 06:07:38
You can use request_->GetUploadProgress().size() f
mattm
2013/01/11 21:42:02
Done.
| |
| 1016 if (current_upload_bytes_ != current) { | 1021 if (current_upload_bytes_ != current) { |
| 1017 current_upload_bytes_ = current; | 1022 current_upload_bytes_ = current; |
| 1018 int64 total = -1; | 1023 int64 total = -1; |
| 1019 if (!is_chunked_upload_) | 1024 if (!is_chunked_upload_) |
| 1020 total = static_cast<int64>(upload_content_.size()); | 1025 total = static_cast<int64>(request_->get_upload()->size()); |
|
hashimoto
2013/01/11 06:07:38
This change introduces a little difference to the
mattm
2013/01/11 21:42:02
Done.
| |
| 1021 delegate_task_runner_->PostTask( | 1026 delegate_task_runner_->PostTask( |
| 1022 FROM_HERE, | 1027 FROM_HERE, |
| 1023 base::Bind( | 1028 base::Bind( |
| 1024 &URLFetcherCore::InformDelegateUploadProgressInDelegateThread, | 1029 &URLFetcherCore::InformDelegateUploadProgressInDelegateThread, |
| 1025 this, current, total)); | 1030 this, current, total)); |
| 1026 } | 1031 } |
| 1027 } | 1032 } |
| 1028 } | 1033 } |
| 1029 | 1034 |
| 1030 void URLFetcherCore::InformDelegateUploadProgressInDelegateThread( | 1035 void URLFetcherCore::InformDelegateUploadProgressInDelegateThread( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 } | 1069 } |
| 1065 | 1070 |
| 1066 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( | 1071 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( |
| 1067 scoped_ptr<std::string> download_data) { | 1072 scoped_ptr<std::string> download_data) { |
| 1068 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 1073 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 1069 if (delegate_) | 1074 if (delegate_) |
| 1070 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); | 1075 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); |
| 1071 } | 1076 } |
| 1072 | 1077 |
| 1073 } // namespace net | 1078 } // namespace net |
| OLD | NEW |