[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 1 | // Copyright (c) 2013 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_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |
| 7 | |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 8 | #include <memory> |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 9 | #include <string> |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 10 | #include <vector> |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 11 | |
[email protected] | 8016d09 | 2013-10-01 09:21:31 | [diff] [blame] | 12 | #include "base/callback_forward.h" |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | class DictionaryValue; |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 17 | class FilePath; |
| 18 | class Value; |
Jay Civelli | 52054ad2 | 2017-12-01 02:15:42 | [diff] [blame] | 19 | } |
| 20 | |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 21 | namespace chromeos { |
| 22 | |
[email protected] | 8016d09 | 2013-10-01 09:21:31 | [diff] [blame] | 23 | // The ExternalCache manages a cache for external extensions. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 24 | class ExternalCache { |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 25 | public: |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 26 | using PutExternalExtensionCallback = |
| 27 | base::OnceCallback<void(const std::string& id, bool success)>; |
jennyz | ce634e9 | 2014-08-30 02:07:36 | [diff] [blame] | 28 | |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 29 | virtual ~ExternalCache() = default; |
[email protected] | 170d1d1 | 2013-10-30 03:32:19 | [diff] [blame] | 30 | |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 31 | // If an external extension should be downloaded, returns the extension's |
| 32 | // update URL. Otherwise, returns an empty URL. |
| 33 | static GURL GetExtensionUpdateUrl(const base::Value& extension_value, |
| 34 | bool always_checking_for_updates); |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 35 | |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 36 | // Converts an external extension value to the external extension value |
| 37 | // describing a cached extension - i.e. a value describing an extension |
| 38 | // returned by GetCachedExtensions(). |
| 39 | static base::Value GetExtensionValueToCache(const base::Value& original_value, |
| 40 | const std::string& path, |
| 41 | const std::string& version); |
| 42 | |
| 43 | // If the external extension is not curently cached, whether the extension's |
| 44 | // value should be added to the set of cached extensions (returned by |
| 45 | // GetCachedExtensions()) regardles of the extension's download status. |
Alexander Hendrich | efaef8a | 2020-08-28 08:51:58 | [diff] [blame] | 46 | static bool ShouldCacheImmediately(const base::Value& extension_value); |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 47 | |
[email protected] | eb35d5b | 2013-07-31 07:05:52 | [diff] [blame] | 48 | // Returns already cached extensions. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 49 | virtual const base::DictionaryValue* GetCachedExtensions() = 0; |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 50 | |
[email protected] | 8290b5d | 2013-10-09 02:51:30 | [diff] [blame] | 51 | // Shut down the cache. The |callback| will be invoked when the cache has shut |
| 52 | // down completely and there are no more pending file I/O operations. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 53 | virtual void Shutdown(base::OnceClosure callback) = 0; |
[email protected] | 8290b5d | 2013-10-09 02:51:30 | [diff] [blame] | 54 | |
| 55 | // Replace the list of extensions to cache with |prefs| and perform update |
| 56 | // checks for these. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 57 | virtual void UpdateExtensionsList( |
| 58 | std::unique_ptr<base::DictionaryValue> prefs) = 0; |
[email protected] | 8290b5d | 2013-10-09 02:51:30 | [diff] [blame] | 59 | |
| 60 | // If a user of one of the ExternalCache's extensions detects that |
| 61 | // the extension is damaged then this method can be used to remove it from |
| 62 | // the cache and retry to download it after a restart. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 63 | virtual void OnDamagedFileDetected(const base::FilePath& path) = 0; |
[email protected] | 8290b5d | 2013-10-09 02:51:30 | [diff] [blame] | 64 | |
[email protected] | c5319cd | 2014-05-03 00:25:55 | [diff] [blame] | 65 | // Removes extensions listed in |ids| from external cache, corresponding crx |
| 66 | // files will be removed from disk too. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 67 | virtual void RemoveExtensions(const std::vector<std::string>& ids) = 0; |
[email protected] | c5319cd | 2014-05-03 00:25:55 | [diff] [blame] | 68 | |
[email protected] | 5b80944 | 2014-05-14 00:13:18 | [diff] [blame] | 69 | // If extension with |id| exists in the cache, returns |true|, |file_path| and |
| 70 | // |version| for the extension. Extension will be marked as used with current |
| 71 | // timestamp. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 72 | virtual bool GetExtension(const std::string& id, |
| 73 | base::FilePath* file_path, |
| 74 | std::string* version) = 0; |
| 75 | |
| 76 | // Whether the extension with the provided id is currently being cached - |
| 77 | // i.e. whether the extension have been added to the external cache, but it's |
| 78 | // data has not yet been fetched, and thus is not available using |
| 79 | // GetExtension(). |
| 80 | virtual bool ExtensionFetchPending(const std::string& id) = 0; |
[email protected] | 5b80944 | 2014-05-14 00:13:18 | [diff] [blame] | 81 | |
jennyz | ce634e9 | 2014-08-30 02:07:36 | [diff] [blame] | 82 | // Puts the external |crx_file_path| into |local_cache_| for extension with |
| 83 | // |id|. |
Toni Barzic | 1256163 | 2018-01-02 20:15:38 | [diff] [blame] | 84 | virtual void PutExternalExtension(const std::string& id, |
| 85 | const base::FilePath& crx_file_path, |
| 86 | const std::string& version, |
| 87 | PutExternalExtensionCallback callback) = 0; |
[email protected] | a456773 | 2013-07-25 21:01:20 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace chromeos |
| 91 | |
| 92 | #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_ |