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

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

Issue 10799005: Replace the DownloadFileManager with direct ownership (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to LKGR. Created 8 years, 5 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 "content/browser/download/base_file.h" 5 #include "content/browser/download/base_file.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const net::BoundNetLog& bound_net_log) 211 const net::BoundNetLog& bound_net_log)
212 : full_path_(full_path), 212 : full_path_(full_path),
213 source_url_(source_url), 213 source_url_(source_url),
214 referrer_url_(referrer_url), 214 referrer_url_(referrer_url),
215 file_stream_(file_stream), 215 file_stream_(file_stream),
216 bytes_so_far_(received_bytes), 216 bytes_so_far_(received_bytes),
217 start_tick_(base::TimeTicks::Now()), 217 start_tick_(base::TimeTicks::Now()),
218 calculate_hash_(calculate_hash), 218 calculate_hash_(calculate_hash),
219 detached_(false), 219 detached_(false),
220 bound_net_log_(bound_net_log) { 220 bound_net_log_(bound_net_log) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
222 memcpy(sha256_hash_, kEmptySha256Hash, kSha256HashLen); 221 memcpy(sha256_hash_, kEmptySha256Hash, kSha256HashLen);
223 if (file_stream_.get()) { 222 if (file_stream_.get()) {
224 file_stream_->SetBoundNetLogSource(bound_net_log_); 223 file_stream_->SetBoundNetLogSource(bound_net_log_);
225 file_stream_->EnableErrorStatistics(); 224 file_stream_->EnableErrorStatistics();
226 } 225 }
227 226
228 if (calculate_hash_) { 227 if (calculate_hash_) {
229 secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); 228 secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256));
230 if ((bytes_so_far_ > 0) && // Not starting at the beginning. 229 if ((bytes_so_far_ > 0) && // Not starting at the beginning.
231 (hash_state != "") && // Reasonably sure we have a hash state. 230 (hash_state != "") && // Reasonably sure we have a hash state.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { 547 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const {
549 base::TimeDelta diff = current_time - start_tick_; 548 base::TimeDelta diff = current_time - start_tick_;
550 int64 diff_ms = diff.InMilliseconds(); 549 int64 diff_ms = diff.InMilliseconds();
551 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; 550 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms;
552 } 551 }
553 552
554 int64 BaseFile::CurrentSpeed() const { 553 int64 BaseFile::CurrentSpeed() const {
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
556 return CurrentSpeedAtTime(base::TimeTicks::Now()); 555 return CurrentSpeedAtTime(base::TimeTicks::Now());
557 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698