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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 bool LocalExtensionCache::RemoveExtension(const std::string& id) { | 138 bool LocalExtensionCache::RemoveExtension(const std::string& id) { |
139 if (state_ != kReady) | 139 if (state_ != kReady) |
140 return false; | 140 return false; |
141 | 141 |
142 CacheMap::iterator it = cached_extensions_.find(id); | 142 CacheMap::iterator it = cached_extensions_.find(id); |
143 if (it == cached_extensions_.end()) | 143 if (it == cached_extensions_.end()) |
144 return false; | 144 return false; |
145 | 145 |
146 backend_task_runner_->PostTask( | 146 backend_task_runner_->PostTask( |
147 FROM_HERE, | 147 FROM_HERE, |
148 base::Bind(&LocalExtensionCache::BackendRemoveCacheEntry, | 148 base::Bind( |
149 it->second.file_path)); | 149 &LocalExtensionCache::BackendRemoveCacheEntry, cache_dir_, id)); |
150 | 150 |
151 cached_extensions_.erase(it); | 151 cached_extensions_.erase(it); |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 bool LocalExtensionCache::GetStatistics(uint64* cache_size, | 155 bool LocalExtensionCache::GetStatistics(uint64* cache_size, |
156 size_t* extensions_count) { | 156 size_t* extensions_count) { |
157 if (state_ != kReady) | 157 if (state_ != kReady) |
158 return false; | 158 return false; |
159 | 159 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 it = cached_extensions_.insert(std::make_pair(id, info)).first; | 431 it = cached_extensions_.insert(std::make_pair(id, info)).first; |
432 } | 432 } |
433 // Time from file system can have lower precision so use precise "now". | 433 // Time from file system can have lower precision so use precise "now". |
434 it->second.last_used = base::Time::Now(); | 434 it->second.last_used = base::Time::Now(); |
435 | 435 |
436 callback.Run(info.file_path, false); | 436 callback.Run(info.file_path, false); |
437 } | 437 } |
438 | 438 |
439 // static | 439 // static |
440 void LocalExtensionCache::BackendRemoveCacheEntry( | 440 void LocalExtensionCache::BackendRemoveCacheEntry( |
441 const base::FilePath& file_path) { | 441 const base::FilePath& cache_dir, |
442 base::DeleteFile(file_path, true /* recursive */); | 442 const std::string& id) { |
443 VLOG(1) << "Removed cached file " << file_path.value(); | 443 std::string file_patthen = id + "-*" + kCRXFileExtension; |
asargent_no_longer_on_chrome
2014/05/15 17:49:01
nit: should this be "file_pattern" ?
jennyz
2014/05/15 18:51:22
Done.
| |
444 base::FileEnumerator enumerator(cache_dir, | |
445 false /* not recursive */, | |
446 base::FileEnumerator::FILES, | |
447 file_patthen); | |
448 for (base::FilePath path = enumerator.Next(); !path.empty(); | |
449 path = enumerator.Next()) { | |
450 CHECK(base::DeleteFile(path, false)); | |
asargent_no_longer_on_chrome
2014/05/15 17:49:01
Is it appropriate to crash the whole browser if yo
jennyz
2014/05/15 18:51:22
Done.
| |
451 VLOG(1) << "Removed cached file " << path.value(); | |
452 } | |
444 } | 453 } |
445 | 454 |
446 // static | 455 // static |
447 bool LocalExtensionCache::CompareCacheItemsAge(const CacheMap::iterator& lhs, | 456 bool LocalExtensionCache::CompareCacheItemsAge(const CacheMap::iterator& lhs, |
448 const CacheMap::iterator& rhs) { | 457 const CacheMap::iterator& rhs) { |
449 return lhs->second.last_used < rhs->second.last_used; | 458 return lhs->second.last_used < rhs->second.last_used; |
450 } | 459 } |
451 | 460 |
452 void LocalExtensionCache::CleanUp() { | 461 void LocalExtensionCache::CleanUp() { |
453 DCHECK_EQ(state_, kReady); | 462 DCHECK_EQ(state_, kReady); |
(...skipping 21 matching lines...) Expand all Loading... | |
475 | 484 |
476 LocalExtensionCache::CacheItemInfo::CacheItemInfo( | 485 LocalExtensionCache::CacheItemInfo::CacheItemInfo( |
477 const std::string& version, | 486 const std::string& version, |
478 const base::Time& last_used, | 487 const base::Time& last_used, |
479 uint64 size, | 488 uint64 size, |
480 const base::FilePath& file_path) | 489 const base::FilePath& file_path) |
481 : version(version), last_used(last_used), size(size), file_path(file_path) { | 490 : version(version), last_used(last_used), size(size), file_path(file_path) { |
482 } | 491 } |
483 | 492 |
484 } // namespace extensions | 493 } // namespace extensions |
OLD | NEW |