NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / updater / extension_cache.h
blobedcc1fa3d3ec91f75993859578c0f9f6f8b11100
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h"
13 namespace extensions {
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();
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;
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;
31 // Shut down the cache. Must be called at most once on browser shutdown.
32 virtual void Shutdown(const base::Closure& callback) = 0;
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;
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;
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;
57 protected:
58 virtual ~ExtensionCache() {}
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);
65 } // namespace extensions
67 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_H_