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/files/file_util.h" | 8 #include "base/files/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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ComputedHashes::Reader reader; | 78 ComputedHashes::Reader reader; |
79 if (!reader.InitFromFile(computed_hashes_path)) | 79 if (!reader.InitFromFile(computed_hashes_path)) |
80 return false; | 80 return false; |
81 | 81 |
82 have_computed_hashes_ = true; | 82 have_computed_hashes_ = true; |
83 | 83 |
84 if (!reader.GetHashes(relative_path_, &block_size_, &hashes_) || | 84 if (!reader.GetHashes(relative_path_, &block_size_, &hashes_) || |
85 block_size_ % crypto::kSHA256Length != 0) | 85 block_size_ % crypto::kSHA256Length != 0) |
86 return false; | 86 return false; |
87 | 87 |
88 const std::string* expected_root = | |
89 verified_contents_->GetTreeHashRoot(relative_path_); | |
90 if (!expected_root) | |
91 return false; | |
92 | |
93 std::string root = | 88 std::string root = |
94 ComputeTreeHashRoot(hashes_, block_size_ / crypto::kSHA256Length); | 89 ComputeTreeHashRoot(hashes_, block_size_ / crypto::kSHA256Length); |
95 if (*expected_root != root) | 90 if (!verified_contents_->TreeHashRootEquals(relative_path_, root)) |
96 return false; | 91 return false; |
97 | 92 |
98 status_ = SUCCESS; | 93 status_ = SUCCESS; |
99 UMA_HISTOGRAM_TIMES("ExtensionContentHashReader.InitLatency", | 94 UMA_HISTOGRAM_TIMES("ExtensionContentHashReader.InitLatency", |
100 timer.Elapsed()); | 95 timer.Elapsed()); |
101 return true; | 96 return true; |
102 } | 97 } |
103 | 98 |
104 int ContentHashReader::block_count() const { | 99 int ContentHashReader::block_count() const { |
105 DCHECK(status_ != NOT_INITIALIZED); | 100 DCHECK(status_ != NOT_INITIALIZED); |
(...skipping 12 matching lines...) Expand all Loading... |
118 DCHECK(block_index >= 0); | 113 DCHECK(block_index >= 0); |
119 | 114 |
120 if (static_cast<unsigned>(block_index) >= hashes_.size()) | 115 if (static_cast<unsigned>(block_index) >= hashes_.size()) |
121 return false; | 116 return false; |
122 *result = &hashes_[block_index]; | 117 *result = &hashes_[block_index]; |
123 | 118 |
124 return true; | 119 return true; |
125 } | 120 } |
126 | 121 |
127 } // namespace extensions | 122 } // namespace extensions |
OLD | NEW |