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 "chrome/browser/extensions/updater/local_extension_cache.h" | 5 #include "chrome/browser/extensions/updater/local_extension_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 base::Bind(&base::DoNothing), callback); | 68 base::Bind(&base::DoNothing), callback); |
69 } | 69 } |
70 | 70 |
71 // static | 71 // static |
72 LocalExtensionCache::CacheMap::iterator LocalExtensionCache::FindExtension( | 72 LocalExtensionCache::CacheMap::iterator LocalExtensionCache::FindExtension( |
73 CacheMap& cache, | 73 CacheMap& cache, |
74 const std::string& id, | 74 const std::string& id, |
75 const std::string& expected_hash) { | 75 const std::string& expected_hash) { |
76 CacheHit hit = cache.equal_range(id); | 76 CacheHit hit = cache.equal_range(id); |
77 CacheMap::iterator empty_hash = cache.end(); | 77 CacheMap::iterator empty_hash = cache.end(); |
78 std::string hash = base::StringToLowerASCII(expected_hash); | 78 std::string hash = base::ToLowerASCII(expected_hash); |
79 for (CacheMap::iterator it = hit.first; it != hit.second; ++it) { | 79 for (CacheMap::iterator it = hit.first; it != hit.second; ++it) { |
80 if (expected_hash.empty() || it->second.expected_hash == hash) { | 80 if (expected_hash.empty() || it->second.expected_hash == hash) { |
81 return it; | 81 return it; |
82 } | 82 } |
83 if (it->second.expected_hash.empty()) { | 83 if (it->second.expected_hash.empty()) { |
84 empty_hash = it; | 84 empty_hash = it; |
85 } | 85 } |
86 } | 86 } |
87 return empty_hash; | 87 return empty_hash; |
88 } | 88 } |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 430 |
431 n = version.find('-'); | 431 n = version.find('-'); |
432 if (n != std::string::npos && n + 1 < version.size()) { | 432 if (n != std::string::npos && n + 1 < version.size()) { |
433 expected_hash = version.substr(n + 1, version.size() - n - 1); | 433 expected_hash = version.substr(n + 1, version.size() - n - 1); |
434 version.resize(n); | 434 version.resize(n); |
435 } | 435 } |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 // Enforce a lower-case id. | 439 // Enforce a lower-case id. |
440 id = base::StringToLowerASCII(id); | 440 id = base::ToLowerASCII(id); |
441 if (!crx_file::id_util::IdIsValid(id)) { | 441 if (!crx_file::id_util::IdIsValid(id)) { |
442 LOG(ERROR) << "Bad extension id in cache: " << id; | 442 LOG(ERROR) << "Bad extension id in cache: " << id; |
443 id.clear(); | 443 id.clear(); |
444 } | 444 } |
445 | 445 |
446 if (!Version(version).IsValid()) { | 446 if (!Version(version).IsValid()) { |
447 LOG(ERROR) << "Bad extension version in cache: " << version; | 447 LOG(ERROR) << "Bad extension version in cache: " << version; |
448 version.clear(); | 448 version.clear(); |
449 } | 449 } |
450 | 450 |
(...skipping 28 matching lines...) Expand all Loading... |
479 base::TouchFile(file_path, time, time); | 479 base::TouchFile(file_path, time, time); |
480 } | 480 } |
481 | 481 |
482 // static | 482 // static |
483 std::string LocalExtensionCache::ExtensionFileName( | 483 std::string LocalExtensionCache::ExtensionFileName( |
484 const std::string& id, | 484 const std::string& id, |
485 const std::string& version, | 485 const std::string& version, |
486 const std::string& expected_hash) { | 486 const std::string& expected_hash) { |
487 std::string filename = id + "-" + version; | 487 std::string filename = id + "-" + version; |
488 if (!expected_hash.empty()) | 488 if (!expected_hash.empty()) |
489 filename += "-" + base::StringToLowerASCII(expected_hash); | 489 filename += "-" + base::ToLowerASCII(expected_hash); |
490 filename += kCRXFileExtension; | 490 filename += kCRXFileExtension; |
491 return filename; | 491 return filename; |
492 } | 492 } |
493 | 493 |
494 // static | 494 // static |
495 void LocalExtensionCache::BackendInstallCacheEntry( | 495 void LocalExtensionCache::BackendInstallCacheEntry( |
496 base::WeakPtr<LocalExtensionCache> local_cache, | 496 base::WeakPtr<LocalExtensionCache> local_cache, |
497 const base::FilePath& cache_dir, | 497 const base::FilePath& cache_dir, |
498 const std::string& id, | 498 const std::string& id, |
499 const std::string& expected_hash, | 499 const std::string& expected_hash, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 605 } |
606 } | 606 } |
607 | 607 |
608 LocalExtensionCache::CacheItemInfo::CacheItemInfo( | 608 LocalExtensionCache::CacheItemInfo::CacheItemInfo( |
609 const std::string& version, | 609 const std::string& version, |
610 const std::string& expected_hash, | 610 const std::string& expected_hash, |
611 const base::Time& last_used, | 611 const base::Time& last_used, |
612 uint64 size, | 612 uint64 size, |
613 const base::FilePath& file_path) | 613 const base::FilePath& file_path) |
614 : version(version), | 614 : version(version), |
615 expected_hash(base::StringToLowerASCII(expected_hash)), | 615 expected_hash(base::ToLowerASCII(expected_hash)), |
616 last_used(last_used), | 616 last_used(last_used), |
617 size(size), | 617 size(size), |
618 file_path(file_path) { | 618 file_path(file_path) { |
619 } | 619 } |
620 | 620 |
621 LocalExtensionCache::CacheItemInfo::~CacheItemInfo() { | 621 LocalExtensionCache::CacheItemInfo::~CacheItemInfo() { |
622 } | 622 } |
623 | 623 |
624 } // namespace extensions | 624 } // namespace extensions |
OLD | NEW |