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

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: Rearranged structures for greater consistency. 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..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))
+ 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)));

Powered by Google App Engine
This is Rietveld 408576698