| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback_forward.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 | |
| 13 namespace extensions { | |
| 14 | |
| 15 // ExtensionCache interface that caches extensions .crx files to share them | |
| 16 // between multiple users and profiles on the machine. | |
| 17 class ExtensionCache { | |
| 18 public: | |
| 19 // Return global singleton instance of ExtensionCache. | |
| 20 static ExtensionCache* GetInstance(); | |
| 21 | |
| 22 // Callback that is invoked when the file placed when PutExtension done. | |
| 23 typedef base::Callback<void(const base::FilePath& file_path, | |
| 24 bool file_ownership_passed)> PutExtensionCallback; | |
| 25 | |
| 26 // Initialize cache in background. The |callback| is called when cache ready. | |
| 27 // Can be called multiple times. The |callback| can be called immediately if | |
| 28 // cache is ready. | |
| 29 virtual void Start(const base::Closure& callback) = 0; | |
| 30 | |
| 31 // Shut down the cache. Must be called at most once on browser shutdown. | |
| 32 virtual void Shutdown(const base::Closure& callback) = 0; | |
| 33 | |
| 34 // Allow caching for the extension with given |id|. User specific extensions | |
| 35 // should not be cached for privacy reasons. But default apps including policy | |
| 36 // configured can be cached. Can be called before Init. | |
| 37 virtual void AllowCaching(const std::string& id) = 0; | |
| 38 | |
| 39 // If extension with |id| exists in the cache, returns |true|, |file_path| and | |
| 40 // |version| for the extension. Extension will be marked as used with current | |
| 41 // timestamp. | |
| 42 virtual bool GetExtension(const std::string& id, | |
| 43 base::FilePath* file_path, | |
| 44 std::string* version) = 0; | |
| 45 | |
| 46 // Put extension with |id| and |version| into local cache. Older version in | |
| 47 // the cache will removed be on next run so it can be safely used. Extension | |
| 48 // will be marked as used with current timestamp. The file will be available | |
| 49 // via GetExtension when |callback| is called. Original |file_path| won't be | |
| 50 // deleted from the disk. There is no guarantee that |callback| will be | |
| 51 // called. | |
| 52 virtual void PutExtension(const std::string& id, | |
| 53 const base::FilePath& file_path, | |
| 54 const std::string& version, | |
| 55 const PutExtensionCallback& callback) = 0; | |
| 56 | |
| 57 protected: | |
| 58 virtual ~ExtensionCache() {} | |
| 59 | |
| 60 // Sets the singleton to the given |cache|. Returns the previous value of | |
| 61 // the singleton. Ownership is not transferred. | |
| 62 static ExtensionCache* SetForTesting(ExtensionCache* cache); | |
| 63 }; | |
| 64 | |
| 65 } // namespace extensions | |
| 66 | |
| 67 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_ | |
| OLD | NEW |