blob: 24f2e5f817d817e02cba0c4322f0ec7852efd2c3 [file] [log] [blame]
[email protected]a4567732013-07-25 21:01:201// 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
dcheng24002d02016-04-08 02:42:408#include <memory>
[email protected]a4567732013-07-25 21:01:209#include <string>
Toni Barzic12561632018-01-02 20:15:3810#include <vector>
[email protected]a4567732013-07-25 21:01:2011
[email protected]8016d092013-10-01 09:21:3112#include "base/callback_forward.h"
Toni Barzic12561632018-01-02 20:15:3813#include "url/gurl.h"
[email protected]a4567732013-07-25 21:01:2014
15namespace base {
16class DictionaryValue;
Toni Barzic12561632018-01-02 20:15:3817class FilePath;
18class Value;
Jay Civelli52054ad22017-12-01 02:15:4219}
20
[email protected]a4567732013-07-25 21:01:2021namespace chromeos {
22
[email protected]8016d092013-10-01 09:21:3123// The ExternalCache manages a cache for external extensions.
Toni Barzic12561632018-01-02 20:15:3824class ExternalCache {
[email protected]a4567732013-07-25 21:01:2025 public:
Toni Barzic12561632018-01-02 20:15:3826 using PutExternalExtensionCallback =
27 base::OnceCallback<void(const std::string& id, bool success)>;
jennyzce634e92014-08-30 02:07:3628
Toni Barzic12561632018-01-02 20:15:3829 virtual ~ExternalCache() = default;
[email protected]170d1d12013-10-30 03:32:1930
Toni Barzic12561632018-01-02 20:15:3831 // 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]a4567732013-07-25 21:01:2035
Toni Barzic12561632018-01-02 20:15:3836 // 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 Hendrichefaef8a2020-08-28 08:51:5846 static bool ShouldCacheImmediately(const base::Value& extension_value);
[email protected]a4567732013-07-25 21:01:2047
[email protected]eb35d5b2013-07-31 07:05:5248 // Returns already cached extensions.
Toni Barzic12561632018-01-02 20:15:3849 virtual const base::DictionaryValue* GetCachedExtensions() = 0;
[email protected]a4567732013-07-25 21:01:2050
[email protected]8290b5d2013-10-09 02:51:3051 // 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 Barzic12561632018-01-02 20:15:3853 virtual void Shutdown(base::OnceClosure callback) = 0;
[email protected]8290b5d2013-10-09 02:51:3054
55 // Replace the list of extensions to cache with |prefs| and perform update
56 // checks for these.
Toni Barzic12561632018-01-02 20:15:3857 virtual void UpdateExtensionsList(
58 std::unique_ptr<base::DictionaryValue> prefs) = 0;
[email protected]8290b5d2013-10-09 02:51:3059
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 Barzic12561632018-01-02 20:15:3863 virtual void OnDamagedFileDetected(const base::FilePath& path) = 0;
[email protected]8290b5d2013-10-09 02:51:3064
[email protected]c5319cd2014-05-03 00:25:5565 // Removes extensions listed in |ids| from external cache, corresponding crx
66 // files will be removed from disk too.
Toni Barzic12561632018-01-02 20:15:3867 virtual void RemoveExtensions(const std::vector<std::string>& ids) = 0;
[email protected]c5319cd2014-05-03 00:25:5568
[email protected]5b809442014-05-14 00:13:1869 // 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 Barzic12561632018-01-02 20:15:3872 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]5b809442014-05-14 00:13:1881
jennyzce634e92014-08-30 02:07:3682 // Puts the external |crx_file_path| into |local_cache_| for extension with
83 // |id|.
Toni Barzic12561632018-01-02 20:15:3884 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]a4567732013-07-25 21:01:2088};
89
90} // namespace chromeos
91
92#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_EXTERNAL_CACHE_H_