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

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

Issue 11843003: Add SetUploadDataStream method to URLFetcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes Created 7 years, 11 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
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_fetcher_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_);
352 DCHECK(!upload_content_);
353 DCHECK(upload_content_type_.empty());
342 upload_content_type_ = upload_content_type; 354 upload_content_type_ = upload_content_type;
343 upload_content_ = upload_content; 355 upload_content_ = upload_content.Pass();
344 } 356 }
345 357
346 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { 358 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) {
347 DCHECK(is_chunked_upload_ || 359 DCHECK(is_chunked_upload_ ||
348 (upload_content_type_.empty() && 360 (upload_content_type_.empty() &&
349 upload_content_.empty())); 361 !upload_content_));
350 upload_content_type_ = content_type; 362 upload_content_type_ = content_type;
351 upload_content_.clear(); 363 upload_content_.reset();
352 is_chunked_upload_ = true; 364 is_chunked_upload_ = true;
353 } 365 }
354 366
355 void URLFetcherCore::AppendChunkToUpload(const std::string& content, 367 void URLFetcherCore::AppendChunkToUpload(const std::string& content,
356 bool is_last_chunk) { 368 bool is_last_chunk) {
357 DCHECK(delegate_task_runner_); 369 DCHECK(delegate_task_runner_);
358 DCHECK(network_task_runner_.get()); 370 DCHECK(network_task_runner_.get());
359 network_task_runner_->PostTask( 371 network_task_runner_->PostTask(
360 FROM_HERE, 372 FROM_HERE,
361 base::Bind(&URLFetcherCore::CompleteAddingUploadDataChunk, this, content, 373 base::Bind(&URLFetcherCore::CompleteAddingUploadDataChunk, this, content,
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 break; 743 break;
732 744
733 case URLFetcher::POST: 745 case URLFetcher::POST:
734 case URLFetcher::PUT: 746 case URLFetcher::PUT:
735 DCHECK(!upload_content_type_.empty()); 747 DCHECK(!upload_content_type_.empty());
736 748
737 request_->set_method( 749 request_->set_method(
738 request_type_ == URLFetcher::POST ? "POST" : "PUT"); 750 request_type_ == URLFetcher::POST ? "POST" : "PUT");
739 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, 751 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType,
740 upload_content_type_); 752 upload_content_type_);
741 if (!upload_content_.empty()) { 753 if (upload_content_)
742 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( 754 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; 755 current_upload_bytes_ = -1;
749 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the 756 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the
750 // layer and avoid using timer here. 757 // layer and avoid using timer here.
751 upload_progress_checker_timer_.reset( 758 upload_progress_checker_timer_.reset(
752 new base::RepeatingTimer<URLFetcherCore>()); 759 new base::RepeatingTimer<URLFetcherCore>());
753 upload_progress_checker_timer_->Start( 760 upload_progress_checker_timer_->Start(
754 FROM_HERE, 761 FROM_HERE,
755 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), 762 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval),
756 this, 763 this,
757 &URLFetcherCore::InformDelegateUploadProgress); 764 &URLFetcherCore::InformDelegateUploadProgress);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 OnReadCompleted(request_.get(), bytes_read); 1012 OnReadCompleted(request_.get(), bytes_read);
1006 } 1013 }
1007 1014
1008 void URLFetcherCore::DisownFile() { 1015 void URLFetcherCore::DisownFile() {
1009 file_writer_->DisownFile(); 1016 file_writer_->DisownFile();
1010 } 1017 }
1011 1018
1012 void URLFetcherCore::InformDelegateUploadProgress() { 1019 void URLFetcherCore::InformDelegateUploadProgress() {
1013 DCHECK(network_task_runner_->BelongsToCurrentThread()); 1020 DCHECK(network_task_runner_->BelongsToCurrentThread());
1014 if (request_.get()) { 1021 if (request_.get()) {
1015 int64 current = request_->GetUploadProgress().position(); 1022 int64 current = request_->GetUploadProgress().position();
hashimoto 2013/01/15 06:59:28 nit: How about replacing |current| and |total| wit
mattm 2013/01/24 02:35:46 Tried it out, but I think it just makes things a m
1016 if (current_upload_bytes_ != current) { 1023 if (current_upload_bytes_ != current) {
1017 current_upload_bytes_ = current; 1024 current_upload_bytes_ = current;
1018 int64 total = -1; 1025 int64 total = -1;
1019 if (!is_chunked_upload_) 1026 if (!is_chunked_upload_) {
1020 total = static_cast<int64>(upload_content_.size()); 1027 total = static_cast<int64>(request_->GetUploadProgress().size());
1028 // Total may be zero if the UploadDataStream::Init has not been called
1029 // yet. Don't send the upload progress until the size is initialized.
1030 if (!total)
1031 return;
1032 }
1021 delegate_task_runner_->PostTask( 1033 delegate_task_runner_->PostTask(
1022 FROM_HERE, 1034 FROM_HERE,
1023 base::Bind( 1035 base::Bind(
1024 &URLFetcherCore::InformDelegateUploadProgressInDelegateThread, 1036 &URLFetcherCore::InformDelegateUploadProgressInDelegateThread,
1025 this, current, total)); 1037 this, current, total));
1026 } 1038 }
1027 } 1039 }
1028 } 1040 }
1029 1041
1030 void URLFetcherCore::InformDelegateUploadProgressInDelegateThread( 1042 void URLFetcherCore::InformDelegateUploadProgressInDelegateThread(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 } 1076 }
1065 1077
1066 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( 1078 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread(
1067 scoped_ptr<std::string> download_data) { 1079 scoped_ptr<std::string> download_data) {
1068 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 1080 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
1069 if (delegate_) 1081 if (delegate_)
1070 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); 1082 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass());
1071 } 1083 }
1072 1084
1073 } // namespace net 1085 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_fetcher_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698