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

Side by Side Diff: content/browser/download/download_file_impl.cc

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Work on feedback. Created 3 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
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 "content/browser/download/download_file_impl.h" 5 #include "content/browser/download/download_file_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 BrowserThread::PostTask( 113 BrowserThread::PostTask(
114 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); 114 BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
115 return; 115 return;
116 } 116 }
117 117
118 download_start_ = base::TimeTicks::Now(); 118 download_start_ = base::TimeTicks::Now();
119 119
120 // Primarily to make reset to zero in restart visible to owner. 120 // Primarily to make reset to zero in restart visible to owner.
121 SendUpdate(); 121 SendUpdate();
122 122
123 // Initial pull from the straw. 123 // Initial pull from the straw from all source streams.
124 for (auto& source_stream : source_streams_) 124 for (auto& source_stream : source_streams_)
125 RegisterAndActivateStream(source_stream.second.get()); 125 RegisterAndActivateStream(source_stream.second.get());
126 126
127 BrowserThread::PostTask( 127 BrowserThread::PostTask(
128 BrowserThread::UI, FROM_HERE, base::Bind( 128 BrowserThread::UI, FROM_HERE, base::Bind(
129 callback, DOWNLOAD_INTERRUPT_REASON_NONE)); 129 callback, DOWNLOAD_INTERRUPT_REASON_NONE));
130 } 130 }
131 131
132 void DownloadFileImpl::AddByteStream( 132 void DownloadFileImpl::AddByteStream(
133 std::unique_ptr<ByteStreamReader> stream_reader, 133 std::unique_ptr<ByteStreamReader> stream_reader,
134 int64_t offset) { 134 int64_t offset,
135 int64_t length) {
135 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 136 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
137 DCHECK(source_streams_.find(offset) == source_streams_.end());
136 138
137 // The |source_streams_| must have an existing entry for the stream reader. 139 source_streams_[offset] = base::MakeUnique<SourceStream>(offset, length);
138 auto current_source_stream = source_streams_.find(offset); 140 SourceStream* stream = source_streams_[offset].get();
139 DCHECK(current_source_stream != source_streams_.end());
140 SourceStream* stream = current_source_stream->second.get();
141 stream->SetByteStream(std::move(stream_reader)); 141 stream->SetByteStream(std::move(stream_reader));
asanka 2017/03/14 19:44:01 Are all SourceStream constructions immediately fol
xingliu 2017/03/14 22:48:29 Done, Thanks for this suggestion, yeah, this make
142 142
143 RegisterAndActivateStream(stream); 143 // If the file is initialized, start to write data, or wait until file opened.
144 if (file_.in_progress())
145 RegisterAndActivateStream(stream);
144 } 146 }
145 147
146 DownloadInterruptReason DownloadFileImpl::WriteDataToFile(int64_t offset, 148 DownloadInterruptReason DownloadFileImpl::WriteDataToFile(int64_t offset,
147 const char* data, 149 const char* data,
148 size_t data_len) { 150 size_t data_len) {
149 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 151 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
150 WillWriteToDisk(data_len); 152 WillWriteToDisk(data_len);
151 return file_.WriteDataToFile(offset, data, data_len); 153 return file_.WriteDataToFile(offset, data, data_len);
152 } 154 }
153 155
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 const base::FilePath& new_path, 447 const base::FilePath& new_path,
446 const RenameCompletionCallback& completion_callback) 448 const RenameCompletionCallback& completion_callback)
447 : option(option), 449 : option(option),
448 new_path(new_path), 450 new_path(new_path),
449 retries_left(kMaxRenameRetries), 451 retries_left(kMaxRenameRetries),
450 completion_callback(completion_callback) {} 452 completion_callback(completion_callback) {}
451 453
452 DownloadFileImpl::RenameParameters::~RenameParameters() {} 454 DownloadFileImpl::RenameParameters::~RenameParameters() {}
453 455
454 } // namespace content 456 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698