| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 void BaseFile::Finish() { | 369 void BaseFile::Finish() { |
| 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 371 | 371 |
| 372 if (calculate_hash_) | 372 if (calculate_hash_) |
| 373 secure_hash_->Finish(sha256_hash_, kSha256HashLen); | 373 secure_hash_->Finish(sha256_hash_, kSha256HashLen); |
| 374 | 374 |
| 375 Close(); | 375 Close(); |
| 376 } | 376 } |
| 377 | 377 |
| 378 bool BaseFile::GetPartialSha256Hash(std::string* hash) { |
| 379 DCHECK(!detached_); |
| 380 if (calculate_hash_) |
| 381 hash->assign(reinterpret_cast<const char*>(sha256_hash_), kSha256HashLen); |
| 382 return calculate_hash_; |
| 383 } |
| 384 |
| 385 bool BaseFile::SetPartialSha256Hash(const std::string& hash) { |
| 386 DCHECK(!detached_); |
| 387 DCHECK(hash.size() == kSha256HashLen); |
| 388 if (calculate_hash_) { |
| 389 memset(sha256_hash_, 0, kSha256HashLen); |
| 390 memcpy(sha256_hash_, hash.c_str(), kSha256HashLen); |
| 391 } |
| 392 return calculate_hash_; |
| 393 } |
| 394 |
| 378 bool BaseFile::GetSha256Hash(std::string* hash) { | 395 bool BaseFile::GetSha256Hash(std::string* hash) { |
| 379 DCHECK(!detached_); | 396 if (in_progress()) |
| 380 if (!calculate_hash_ || in_progress()) | |
| 381 return false; | 397 return false; |
| 382 hash->assign(reinterpret_cast<const char*>(sha256_hash_), | 398 return GetPartialSha256Hash(hash); |
| 383 sizeof(sha256_hash_)); | |
| 384 return true; | |
| 385 } | 399 } |
| 386 | 400 |
| 387 void BaseFile::AnnotateWithSourceInformation() { | 401 void BaseFile::AnnotateWithSourceInformation() { |
| 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 389 DCHECK(!detached_); | 403 DCHECK(!detached_); |
| 390 | 404 |
| 391 #if defined(OS_WIN) | 405 #if defined(OS_WIN) |
| 392 // Sets the Zone to tell Windows that this file comes from the internet. | 406 // Sets the Zone to tell Windows that this file comes from the internet. |
| 393 // We ignore the return value because a failure is not fatal. | 407 // We ignore the return value because a failure is not fatal. |
| 394 win_util::SetInternetZoneIdentifier(full_path_, | 408 win_util::SetInternetZoneIdentifier(full_path_, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 std::string BaseFile::DebugString() const { | 467 std::string BaseFile::DebugString() const { |
| 454 return base::StringPrintf("{ source_url_ = \"%s\"" | 468 return base::StringPrintf("{ source_url_ = \"%s\"" |
| 455 " full_path_ = \"%" PRFilePath "\"" | 469 " full_path_ = \"%" PRFilePath "\"" |
| 456 " bytes_so_far_ = %" PRId64 | 470 " bytes_so_far_ = %" PRId64 |
| 457 " detached_ = %c }", | 471 " detached_ = %c }", |
| 458 source_url_.spec().c_str(), | 472 source_url_.spec().c_str(), |
| 459 full_path_.value().c_str(), | 473 full_path_.value().c_str(), |
| 460 bytes_so_far_, | 474 bytes_so_far_, |
| 461 detached_ ? 'T' : 'F'); | 475 detached_ ? 'T' : 'F'); |
| 462 } | 476 } |
| OLD | NEW |