Commit 74ecc94c authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

ContentHashReader: Simplify how state of hashes are stored.

ContentHashReader doesn't need to remember whether each of
"verified_contents.json" and "computed_hashes.json" were found
correctly, the caller only cares whether both of them are present or
not. Collapse the two bools into one.

Bug: None
Change-Id: Idc0b0538f66ff88767acee87eba048ecd429df00
Reviewed-on: https://chromium-review.googlesource.com/828543
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524590}
parent cfc9d280
...@@ -33,12 +33,7 @@ ContentHashReader::ContentHashReader(const std::string& extension_id, ...@@ -33,12 +33,7 @@ ContentHashReader::ContentHashReader(const std::string& extension_id,
extension_version_(extension_version.GetString()), extension_version_(extension_version.GetString()),
extension_root_(extension_root), extension_root_(extension_root),
relative_path_(relative_path), relative_path_(relative_path),
key_(key), key_(key) {}
status_(NOT_INITIALIZED),
have_verified_contents_(false),
have_computed_hashes_(false),
file_missing_from_verified_contents_(false),
block_size_(0) {}
ContentHashReader::~ContentHashReader() { ContentHashReader::~ContentHashReader() {
} }
...@@ -60,8 +55,6 @@ bool ContentHashReader::Init() { ...@@ -60,8 +55,6 @@ bool ContentHashReader::Init() {
return false; return false;
} }
have_verified_contents_ = true;
base::FilePath computed_hashes_path = base::FilePath computed_hashes_path =
file_util::GetComputedHashesPath(extension_root_); file_util::GetComputedHashesPath(extension_root_);
if (!base::PathExists(computed_hashes_path)) if (!base::PathExists(computed_hashes_path))
...@@ -71,7 +64,7 @@ bool ContentHashReader::Init() { ...@@ -71,7 +64,7 @@ bool ContentHashReader::Init() {
if (!reader.InitFromFile(computed_hashes_path)) if (!reader.InitFromFile(computed_hashes_path))
return false; return false;
have_computed_hashes_ = true; has_content_hashes_ = true;
// Extensions sometimes request resources that do not have an entry in // Extensions sometimes request resources that do not have an entry in
// verified_contents.json. This can happen when an extension sends an XHR to a // verified_contents.json. This can happen when an extension sends an XHR to a
......
...@@ -39,14 +39,12 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> { ...@@ -39,14 +39,12 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> {
// should likely be discarded. // should likely be discarded.
bool Init(); bool Init();
// These return whether we found valid verified_contents.json / // Returns true if we found valid verified_contents.json and
// computed_hashes.json files respectively. Note that both of these can be // computed_hashes.json files. Note that this can be true even if we didn't
// true but we still didn't find an entry for |relative_path_| in them. // find an entry for |relative_path_| in them.
bool have_verified_contents() const { return have_verified_contents_; } bool has_content_hashes() const { return has_content_hashes_; }
bool have_computed_hashes() const { return have_computed_hashes_; }
// Returns whether or not this resource's entry exists in // Returns whether or not this resource's entry exists in
// verified_contents.json (given that both |have_verified_contents_| and // verified_contents.json (given that |has_content_hashes_| is true.
// |have_computed_hashes_| are true).
bool file_missing_from_verified_contents() const { bool file_missing_from_verified_contents() const {
return file_missing_from_verified_contents_; return file_missing_from_verified_contents_;
} }
...@@ -72,14 +70,13 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> { ...@@ -72,14 +70,13 @@ class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> {
base::FilePath relative_path_; base::FilePath relative_path_;
ContentVerifierKey key_; ContentVerifierKey key_;
InitStatus status_; InitStatus status_ = NOT_INITIALIZED;
bool have_verified_contents_; bool has_content_hashes_ = false;
bool have_computed_hashes_; bool file_missing_from_verified_contents_ = false;
bool file_missing_from_verified_contents_;
// The blocksize used for generating the hashes. // The blocksize used for generating the hashes.
int block_size_; int block_size_ = 0;
std::vector<std::string> hashes_; std::vector<std::string> hashes_;
......
...@@ -175,8 +175,7 @@ void ContentVerifyJob::OnHashesReady(bool success) { ...@@ -175,8 +175,7 @@ void ContentVerifyJob::OnHashesReady(bool success) {
// TODO(lazyboy): Make ContentHashReader::Init return an enum instead of // TODO(lazyboy): Make ContentHashReader::Init return an enum instead of
// bool. This should make the following checks on |hash_reader_| easier // bool. This should make the following checks on |hash_reader_| easier
// to digest and will avoid future bugs from creeping up. // to digest and will avoid future bugs from creeping up.
if (!hash_reader_->have_verified_contents() || if (!hash_reader_->has_content_hashes()) {
!hash_reader_->have_computed_hashes()) {
DispatchFailureCallback(MISSING_ALL_HASHES); DispatchFailureCallback(MISSING_ALL_HASHES);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment