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

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

Issue 14578004: Support range uploading of a file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 delegate_(d), 71 delegate_(d),
72 delegate_task_runner_( 72 delegate_task_runner_(
73 base::ThreadTaskRunnerHandle::Get()), 73 base::ThreadTaskRunnerHandle::Get()),
74 request_(NULL), 74 request_(NULL),
75 load_flags_(LOAD_NORMAL), 75 load_flags_(LOAD_NORMAL),
76 response_code_(URLFetcher::RESPONSE_CODE_INVALID), 76 response_code_(URLFetcher::RESPONSE_CODE_INVALID),
77 buffer_(new IOBuffer(kBufferSize)), 77 buffer_(new IOBuffer(kBufferSize)),
78 url_request_data_key_(NULL), 78 url_request_data_key_(NULL),
79 was_fetched_via_proxy_(false), 79 was_fetched_via_proxy_(false),
80 upload_content_set_(false), 80 upload_content_set_(false),
81 upload_range_offset_(0),
82 upload_range_length_(0),
81 is_chunked_upload_(false), 83 is_chunked_upload_(false),
82 was_cancelled_(false), 84 was_cancelled_(false),
83 file_writer_(NULL), 85 file_writer_(NULL),
84 response_destination_(STRING), 86 response_destination_(STRING),
85 stop_on_redirect_(false), 87 stop_on_redirect_(false),
86 stopped_on_redirect_(false), 88 stopped_on_redirect_(false),
87 automatically_retry_on_5xx_(true), 89 automatically_retry_on_5xx_(true),
88 num_retries_on_5xx_(0), 90 num_retries_on_5xx_(0),
89 max_retries_on_5xx_(0), 91 max_retries_on_5xx_(0),
90 num_retries_on_network_changes_(0), 92 num_retries_on_network_changes_(0),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DCHECK(upload_content.empty() || !upload_content_type.empty()); 140 DCHECK(upload_content.empty() || !upload_content_type.empty());
139 141
140 upload_content_type_ = upload_content_type; 142 upload_content_type_ = upload_content_type;
141 upload_content_ = upload_content; 143 upload_content_ = upload_content;
142 upload_content_set_ = true; 144 upload_content_set_ = true;
143 } 145 }
144 146
145 void URLFetcherCore::SetUploadFilePath( 147 void URLFetcherCore::SetUploadFilePath(
146 const std::string& upload_content_type, 148 const std::string& upload_content_type,
147 const base::FilePath& file_path, 149 const base::FilePath& file_path,
150 uint64 range_offset,
151 uint64 range_length,
148 scoped_refptr<base::TaskRunner> file_task_runner) { 152 scoped_refptr<base::TaskRunner> file_task_runner) {
149 DCHECK(!is_chunked_upload_); 153 DCHECK(!is_chunked_upload_);
150 DCHECK(!upload_content_set_); 154 DCHECK(!upload_content_set_);
151 DCHECK(upload_content_.empty()); 155 DCHECK(upload_content_.empty());
152 DCHECK(upload_file_path_.empty()); 156 DCHECK(upload_file_path_.empty());
157 DCHECK_EQ(upload_range_offset_, 0ULL);
158 DCHECK_EQ(upload_range_length_, 0ULL);
153 DCHECK(upload_content_type_.empty()); 159 DCHECK(upload_content_type_.empty());
154 DCHECK(!upload_content_type.empty()); 160 DCHECK(!upload_content_type.empty());
155 161
156 upload_content_type_ = upload_content_type; 162 upload_content_type_ = upload_content_type;
157 upload_file_path_ = file_path; 163 upload_file_path_ = file_path;
164 upload_range_offset_ = range_offset;
165 upload_range_length_ = range_length;
158 upload_file_task_runner_ = file_task_runner; 166 upload_file_task_runner_ = file_task_runner;
159 upload_content_set_ = true; 167 upload_content_set_ = true;
160 } 168 }
161 169
162 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) { 170 void URLFetcherCore::SetChunkedUpload(const std::string& content_type) {
163 DCHECK(is_chunked_upload_ || 171 DCHECK(is_chunked_upload_ ||
164 (upload_content_type_.empty() && 172 (upload_content_type_.empty() &&
165 upload_content_.empty())); 173 upload_content_.empty()));
166 174
167 // Empty |content_type| is not allowed here, because it is impossible 175 // Empty |content_type| is not allowed here, because it is impossible
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 570 }
563 if (!upload_content_.empty()) { 571 if (!upload_content_.empty()) {
564 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( 572 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader(
565 upload_content_.data(), upload_content_.size())); 573 upload_content_.data(), upload_content_.size()));
566 request_->set_upload(make_scoped_ptr( 574 request_->set_upload(make_scoped_ptr(
567 UploadDataStream::CreateWithReader(reader.Pass(), 0))); 575 UploadDataStream::CreateWithReader(reader.Pass(), 0)));
568 } else if (!upload_file_path_.empty()) { 576 } else if (!upload_file_path_.empty()) {
569 scoped_ptr<UploadElementReader> reader(new UploadFileElementReader( 577 scoped_ptr<UploadElementReader> reader(new UploadFileElementReader(
570 upload_file_task_runner_, 578 upload_file_task_runner_,
571 upload_file_path_, 579 upload_file_path_,
572 0, kuint64max, base::Time())); 580 upload_range_offset_,
581 upload_range_length_,
582 base::Time()));
573 request_->set_upload(make_scoped_ptr( 583 request_->set_upload(make_scoped_ptr(
574 UploadDataStream::CreateWithReader(reader.Pass(), 0))); 584 UploadDataStream::CreateWithReader(reader.Pass(), 0)));
575 } 585 }
576 586
577 current_upload_bytes_ = -1; 587 current_upload_bytes_ = -1;
578 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the 588 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the
579 // layer and avoid using timer here. 589 // layer and avoid using timer here.
580 upload_progress_checker_timer_.reset( 590 upload_progress_checker_timer_.reset(
581 new base::RepeatingTimer<URLFetcherCore>()); 591 new base::RepeatingTimer<URLFetcherCore>());
582 upload_progress_checker_timer_->Start( 592 upload_progress_checker_timer_->Start(
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 } 910 }
901 911
902 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( 912 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread(
903 scoped_ptr<std::string> download_data) { 913 scoped_ptr<std::string> download_data) {
904 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); 914 DCHECK(delegate_task_runner_->BelongsToCurrentThread());
905 if (delegate_) 915 if (delegate_)
906 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); 916 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass());
907 } 917 }
908 918
909 } // namespace net 919 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698