| 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_fetcher.h" | 5 #include "extensions/browser/content_hash_fetcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // for each one. | 372 // for each one. |
| 373 ComputedHashes::Writer writer; | 373 ComputedHashes::Writer writer; |
| 374 for (SortedFilePathSet::iterator i = paths.begin(); i != paths.end(); ++i) { | 374 for (SortedFilePathSet::iterator i = paths.begin(); i != paths.end(); ++i) { |
| 375 if (IsCancelled()) | 375 if (IsCancelled()) |
| 376 return false; | 376 return false; |
| 377 const base::FilePath& full_path = *i; | 377 const base::FilePath& full_path = *i; |
| 378 base::FilePath relative_path; | 378 base::FilePath relative_path; |
| 379 extension_path_.AppendRelativePath(full_path, &relative_path); | 379 extension_path_.AppendRelativePath(full_path, &relative_path); |
| 380 relative_path = relative_path.NormalizePathSeparatorsTo('/'); | 380 relative_path = relative_path.NormalizePathSeparatorsTo('/'); |
| 381 | 381 |
| 382 const std::string* expected_root = | 382 if (!verified_contents_->HasTreeHashRoot(relative_path)) |
| 383 verified_contents_->GetTreeHashRoot(relative_path); | |
| 384 if (!expected_root) | |
| 385 continue; | 383 continue; |
| 386 | 384 |
| 387 std::string contents; | 385 std::string contents; |
| 388 if (!base::ReadFileToString(full_path, &contents)) { | 386 if (!base::ReadFileToString(full_path, &contents)) { |
| 389 LOG(ERROR) << "Could not read " << full_path.MaybeAsASCII(); | 387 LOG(ERROR) << "Could not read " << full_path.MaybeAsASCII(); |
| 390 continue; | 388 continue; |
| 391 } | 389 } |
| 392 | 390 |
| 393 // Iterate through taking the hash of each block of size (block_size_) of | 391 // Iterate through taking the hash of each block of size (block_size_) of |
| 394 // the file. | 392 // the file. |
| 395 std::vector<std::string> hashes; | 393 std::vector<std::string> hashes; |
| 396 ComputedHashes::ComputeHashesForContent(contents, block_size_, &hashes); | 394 ComputedHashes::ComputeHashesForContent(contents, block_size_, &hashes); |
| 397 std::string root = | 395 std::string root = |
| 398 ComputeTreeHashRoot(hashes, block_size_ / crypto::kSHA256Length); | 396 ComputeTreeHashRoot(hashes, block_size_ / crypto::kSHA256Length); |
| 399 if (expected_root && *expected_root != root) { | 397 if (!verified_contents_->TreeHashRootEquals(relative_path, root)) { |
| 400 VLOG(1) << "content mismatch for " << relative_path.AsUTF8Unsafe(); | 398 VLOG(1) << "content mismatch for " << relative_path.AsUTF8Unsafe(); |
| 401 hash_mismatch_paths_.insert(relative_path); | 399 hash_mismatch_paths_.insert(relative_path); |
| 402 continue; | 400 continue; |
| 403 } | 401 } |
| 404 | 402 |
| 405 writer.AddHashes(relative_path, block_size_, hashes); | 403 writer.AddHashes(relative_path, block_size_, hashes); |
| 406 } | 404 } |
| 407 bool result = writer.WriteToFile(hashes_file); | 405 bool result = writer.WriteToFile(hashes_file); |
| 408 UMA_HISTOGRAM_TIMES("ExtensionContentHashFetcher.CreateHashesTime", | 406 UMA_HISTOGRAM_TIMES("ExtensionContentHashFetcher.CreateHashesTime", |
| 409 timer.Elapsed()); | 407 timer.Elapsed()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 496 |
| 499 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { | 497 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { |
| 500 if (i->second.get() == job) { | 498 if (i->second.get() == job) { |
| 501 jobs_.erase(i); | 499 jobs_.erase(i); |
| 502 break; | 500 break; |
| 503 } | 501 } |
| 504 } | 502 } |
| 505 } | 503 } |
| 506 | 504 |
| 507 } // namespace extensions | 505 } // namespace extensions |
| OLD | NEW |