summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/base_file.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/download/base_file.h')
-rw-r--r--chrome/browser/download/base_file.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/chrome/browser/download/base_file.h b/chrome/browser/download/base_file.h
index ffa63cc..3b0782a 100644
--- a/chrome/browser/download/base_file.h
+++ b/chrome/browser/download/base_file.h
@@ -10,6 +10,8 @@
#include "base/file_path.h"
#include "base/linked_ptr.h"
+#include "base/scoped_ptr.h"
+#include "base/third_party/nss/blapi.h"
#include "chrome/browser/power_save_blocker.h"
#include "googleurl/src/gurl.h"
@@ -28,7 +30,8 @@ class BaseFile {
const linked_ptr<net::FileStream>& file_stream);
~BaseFile();
- bool Initialize();
+ // If calculate_hash is true, sha256 hash will be calculated.
+ bool Initialize(bool calculate_hash);
// Write a new chunk of data to the file. Returns true on success (all bytes
// written to the file).
@@ -53,6 +56,10 @@ class BaseFile {
bool in_progress() const { return file_stream_ != NULL; }
int64 bytes_so_far() const { return bytes_so_far_; }
+ // Set |hash| with sha256 digest for the file.
+ // Returns true if digest is successfully calculated.
+ virtual bool GetSha256Hash(std::string* hash);
+
virtual std::string DebugString() const;
protected:
@@ -66,6 +73,8 @@ class BaseFile {
bool path_renamed_;
private:
+ static const size_t kSha256HashLen = 32;
+
// Source URL for the file being downloaded.
GURL source_url_;
@@ -81,6 +90,15 @@ class BaseFile {
// RAII handle to keep the system from sleeping while we're downloading.
PowerSaveBlocker power_save_blocker_;
+ // Indicates if sha256 hash should be calculated for the file.
+ bool calculate_hash_;
+
+ // Used to calculate sha256 hash for the file when calculate_hash_
+ // is set.
+ scoped_ptr<SHA256Context> sha_context_;
+
+ unsigned char sha256_hash_[kSha256HashLen];
+
DISALLOW_COPY_AND_ASSIGN(BaseFile);
};