| 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 EXTENSIONS_BROWSER_STATE_STORE_H_ | 5 #ifndef EXTENSIONS_BROWSER_STATE_STORE_H_ |
| 6 #define EXTENSIONS_BROWSER_STATE_STORE_H_ | 6 #define EXTENSIONS_BROWSER_STATE_STORE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 public: | 32 public: |
| 33 typedef ValueStoreFrontend::ReadCallback ReadCallback; | 33 typedef ValueStoreFrontend::ReadCallback ReadCallback; |
| 34 | 34 |
| 35 // If |deferred_load| is true, we won't load the database until the first | 35 // If |deferred_load| is true, we won't load the database until the first |
| 36 // page has been loaded. | 36 // page has been loaded. |
| 37 StateStore(content::BrowserContext* context, | 37 StateStore(content::BrowserContext* context, |
| 38 const scoped_refptr<ValueStoreFactory>& store_factory, | 38 const scoped_refptr<ValueStoreFactory>& store_factory, |
| 39 ValueStoreFrontend::BackendType backend_type, | 39 ValueStoreFrontend::BackendType backend_type, |
| 40 bool deferred_load); | 40 bool deferred_load); |
| 41 // This variant is useful for testing (using a mock ValueStore). | 41 // This variant is useful for testing (using a mock ValueStore). |
| 42 StateStore(content::BrowserContext* context, scoped_ptr<ValueStore> store); | 42 StateStore(content::BrowserContext* context, |
| 43 std::unique_ptr<ValueStore> store); |
| 43 ~StateStore() override; | 44 ~StateStore() override; |
| 44 | 45 |
| 45 // Requests that the state store to be initialized after its usual delay. Can | 46 // Requests that the state store to be initialized after its usual delay. Can |
| 46 // be explicitly called by an embedder when the embedder does not trigger the | 47 // be explicitly called by an embedder when the embedder does not trigger the |
| 47 // usual page load notifications. | 48 // usual page load notifications. |
| 48 void RequestInitAfterDelay(); | 49 void RequestInitAfterDelay(); |
| 49 | 50 |
| 50 // Register a key for removal upon extension install/uninstall. We remove | 51 // Register a key for removal upon extension install/uninstall. We remove |
| 51 // for install to reset state when an extension upgrades. | 52 // for install to reset state when an extension upgrades. |
| 52 void RegisterKey(const std::string& key); | 53 void RegisterKey(const std::string& key); |
| 53 | 54 |
| 54 // Get the value associated with the given extension and key, and pass | 55 // Get the value associated with the given extension and key, and pass |
| 55 // it to |callback| asynchronously. | 56 // it to |callback| asynchronously. |
| 56 void GetExtensionValue(const std::string& extension_id, | 57 void GetExtensionValue(const std::string& extension_id, |
| 57 const std::string& key, | 58 const std::string& key, |
| 58 ReadCallback callback); | 59 ReadCallback callback); |
| 59 | 60 |
| 60 // Sets a value for a given extension and key. | 61 // Sets a value for a given extension and key. |
| 61 void SetExtensionValue(const std::string& extension_id, | 62 void SetExtensionValue(const std::string& extension_id, |
| 62 const std::string& key, | 63 const std::string& key, |
| 63 scoped_ptr<base::Value> value); | 64 std::unique_ptr<base::Value> value); |
| 64 | 65 |
| 65 // Removes a value for a given extension and key. | 66 // Removes a value for a given extension and key. |
| 66 void RemoveExtensionValue(const std::string& extension_id, | 67 void RemoveExtensionValue(const std::string& extension_id, |
| 67 const std::string& key); | 68 const std::string& key); |
| 68 | 69 |
| 69 // Return whether or not the StateStore has initialized itself. | 70 // Return whether or not the StateStore has initialized itself. |
| 70 bool IsInitialized() const; | 71 bool IsInitialized() const; |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 class DelayedTaskQueue; | 74 class DelayedTaskQueue; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 // ExtensionRegistryObserver implementation. | 90 // ExtensionRegistryObserver implementation. |
| 90 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 91 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 91 const Extension* extension, | 92 const Extension* extension, |
| 92 extensions::UninstallReason reason) override; | 93 extensions::UninstallReason reason) override; |
| 93 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | 94 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 94 const Extension* extension, | 95 const Extension* extension, |
| 95 bool is_update, | 96 bool is_update, |
| 96 const std::string& old_name) override; | 97 const std::string& old_name) override; |
| 97 | 98 |
| 98 // The store that holds our key/values. | 99 // The store that holds our key/values. |
| 99 scoped_ptr<ValueStoreFrontend> store_; | 100 std::unique_ptr<ValueStoreFrontend> store_; |
| 100 | 101 |
| 101 // List of all known keys. They will be cleared for each extension when it is | 102 // List of all known keys. They will be cleared for each extension when it is |
| 102 // (un)installed. | 103 // (un)installed. |
| 103 std::set<std::string> registered_keys_; | 104 std::set<std::string> registered_keys_; |
| 104 | 105 |
| 105 // Keeps track of tasks we have delayed while starting up. | 106 // Keeps track of tasks we have delayed while starting up. |
| 106 scoped_ptr<DelayedTaskQueue> task_queue_; | 107 std::unique_ptr<DelayedTaskQueue> task_queue_; |
| 107 | 108 |
| 108 content::NotificationRegistrar registrar_; | 109 content::NotificationRegistrar registrar_; |
| 109 | 110 |
| 110 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 111 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 111 extension_registry_observer_; | 112 extension_registry_observer_; |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 } // namespace extensions | 115 } // namespace extensions |
| 115 | 116 |
| 116 #endif // EXTENSIONS_BROWSER_STATE_STORE_H_ | 117 #endif // EXTENSIONS_BROWSER_STATE_STORE_H_ |
| OLD | NEW |