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/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 Loading... |
211 Close(); | 211 Close(); |
212 } | 212 } |
213 | 213 |
214 // OS_WIN, OS_MACOSX and OS_LINUX have specialized implementations. | 214 // OS_WIN, OS_MACOSX and OS_LINUX have specialized implementations. |
215 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX) | 215 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX) |
216 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation() { | 216 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation() { |
217 return DOWNLOAD_INTERRUPT_REASON_NONE; | 217 return DOWNLOAD_INTERRUPT_REASON_NONE; |
218 } | 218 } |
219 #endif | 219 #endif |
220 | 220 |
221 int64 BaseFile::CurrentSpeed() const { | |
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
223 return CurrentSpeedAtTime(base::TimeTicks::Now()); | |
224 } | |
225 | |
226 bool BaseFile::GetHash(std::string* hash) { | 221 bool BaseFile::GetHash(std::string* hash) { |
227 DCHECK(!detached_); | 222 DCHECK(!detached_); |
228 hash->assign(reinterpret_cast<const char*>(sha256_hash_), | 223 hash->assign(reinterpret_cast<const char*>(sha256_hash_), |
229 sizeof(sha256_hash_)); | 224 sizeof(sha256_hash_)); |
230 return (calculate_hash_ && !in_progress()); | 225 return (calculate_hash_ && !in_progress()); |
231 } | 226 } |
232 | 227 |
233 std::string BaseFile::GetHashState() { | 228 std::string BaseFile::GetHashState() { |
234 if (!calculate_hash_) | 229 if (!calculate_hash_) |
235 return std::string(); | 230 return std::string(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 327 } |
333 } | 328 } |
334 | 329 |
335 void BaseFile::ClearStream() { | 330 void BaseFile::ClearStream() { |
336 // This should only be called when we have a stream. | 331 // This should only be called when we have a stream. |
337 DCHECK(file_stream_.get() != NULL); | 332 DCHECK(file_stream_.get() != NULL); |
338 file_stream_.reset(); | 333 file_stream_.reset(); |
339 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED); | 334 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED); |
340 } | 335 } |
341 | 336 |
342 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { | |
343 base::TimeDelta diff = current_time - start_tick_; | |
344 int64 diff_ms = diff.InMilliseconds(); | |
345 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; | |
346 } | |
347 | |
348 DownloadInterruptReason BaseFile::LogNetError( | 337 DownloadInterruptReason BaseFile::LogNetError( |
349 const char* operation, | 338 const char* operation, |
350 net::Error error) { | 339 net::Error error) { |
351 bound_net_log_.AddEvent( | 340 bound_net_log_.AddEvent( |
352 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 341 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
353 base::Bind(&FileErrorNetLogCallback, operation, error)); | 342 base::Bind(&FileErrorNetLogCallback, operation, error)); |
354 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); | 343 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); |
355 } | 344 } |
356 | 345 |
357 DownloadInterruptReason BaseFile::LogSystemError( | 346 DownloadInterruptReason BaseFile::LogSystemError( |
(...skipping 11 matching lines...) Expand all Loading... |
369 const char* operation, | 358 const char* operation, |
370 int os_error, | 359 int os_error, |
371 DownloadInterruptReason reason) { | 360 DownloadInterruptReason reason) { |
372 bound_net_log_.AddEvent( | 361 bound_net_log_.AddEvent( |
373 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 362 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
374 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 363 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
375 return reason; | 364 return reason; |
376 } | 365 } |
377 | 366 |
378 } // namespace content | 367 } // namespace content |
OLD | NEW |