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 EXTENSIONS_BROWSER_UPDATER_EXTENSION_CACHE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_ |
6 #define EXTENSIONS_BROWSER_UPDATER_EXTENSION_CACHE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 // ExtensionCache interface that caches extensions .crx files to share them | 15 // ExtensionCache interface that caches extensions .crx files to share them |
16 // between multiple users and profiles on the machine. | 16 // between multiple users and profiles on the machine. |
17 class ExtensionCache { | 17 class ExtensionCache { |
18 public: | 18 public: |
| 19 // Return global singleton instance of ExtensionCache. |
| 20 static ExtensionCache* GetInstance(); |
| 21 |
19 // Callback that is invoked when the file placed when PutExtension done. | 22 // Callback that is invoked when the file placed when PutExtension done. |
20 typedef base::Callback<void(const base::FilePath& file_path, | 23 typedef base::Callback<void(const base::FilePath& file_path, |
21 bool file_ownership_passed)> PutExtensionCallback; | 24 bool file_ownership_passed)> PutExtensionCallback; |
22 | 25 |
23 ExtensionCache() {} | |
24 virtual ~ExtensionCache() {} | |
25 | |
26 // Initialize cache in background. The |callback| is called when cache ready. | 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 | 27 // Can be called multiple times. The |callback| can be called immediately if |
28 // cache is ready. | 28 // cache is ready. |
29 virtual void Start(const base::Closure& callback) = 0; | 29 virtual void Start(const base::Closure& callback) = 0; |
30 | 30 |
31 // Shut down the cache. Must be called at most once on browser shutdown. | 31 // Shut down the cache. Must be called at most once on browser shutdown. |
32 virtual void Shutdown(const base::Closure& callback) = 0; | 32 virtual void Shutdown(const base::Closure& callback) = 0; |
33 | 33 |
34 // Allow caching for the extension with given |id|. User specific extensions | 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 | 35 // should not be cached for privacy reasons. But default apps including policy |
(...skipping 11 matching lines...) Expand all Loading... |
47 // the cache will removed be on next run so it can be safely used. Extension | 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 | 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 | 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 | 50 // deleted from the disk. There is no guarantee that |callback| will be |
51 // called. | 51 // called. |
52 virtual void PutExtension(const std::string& id, | 52 virtual void PutExtension(const std::string& id, |
53 const base::FilePath& file_path, | 53 const base::FilePath& file_path, |
54 const std::string& version, | 54 const std::string& version, |
55 const PutExtensionCallback& callback) = 0; | 55 const PutExtensionCallback& callback) = 0; |
56 | 56 |
57 private: | 57 protected: |
58 DISALLOW_COPY_AND_ASSIGN(ExtensionCache); | 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); |
59 }; | 63 }; |
60 | 64 |
61 } // namespace extensions | 65 } // namespace extensions |
62 | 66 |
63 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_CACHE_H_ | 67 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_ |
OLD | NEW |