OLD | NEW |
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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
266 DCHECK(!detached_); | 266 DCHECK(!detached_); |
267 | 267 |
268 // NOTE(benwells): The above DCHECK won't be present in release builds, | 268 // NOTE(benwells): The above DCHECK won't be present in release builds, |
269 // so we log any occurences to see how common this error is in the wild. | 269 // so we log any occurences to see how common this error is in the wild. |
270 if (detached_) { | 270 if (detached_) { |
271 download_stats::RecordDownloadCount( | 271 download_stats::RecordDownloadCount( |
272 download_stats::APPEND_TO_DETACHED_FILE_COUNT); | 272 download_stats::APPEND_TO_DETACHED_FILE_COUNT); |
273 } | 273 } |
274 | 274 |
275 if (bound_net_log_.IsLoggingAllEvents()) { | |
276 bound_net_log_.AddEvent( | |
277 net::NetLog::TYPE_DOWNLOAD_FILE_WRITTEN, | |
278 make_scoped_refptr(new net::NetLogIntegerParameter( | |
279 "byte_count", data_len))); | |
280 } | |
281 | |
282 if (!file_stream_.get()) | 275 if (!file_stream_.get()) |
283 return LOG_ERROR("get", net::ERR_INVALID_HANDLE); | 276 return LOG_ERROR("get", net::ERR_INVALID_HANDLE); |
284 | 277 |
285 // TODO(phajdan.jr): get rid of this check. | 278 // TODO(phajdan.jr): get rid of this check. |
286 if (data_len == 0) | 279 if (data_len == 0) |
287 return net::OK; | 280 return net::OK; |
288 | 281 |
289 // The Write call below is not guaranteed to write all the data. | 282 // The Write call below is not guaranteed to write all the data. |
290 size_t write_count = 0; | 283 size_t write_count = 0; |
291 size_t len = data_len; | 284 size_t len = data_len; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { | 554 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { |
562 base::TimeDelta diff = current_time - start_tick_; | 555 base::TimeDelta diff = current_time - start_tick_; |
563 int64 diff_ms = diff.InMilliseconds(); | 556 int64 diff_ms = diff.InMilliseconds(); |
564 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; | 557 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; |
565 } | 558 } |
566 | 559 |
567 int64 BaseFile::CurrentSpeed() const { | 560 int64 BaseFile::CurrentSpeed() const { |
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
569 return CurrentSpeedAtTime(base::TimeTicks::Now()); | 562 return CurrentSpeedAtTime(base::TimeTicks::Now()); |
570 } | 563 } |
OLD | NEW |