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