| 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 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Callback invoked on UI thread when PutExtension is completed. | 25 // Callback invoked on UI thread when PutExtension is completed. |
| 26 typedef base::Callback<void(const base::FilePath& file_path, | 26 typedef base::Callback<void(const base::FilePath& file_path, |
| 27 bool file_ownership_passed)> PutExtensionCallback; | 27 bool file_ownership_passed)> PutExtensionCallback; |
| 28 | 28 |
| 29 // |cache_dir| - directory that will be used for caching CRX files. | 29 // |cache_dir| - directory that will be used for caching CRX files. |
| 30 // |max_cache_size| - maximum disk space that cache can use, 0 means no limit. | 30 // |max_cache_size| - maximum disk space that cache can use, 0 means no limit. |
| 31 // |max_cache_age| - maximum age that unused item can be kept in cache, 0 age | 31 // |max_cache_age| - maximum age that unused item can be kept in cache, 0 age |
| 32 // means that all unused cache items will be removed on Shutdown. | 32 // means that all unused cache items will be removed on Shutdown. |
| 33 // All file I/O is done via the |backend_task_runner|. | 33 // All file I/O is done via the |backend_task_runner|. |
| 34 LocalExtensionCache(const base::FilePath& cache_dir, | 34 LocalExtensionCache(const base::FilePath& cache_dir, |
| 35 size_t max_cache_size, | 35 uint64 max_cache_size, |
| 36 const base::TimeDelta& max_cache_age, | 36 const base::TimeDelta& max_cache_age, |
| 37 const scoped_refptr<base::SequencedTaskRunner>& | 37 const scoped_refptr<base::SequencedTaskRunner>& |
| 38 backend_task_runner); | 38 backend_task_runner); |
| 39 ~LocalExtensionCache(); | 39 ~LocalExtensionCache(); |
| 40 | 40 |
| 41 // Name of flag file that indicates that cache is ready (import finished). | 41 // Name of flag file that indicates that cache is ready (import finished). |
| 42 static const char kCacheReadyFlagFileName[]; | 42 static const char kCacheReadyFlagFileName[]; |
| 43 | 43 |
| 44 // Initialize cache. If |wait_for_cache_initialization| is |true|, the cache | 44 // Initialize cache. If |wait_for_cache_initialization| is |true|, the cache |
| 45 // contents will not be read until a flag file appears in the cache directory, | 45 // contents will not be read until a flag file appears in the cache directory, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 66 // of |file_path| or return it back via |callback|. | 66 // of |file_path| or return it back via |callback|. |
| 67 void PutExtension(const std::string& id, | 67 void PutExtension(const std::string& id, |
| 68 const base::FilePath& file_path, | 68 const base::FilePath& file_path, |
| 69 const std::string& version, | 69 const std::string& version, |
| 70 const PutExtensionCallback& callback); | 70 const PutExtensionCallback& callback); |
| 71 | 71 |
| 72 // Remove extension with |id| from local cache, corresponding crx file will be | 72 // Remove extension with |id| from local cache, corresponding crx file will be |
| 73 // removed from disk too. | 73 // removed from disk too. |
| 74 bool RemoveExtension(const std::string& id); | 74 bool RemoveExtension(const std::string& id); |
| 75 | 75 |
| 76 // Return cache statistics. Returns |false| if cache is not ready. |
| 77 bool GetStatistics(uint64* cache_size, |
| 78 size_t* extensions_count); |
| 79 |
| 76 bool is_ready() const { return state_ == kReady; } | 80 bool is_ready() const { return state_ == kReady; } |
| 77 bool is_uninitialized() const { return state_ == kUninitialized; } | 81 bool is_uninitialized() const { return state_ == kUninitialized; } |
| 78 bool is_shutdown() const { return state_ == kShutdown; } | 82 bool is_shutdown() const { return state_ == kShutdown; } |
| 79 | 83 |
| 80 // For tests only! | 84 // For tests only! |
| 81 void SetCacheStatusPollingDelayForTests(const base::TimeDelta& delay); | 85 void SetCacheStatusPollingDelayForTests(const base::TimeDelta& delay); |
| 82 | 86 |
| 83 private: | 87 private: |
| 84 struct CacheItemInfo { | 88 struct CacheItemInfo { |
| 85 std::string version; | 89 std::string version; |
| 86 base::Time last_used; | 90 base::Time last_used; |
| 87 int64 size; | 91 uint64 size; |
| 88 base::FilePath file_path; | 92 base::FilePath file_path; |
| 89 | 93 |
| 90 CacheItemInfo(const std::string& version, | 94 CacheItemInfo(const std::string& version, |
| 91 const base::Time& last_used, | 95 const base::Time& last_used, |
| 92 const size_t size, | 96 const uint64 size, |
| 93 const base::FilePath& file_path); | 97 const base::FilePath& file_path); |
| 94 }; | 98 }; |
| 95 typedef std::map<std::string, CacheItemInfo> CacheMap; | 99 typedef std::map<std::string, CacheItemInfo> CacheMap; |
| 96 | 100 |
| 97 enum State { | 101 enum State { |
| 98 kUninitialized, | 102 kUninitialized, |
| 99 kWaitInitialization, | 103 kWaitInitialization, |
| 100 kReady, | 104 kReady, |
| 101 kShutdown | 105 kShutdown |
| 102 }; | 106 }; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 static bool CompareCacheItemsAge(const CacheMap::iterator& lhs, | 172 static bool CompareCacheItemsAge(const CacheMap::iterator& lhs, |
| 169 const CacheMap::iterator& rhs); | 173 const CacheMap::iterator& rhs); |
| 170 | 174 |
| 171 // Calculate which files need to be deleted and schedule files deletion. | 175 // Calculate which files need to be deleted and schedule files deletion. |
| 172 void CleanUp(); | 176 void CleanUp(); |
| 173 | 177 |
| 174 // Path to the directory where the extension cache is stored. | 178 // Path to the directory where the extension cache is stored. |
| 175 base::FilePath cache_dir_; | 179 base::FilePath cache_dir_; |
| 176 | 180 |
| 177 // Maximum size of cache dir on disk. | 181 // Maximum size of cache dir on disk. |
| 178 size_t max_cache_size_; | 182 uint64 max_cache_size_; |
| 179 | 183 |
| 180 // Minimal age of unused item in cache, items prior to this age will be | 184 // Minimal age of unused item in cache, items prior to this age will be |
| 181 // deleted on shutdown. | 185 // deleted on shutdown. |
| 182 base::Time min_cache_age_; | 186 base::Time min_cache_age_; |
| 183 | 187 |
| 184 // Task runner for executing file I/O tasks. | 188 // Task runner for executing file I/O tasks. |
| 185 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; | 189 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
| 186 | 190 |
| 187 // Track state of the instance. | 191 // Track state of the instance. |
| 188 State state_; | 192 State state_; |
| 189 | 193 |
| 190 // This contains info about all cached extensions. | 194 // This contains info about all cached extensions. |
| 191 CacheMap cached_extensions_; | 195 CacheMap cached_extensions_; |
| 192 | 196 |
| 193 // Weak factory for callbacks from the backend and delayed tasks. | 197 // Weak factory for callbacks from the backend and delayed tasks. |
| 194 base::WeakPtrFactory<LocalExtensionCache> weak_ptr_factory_; | 198 base::WeakPtrFactory<LocalExtensionCache> weak_ptr_factory_; |
| 195 | 199 |
| 196 // Delay between polling cache status. | 200 // Delay between polling cache status. |
| 197 base::TimeDelta cache_status_polling_delay_; | 201 base::TimeDelta cache_status_polling_delay_; |
| 198 | 202 |
| 199 DISALLOW_COPY_AND_ASSIGN(LocalExtensionCache); | 203 DISALLOW_COPY_AND_ASSIGN(LocalExtensionCache); |
| 200 }; | 204 }; |
| 201 | 205 |
| 202 } // namespace extensions | 206 } // namespace extensions |
| 203 | 207 |
| 204 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ | 208 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ |
| OLD | NEW |