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