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

Unified Diff: content/browser/download/base_file.cc

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..685d0ed96e273be6535d31b05c54a5a6f05198c8 100644
--- a/content/browser/download/base_file.cc
+++ b/content/browser/download/base_file.cc
@@ -193,6 +193,7 @@ BaseFile::BaseFile(const FilePath& full_path,
const GURL& source_url,
const GURL& referrer_url,
int64 received_bytes,
+ const Pickle& hash_state,
const linked_ptr<net::FileStream>& file_stream)
: full_path_(full_path),
source_url_(source_url),
@@ -201,6 +202,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 +224,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_.size() != 0) && (bytes_so_far_ > 0))
+ SetSha256HashState(&initial_hash_state_);
+ }
if (full_path_.empty()) {
FilePath temp_file;
@@ -387,7 +392,16 @@ bool BaseFile::GetSha256Hash(std::string* hash) {
DCHECK(!detached_);
hash->assign(reinterpret_cast<const char*>(sha256_hash_),
sizeof(sha256_hash_));
- return (calculate_hash_ && !in_progress());
+ return (calculate_hash_);
+}
+
+bool BaseFile::GetSha256HashState(Pickle* hash_state) {
+ return secure_hash_->Serialize(hash_state);
+}
+
+bool BaseFile::SetSha256HashState(Pickle* hash_state) {
+ void* data_iterator = NULL;
+ return secure_hash_->Deserialize(&data_iterator, hash_state);
}
bool BaseFile::IsEmptySha256Hash(const std::string& hash) {

Powered by Google App Engine
This is Rietveld 408576698