Chromium Code Reviews| Index: content/browser/download/base_file.cc |
| diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc |
| index 51121001de8b64534119d8a7fb99411b77f7e324..47aad4944b1aabfc54bfe815ab66380765ad9dea 100644 |
| --- a/content/browser/download/base_file.cc |
| +++ b/content/browser/download/base_file.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/file_util.h" |
| #include "base/format_macros.h" |
| #include "base/logging.h" |
| +#include "base/pickle.h" |
| #include "base/stringprintf.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "base/utf_string_conversions.h" |
| @@ -193,6 +194,7 @@ BaseFile::BaseFile(const FilePath& full_path, |
| const GURL& source_url, |
| const GURL& referrer_url, |
| int64 received_bytes, |
| + const std::string& hash_state, |
| const linked_ptr<net::FileStream>& file_stream) |
| : full_path_(full_path), |
| source_url_(source_url), |
| @@ -201,6 +203,7 @@ BaseFile::BaseFile(const FilePath& full_path, |
| bytes_so_far_(received_bytes), |
| power_save_blocker_(PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep), |
| calculate_hash_(false), |
| + initial_hash_state_(hash_state), |
| detached_(false) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| memcpy(sha256_hash_, kEmptySha256Hash, kSha256HashLen); |
| @@ -222,8 +225,11 @@ net::Error BaseFile::Initialize(bool calculate_hash) { |
| calculate_hash_ = calculate_hash; |
| - if (calculate_hash_) |
| + if (calculate_hash_) { |
| secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
| + if (!initial_hash_state_.empty() && (bytes_so_far_ > 0)) |
|
Randy Smith (Not in Mondays)
2011/11/23 19:25:13
I'm inclined to leave out the "bytes_so_far_" test
ahendrickson
2011/12/20 00:04:14
I want to be able to zero the bytes_so_far_ value
Randy Smith (Not in Mondays)
2011/12/20 17:05:40
Why? That seems like it's just inconsistent data,
ahendrickson
2011/12/20 22:06:54
I will try to keep them consistent. I just think
|
| + SetSha256HashState(initial_hash_state_); |
| + } |
| if (full_path_.empty()) { |
| FilePath temp_file; |
| @@ -390,6 +396,28 @@ bool BaseFile::GetSha256Hash(std::string* hash) { |
| return (calculate_hash_ && !in_progress()); |
| } |
| +std::string BaseFile::GetSha256HashState() { |
| + if (!calculate_hash_) |
| + return ""; |
| + |
| + Pickle hash_state; |
| + if (!secure_hash_->Serialize(&hash_state)) |
| + return ""; |
| + |
| + return std::string(reinterpret_cast<const char*>(hash_state.data()), |
| + hash_state.size()); |
| +} |
| + |
| +bool BaseFile::SetSha256HashState(const std::string& hash_state_bytes) { |
| + if (!calculate_hash_) |
| + return false; |
| + |
| + Pickle hash_state(hash_state_bytes.c_str(), hash_state_bytes.size()); |
| + void* data_iterator = NULL; |
| + |
| + return secure_hash_->Deserialize(&data_iterator, &hash_state); |
| +} |
| + |
| bool BaseFile::IsEmptySha256Hash(const std::string& hash) { |
| return (hash.size() == kSha256HashLen && |
| 0 == memcmp(hash.data(), kEmptySha256Hash, sizeof(kSha256HashLen))); |