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

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

Issue 12383015: Add SetUploadFilePath method to URLFetcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes Created 7 years, 9 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/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "base/tracked_objects.h" 13 #include "base/tracked_objects.h"
14 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
15 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/upload_bytes_element_reader.h" 17 #include "net/base/upload_bytes_element_reader.h"
18 #include "net/base/upload_data_stream.h" 18 #include "net/base/upload_data_stream.h"
19 #include "net/base/upload_file_element_reader.h"
19 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
20 #include "net/url_request/url_fetcher_delegate.h" 21 #include "net/url_request/url_fetcher_delegate.h"
21 #include "net/url_request/url_fetcher_file_writer.h" 22 #include "net/url_request/url_fetcher_file_writer.h"
22 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
23 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
24 #include "net/url_request/url_request_throttler_manager.h" 25 #include "net/url_request/url_request_throttler_manager.h"
25 26
26 namespace { 27 namespace {
27 28
28 const int kBufferSize = 4096; 29 const int kBufferSize = 4096;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 network_task_runner_->PostTask( 123 network_task_runner_->PostTask(
123 FROM_HERE, base::Bind(&URLFetcherCore::CancelURLRequest, this)); 124 FROM_HERE, base::Bind(&URLFetcherCore::CancelURLRequest, this));
124 } 125 }
125 } 126 }
126 127
127 void URLFetcherCore::SetUploadData(const std::string& upload_content_type, 128 void URLFetcherCore::SetUploadData(const std::string& upload_content_type,
128 const std::string& upload_content) { 129 const std::string& upload_content) {
129 DCHECK(!is_chunked_upload_); 130 DCHECK(!is_chunked_upload_);
130 DCHECK(!upload_content_set_); 131 DCHECK(!upload_content_set_);
131 DCHECK(upload_content_.empty()); 132 DCHECK(upload_content_.empty());
133 DCHECK(upload_file_path_.empty());
132 DCHECK(upload_content_type_.empty()); 134 DCHECK(upload_content_type_.empty());
133 135
134 // Empty |upload_content_type| is allowed iff the |upload_content| is empty. 136 // Empty |upload_content_type| is allowed iff the |upload_content| is empty.
135 DCHECK(upload_content.empty() || !upload_content_type.empty()); 137 DCHECK(upload_content.empty() || !upload_content_type.empty());
136 138
137 upload_content_type_ = upload_content_type; 139 upload_content_type_ = upload_content_type;
138 upload_content_ = upload_content; 140 upload_content_ = upload_content;
139 upload_content_set_ = true; 141 upload_content_set_ = true;
140 } 142 }
141 143
144 void URLFetcherCore::SetUploadFilePath(
145 const std::string& upload_content_type,
146 const base::FilePath& file_path,
147 scoped_refptr<base::TaskRunner> file_task_runner) {
148 DCHECK(!is_chunked_upload_);
149 DCHECK(!upload_content_set_);
150 DCHECK(upload_content_.empty());
151 DCHECK(upload_file_path_.empty());
152 DCHECK(upload_content_type_.empty());
153 DCHECK(!upload_content_type.empty());
154
155 upload_content_type_ = upload_content_type;
156 upload_file_path_ = file_path;
157 upload_file_task_runner_ = file_task_runner;
158 upload_content_set_ = true;
159 }
160
142 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { 161 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) {
143 DCHECK(is_chunked_upload_ || 162 DCHECK(is_chunked_upload_ ||
144 (upload_content_type_.empty() && 163 (upload_content_type_.empty() &&
145 upload_content_.empty())); 164 upload_content_.empty()));
146 165
147 // Empty |content_type| is not allowed here, because it is impossible 166 // Empty |content_type| is not allowed here, because it is impossible
148 // to ensure non-empty upload content as it is not yet supplied. 167 // to ensure non-empty upload content as it is not yet supplied.
149 DCHECK(!content_type.empty()); 168 DCHECK(!content_type.empty());
150 169
151 upload_content_type_ = content_type; 170 upload_content_type_ = content_type;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 upload_content_type_); 563 upload_content_type_);
545 if (!upload_content_type_.empty()) { 564 if (!upload_content_type_.empty()) {
546 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, 565 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType,
547 upload_content_type_); 566 upload_content_type_);
548 } 567 }
549 if (!upload_content_.empty()) { 568 if (!upload_content_.empty()) {
550 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( 569 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader(
551 upload_content_.data(), upload_content_.size())); 570 upload_content_.data(), upload_content_.size()));
552 request_->set_upload(make_scoped_ptr( 571 request_->set_upload(make_scoped_ptr(
553 UploadDataStream::CreateWithReader(reader.Pass(), 0))); 572 UploadDataStream::CreateWithReader(reader.Pass(), 0)));
573 } else if (!upload_file_path_.empty()) {
574 scoped_ptr<UploadElementReader> reader(new UploadFileElementReader(
575 upload_file_task_runner_,
576 upload_file_path_,
577 0, kuint64max, base::Time()));
578 request_->set_upload(make_scoped_ptr(
579 UploadDataStream::CreateWithReader(reader.Pass(), 0)));
554 } 580 }
555 581
556 current_upload_bytes_ = -1; 582 current_upload_bytes_ = -1;
557 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the 583 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the
558 // layer and avoid using timer here. 584 // layer and avoid using timer here.
559 upload_progress_checker_timer_.reset( 585 upload_progress_checker_timer_.reset(
560 new base::RepeatingTimer<URLFetcherCore>()); 586 new base::RepeatingTimer<URLFetcherCore>());
561 upload_progress_checker_timer_->Start( 587 upload_progress_checker_timer_->Start(
562 FROM_HERE, 588 FROM_HERE,
563 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), 589 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval),
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 file_writer_->DisownFile(); 869 file_writer_->DisownFile();
844 } 870 }
845 871
846 void URLFetcherCore::InformDelegateUploadProgress() { 872 void URLFetcherCore::InformDelegateUploadProgress() {
847 DCHECK(network_task_runner_->BelongsToCurrentThread()); 873 DCHECK(network_task_runner_->BelongsToCurrentThread());
848 if (request_.get()) { 874 if (request_.get()) {
849 int64 current = request_->GetUploadProgress().position(); 875 int64 current = request_->GetUploadProgress().position();
850 if (current_upload_bytes_ != current) { 876 if (current_upload_bytes_ != current) {
851 current_upload_bytes_ = current; 877 current_upload_bytes_ = current;
852 int64 total = -1; 878 int64 total = -1;
853 if (!is_chunked_upload_) 879 if (!is_chunked_upload_) {
854 total = static_cast<int64>(upload_content_.size()); 880 total = static_cast<int64>(request_->GetUploadProgress().size());
881 // Total may be zero if the UploadDataStream::Init has not been called
882 // yet. Don't send the upload progress until the size is initialized.
883 if (!total)
884 return;
885 }
855 delegate_task_runner_->PostTask( 886 delegate_task_runner_->PostTask(
856 FROM_HERE, 887 FROM_HERE,
857 base::Bind( 888 base::Bind(
858 &URLFetcherCore::InformDelegateUploadProgressInDelegateThread, 889 &URLFetcherCore::InformDelegateUploadProgressInDelegateThread,
859 this, current, total)); 890 this, current, total));
860 } 891 }
861 } 892 }
862 } 893 }
863 894
864 void URLFetcherCore::InformDelegateUploadProgressInDelegateThread( 895 void URLFetcherCore::InformDelegateUploadProgressInDelegateThread(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 } 929 }
899 930
900 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( 931 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread(
901 scoped_ptr<std::string> download_data) { 932 scoped_ptr<std::string> download_data) {
902 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 933 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
903 if (delegate_) 934 if (delegate_)
904 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); 935 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass());
905 } 936 }
906 937
907 } // namespace net 938 } // 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