| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/content_hash_reader.h" | 5 #include "extensions/browser/content_hash_reader.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 const base::Version& extension_version, | 28 const base::Version& extension_version, |
| 29 const base::FilePath& extension_root, | 29 const base::FilePath& extension_root, |
| 30 const base::FilePath& relative_path, | 30 const base::FilePath& relative_path, |
| 31 const ContentVerifierKey& key) | 31 const ContentVerifierKey& key) |
| 32 : extension_id_(extension_id), | 32 : extension_id_(extension_id), |
| 33 extension_version_(extension_version.GetString()), | 33 extension_version_(extension_version.GetString()), |
| 34 extension_root_(extension_root), | 34 extension_root_(extension_root), |
| 35 relative_path_(relative_path), | 35 relative_path_(relative_path), |
| 36 key_(key), | 36 key_(key), |
| 37 status_(NOT_INITIALIZED), | 37 status_(NOT_INITIALIZED), |
| 38 content_exists_(false), |
| 38 have_verified_contents_(false), | 39 have_verified_contents_(false), |
| 39 have_computed_hashes_(false), | 40 have_computed_hashes_(false), |
| 40 block_size_(0) { | 41 block_size_(0) { |
| 41 } | 42 } |
| 42 | 43 |
| 43 ContentHashReader::~ContentHashReader() { | 44 ContentHashReader::~ContentHashReader() { |
| 44 } | 45 } |
| 45 | 46 |
| 46 bool ContentHashReader::Init() { | 47 bool ContentHashReader::Init() { |
| 47 base::ElapsedTimer timer; | 48 base::ElapsedTimer timer; |
| 48 DCHECK_EQ(status_, NOT_INITIALIZED); | 49 DCHECK_EQ(status_, NOT_INITIALIZED); |
| 49 status_ = FAILURE; | 50 status_ = FAILURE; |
| 50 base::FilePath verified_contents_path = | 51 base::FilePath verified_contents_path = |
| 51 file_util::GetVerifiedContentsPath(extension_root_); | 52 file_util::GetVerifiedContentsPath(extension_root_); |
| 52 | 53 |
| 54 // Check that this is a valid resource to verify (i.e., it exists). |
| 55 base::FilePath content_path = extension_root_.Append(relative_path_); |
| 56 if (!base::PathExists(content_path)) |
| 57 return false; |
| 58 |
| 59 content_exists_ = true; |
| 60 |
| 53 if (!base::PathExists(verified_contents_path)) | 61 if (!base::PathExists(verified_contents_path)) |
| 54 return false; | 62 return false; |
| 55 | 63 |
| 56 verified_contents_.reset(new VerifiedContents(key_.data, key_.size)); | 64 verified_contents_.reset(new VerifiedContents(key_.data, key_.size)); |
| 57 if (!verified_contents_->InitFrom(verified_contents_path, false) || | 65 if (!verified_contents_->InitFrom(verified_contents_path, false) || |
| 58 !verified_contents_->valid_signature() || | 66 !verified_contents_->valid_signature() || |
| 59 !verified_contents_->version().Equals(extension_version_) || | 67 !verified_contents_->version().Equals(extension_version_) || |
| 60 verified_contents_->extension_id() != extension_id_) | 68 verified_contents_->extension_id() != extension_id_) |
| 61 return false; | 69 return false; |
| 62 | 70 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 DCHECK(block_index >= 0); | 118 DCHECK(block_index >= 0); |
| 111 | 119 |
| 112 if (static_cast<unsigned>(block_index) >= hashes_.size()) | 120 if (static_cast<unsigned>(block_index) >= hashes_.size()) |
| 113 return false; | 121 return false; |
| 114 *result = &hashes_[block_index]; | 122 *result = &hashes_[block_index]; |
| 115 | 123 |
| 116 return true; | 124 return true; |
| 117 } | 125 } |
| 118 | 126 |
| 119 } // namespace extensions | 127 } // namespace extensions |
| OLD | NEW |