Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: trunk/src/chrome/browser/extensions/updater/local_extension_cache.h

Issue 139173009: Revert 247760 "Add UMA stats for ExtensionCache" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 uint64 max_cache_size, 35 size_t 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
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
80 bool is_ready() const { return state_ == kReady; } 76 bool is_ready() const { return state_ == kReady; }
81 bool is_uninitialized() const { return state_ == kUninitialized; } 77 bool is_uninitialized() const { return state_ == kUninitialized; }
82 bool is_shutdown() const { return state_ == kShutdown; } 78 bool is_shutdown() const { return state_ == kShutdown; }
83 79
84 // For tests only! 80 // For tests only!
85 void SetCacheStatusPollingDelayForTests(const base::TimeDelta& delay); 81 void SetCacheStatusPollingDelayForTests(const base::TimeDelta& delay);
86 82
87 private: 83 private:
88 struct CacheItemInfo { 84 struct CacheItemInfo {
89 std::string version; 85 std::string version;
90 base::Time last_used; 86 base::Time last_used;
91 uint64 size; 87 int64 size;
92 base::FilePath file_path; 88 base::FilePath file_path;
93 89
94 CacheItemInfo(const std::string& version, 90 CacheItemInfo(const std::string& version,
95 const base::Time& last_used, 91 const base::Time& last_used,
96 const uint64 size, 92 const size_t size,
97 const base::FilePath& file_path); 93 const base::FilePath& file_path);
98 }; 94 };
99 typedef std::map<std::string, CacheItemInfo> CacheMap; 95 typedef std::map<std::string, CacheItemInfo> CacheMap;
100 96
101 enum State { 97 enum State {
102 kUninitialized, 98 kUninitialized,
103 kWaitInitialization, 99 kWaitInitialization,
104 kReady, 100 kReady,
105 kShutdown 101 kShutdown
106 }; 102 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 static bool CompareCacheItemsAge(const CacheMap::iterator& lhs, 168 static bool CompareCacheItemsAge(const CacheMap::iterator& lhs,
173 const CacheMap::iterator& rhs); 169 const CacheMap::iterator& rhs);
174 170
175 // Calculate which files need to be deleted and schedule files deletion. 171 // Calculate which files need to be deleted and schedule files deletion.
176 void CleanUp(); 172 void CleanUp();
177 173
178 // Path to the directory where the extension cache is stored. 174 // Path to the directory where the extension cache is stored.
179 base::FilePath cache_dir_; 175 base::FilePath cache_dir_;
180 176
181 // Maximum size of cache dir on disk. 177 // Maximum size of cache dir on disk.
182 uint64 max_cache_size_; 178 size_t max_cache_size_;
183 179
184 // Minimal age of unused item in cache, items prior to this age will be 180 // Minimal age of unused item in cache, items prior to this age will be
185 // deleted on shutdown. 181 // deleted on shutdown.
186 base::Time min_cache_age_; 182 base::Time min_cache_age_;
187 183
188 // Task runner for executing file I/O tasks. 184 // Task runner for executing file I/O tasks.
189 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; 185 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
190 186
191 // Track state of the instance. 187 // Track state of the instance.
192 State state_; 188 State state_;
193 189
194 // This contains info about all cached extensions. 190 // This contains info about all cached extensions.
195 CacheMap cached_extensions_; 191 CacheMap cached_extensions_;
196 192
197 // Weak factory for callbacks from the backend and delayed tasks. 193 // Weak factory for callbacks from the backend and delayed tasks.
198 base::WeakPtrFactory<LocalExtensionCache> weak_ptr_factory_; 194 base::WeakPtrFactory<LocalExtensionCache> weak_ptr_factory_;
199 195
200 // Delay between polling cache status. 196 // Delay between polling cache status.
201 base::TimeDelta cache_status_polling_delay_; 197 base::TimeDelta cache_status_polling_delay_;
202 198
203 DISALLOW_COPY_AND_ASSIGN(LocalExtensionCache); 199 DISALLOW_COPY_AND_ASSIGN(LocalExtensionCache);
204 }; 200 };
205 201
206 } // namespace extensions 202 } // namespace extensions
207 203
208 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_ 204 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_LOCAL_EXTENSION_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698