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

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

Issue 809663003: net: Add SetUploadStream method to URLFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 } 136 }
137 137
138 void URLFetcherCore::SetUploadData(const std::string& upload_content_type, 138 void URLFetcherCore::SetUploadData(const std::string& upload_content_type,
139 const std::string& upload_content) { 139 const std::string& upload_content) {
140 DCHECK(!is_chunked_upload_); 140 DCHECK(!is_chunked_upload_);
141 DCHECK(!upload_content_set_); 141 DCHECK(!upload_content_set_);
142 DCHECK(upload_content_.empty()); 142 DCHECK(upload_content_.empty());
143 DCHECK(upload_file_path_.empty()); 143 DCHECK(upload_file_path_.empty());
144 DCHECK(upload_content_type_.empty()); 144 DCHECK(upload_content_type_.empty());
145 DCHECK(!upload_stream_);
145 146
146 // Empty |upload_content_type| is allowed iff the |upload_content| is empty. 147 // Empty |upload_content_type| is allowed iff the |upload_content| is empty.
147 DCHECK(upload_content.empty() || !upload_content_type.empty()); 148 DCHECK(upload_content.empty() || !upload_content_type.empty());
148 149
149 upload_content_type_ = upload_content_type; 150 upload_content_type_ = upload_content_type;
150 upload_content_ = upload_content; 151 upload_content_ = upload_content;
151 upload_content_set_ = true; 152 upload_content_set_ = true;
152 } 153 }
153 154
154 void URLFetcherCore::SetUploadFilePath( 155 void URLFetcherCore::SetUploadFilePath(
155 const std::string& upload_content_type, 156 const std::string& upload_content_type,
156 const base::FilePath& file_path, 157 const base::FilePath& file_path,
157 uint64 range_offset, 158 uint64 range_offset,
158 uint64 range_length, 159 uint64 range_length,
159 scoped_refptr<base::TaskRunner> file_task_runner) { 160 scoped_refptr<base::TaskRunner> file_task_runner) {
160 DCHECK(!is_chunked_upload_); 161 DCHECK(!is_chunked_upload_);
161 DCHECK(!upload_content_set_); 162 DCHECK(!upload_content_set_);
162 DCHECK(upload_content_.empty()); 163 DCHECK(upload_content_.empty());
163 DCHECK(upload_file_path_.empty()); 164 DCHECK(upload_file_path_.empty());
164 DCHECK_EQ(upload_range_offset_, 0ULL); 165 DCHECK_EQ(upload_range_offset_, 0ULL);
165 DCHECK_EQ(upload_range_length_, 0ULL); 166 DCHECK_EQ(upload_range_length_, 0ULL);
166 DCHECK(upload_content_type_.empty()); 167 DCHECK(upload_content_type_.empty());
167 DCHECK(!upload_content_type.empty()); 168 DCHECK(!upload_content_type.empty());
169 DCHECK(!upload_stream_);
168 170
169 upload_content_type_ = upload_content_type; 171 upload_content_type_ = upload_content_type;
170 upload_file_path_ = file_path; 172 upload_file_path_ = file_path;
171 upload_range_offset_ = range_offset; 173 upload_range_offset_ = range_offset;
172 upload_range_length_ = range_length; 174 upload_range_length_ = range_length;
173 upload_file_task_runner_ = file_task_runner; 175 upload_file_task_runner_ = file_task_runner;
174 upload_content_set_ = true; 176 upload_content_set_ = true;
175 } 177 }
176 178
179 void URLFetcherCore::SetUploadStream(const std::string& upload_content_type,
180 scoped_ptr<net::UploadDataStream> stream) {
181 DCHECK(!is_chunked_upload_);
182 DCHECK(!upload_content_set_);
183 DCHECK(upload_content_.empty());
184 DCHECK(upload_file_path_.empty());
185 DCHECK(upload_content_type_.empty());
186 DCHECK(!upload_stream_);
187
188 upload_content_type_ = upload_content_type;
189 upload_stream_ = stream.Pass();
190 upload_content_set_ = true;
191 }
192
177 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { 193 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) {
178 DCHECK(is_chunked_upload_ || 194 DCHECK(is_chunked_upload_ ||
179 (upload_content_type_.empty() && 195 (upload_content_type_.empty() &&
180 upload_content_.empty())); 196 upload_content_.empty()));
181 197
182 // Empty |content_type| is not allowed here, because it is impossible 198 // Empty |content_type| is not allowed here, because it is impossible
183 // to ensure non-empty upload content as it is not yet supplied. 199 // to ensure non-empty upload content as it is not yet supplied.
184 DCHECK(!content_type.empty()); 200 DCHECK(!content_type.empty());
185 201
186 upload_content_type_ = content_type; 202 upload_content_type_ = content_type;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); 614 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
599 } else if (!upload_file_path_.empty()) { 615 } else if (!upload_file_path_.empty()) {
600 scoped_ptr<UploadElementReader> reader( 616 scoped_ptr<UploadElementReader> reader(
601 new UploadFileElementReader(upload_file_task_runner_.get(), 617 new UploadFileElementReader(upload_file_task_runner_.get(),
602 upload_file_path_, 618 upload_file_path_,
603 upload_range_offset_, 619 upload_range_offset_,
604 upload_range_length_, 620 upload_range_length_,
605 base::Time())); 621 base::Time()));
606 request_->set_upload( 622 request_->set_upload(
607 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0)); 623 ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0));
624 } else if (upload_stream_) {
625 request_->set_upload(upload_stream_.Pass());
608 } 626 }
609 627
610 current_upload_bytes_ = -1; 628 current_upload_bytes_ = -1;
611 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the 629 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the
612 // layer and avoid using timer here. 630 // layer and avoid using timer here.
613 upload_progress_checker_timer_.reset( 631 upload_progress_checker_timer_.reset(
614 new base::RepeatingTimer<URLFetcherCore>()); 632 new base::RepeatingTimer<URLFetcherCore>());
615 upload_progress_checker_timer_->Start( 633 upload_progress_checker_timer_->Start(
616 FROM_HERE, 634 FROM_HERE,
617 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), 635 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval),
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 } 958 }
941 959
942 void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread( 960 void URLFetcherCore::InformDelegateDownloadProgressInDelegateThread(
943 int64 current, int64 total) { 961 int64 current, int64 total) {
944 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 962 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
945 if (delegate_) 963 if (delegate_)
946 delegate_->OnURLFetchDownloadProgress(fetcher_, current, total); 964 delegate_->OnURLFetchDownloadProgress(fetcher_, current, total);
947 } 965 }
948 966
949 } // namespace net 967 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698