NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / updater / extension_cache_impl.h
blob4c821c4288fce8380119cf2b37437423737c9120
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_IMPL_H_
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_IMPL_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/callback_forward.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/extensions/updater/extension_cache.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
20 template <typename T> struct DefaultSingletonTraits;
22 namespace extensions {
24 class LocalExtensionCache;
26 // Singleton call that caches extensions .crx files to share them between
27 // multiple users and profiles on the machine.
28 class ExtensionCacheImpl : public ExtensionCache,
29 public content::NotificationObserver {
30 public:
31 static ExtensionCacheImpl* GetInstance();
33 // Implementation of ExtensionCache.
34 virtual void Start(const base::Closure& callback) OVERRIDE;
35 virtual void Shutdown(const base::Closure& callback) OVERRIDE;
36 virtual void AllowCaching(const std::string& id) OVERRIDE;
37 virtual bool GetExtension(const std::string& id,
38 base::FilePath* file_path,
39 std::string* version) OVERRIDE;
40 virtual void PutExtension(const std::string& id,
41 const base::FilePath& file_path,
42 const std::string& version,
43 const PutExtensionCallback& callback) OVERRIDE;
45 // Implementation of content::NotificationObserver:
46 virtual void Observe(int type,
47 const content::NotificationSource& source,
48 const content::NotificationDetails& details) OVERRIDE;
50 private:
51 friend struct DefaultSingletonTraits<ExtensionCacheImpl>;
53 ExtensionCacheImpl();
54 virtual ~ExtensionCacheImpl();
56 // Callback that is called when local cache is ready.
57 void OnCacheInitialized();
59 // Weak factory for callbacks.
60 base::WeakPtrFactory<ExtensionCacheImpl> weak_ptr_factory_;
62 // Cache implementation that uses local cache dir.
63 scoped_ptr<LocalExtensionCache> cache_;
65 // Set of extensions that can be cached.
66 std::set<std::string> allowed_extensions_;
68 // List of callbacks that should be called when the cache is ready.
69 std::vector<base::Closure> init_callbacks_;
71 // Observes failures to install CRX files.
72 content::NotificationRegistrar notification_registrar_;
74 DISALLOW_COPY_AND_ASSIGN(ExtensionCacheImpl);
77 } // namespace extensions
79 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_CACHE_IMPL_H_