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 20 matching lines...) Expand all Loading... |
31 public: | 31 public: |
32 typedef ValueStoreFrontend::ReadCallback ReadCallback; | 32 typedef ValueStoreFrontend::ReadCallback ReadCallback; |
33 | 33 |
34 // If |deferred_load| is true, we won't load the database until the first | 34 // If |deferred_load| is true, we won't load the database until the first |
35 // page has been loaded. | 35 // page has been loaded. |
36 StateStore(content::BrowserContext* context, | 36 StateStore(content::BrowserContext* context, |
37 const base::FilePath& db_path, | 37 const base::FilePath& db_path, |
38 bool deferred_load); | 38 bool deferred_load); |
39 // This variant is useful for testing (using a mock ValueStore). | 39 // This variant is useful for testing (using a mock ValueStore). |
40 StateStore(content::BrowserContext* context, scoped_ptr<ValueStore> store); | 40 StateStore(content::BrowserContext* context, scoped_ptr<ValueStore> store); |
41 virtual ~StateStore(); | 41 ~StateStore() override; |
42 | 42 |
43 // Requests that the state store to be initialized after its usual delay. Can | 43 // Requests that the state store to be initialized after its usual delay. Can |
44 // be explicitly called by an embedder when the embedder does not trigger the | 44 // be explicitly called by an embedder when the embedder does not trigger the |
45 // usual page load notifications. | 45 // usual page load notifications. |
46 void RequestInitAfterDelay(); | 46 void RequestInitAfterDelay(); |
47 | 47 |
48 // Register a key for removal upon extension install/uninstall. We remove | 48 // Register a key for removal upon extension install/uninstall. We remove |
49 // for install to reset state when an extension upgrades. | 49 // for install to reset state when an extension upgrades. |
50 void RegisterKey(const std::string& key); | 50 void RegisterKey(const std::string& key); |
51 | 51 |
(...skipping 12 matching lines...) Expand all Loading... |
64 void RemoveExtensionValue(const std::string& extension_id, | 64 void RemoveExtensionValue(const std::string& extension_id, |
65 const std::string& key); | 65 const std::string& key); |
66 | 66 |
67 // Return whether or not the StateStore has initialized itself. | 67 // Return whether or not the StateStore has initialized itself. |
68 bool IsInitialized() const; | 68 bool IsInitialized() const; |
69 | 69 |
70 private: | 70 private: |
71 class DelayedTaskQueue; | 71 class DelayedTaskQueue; |
72 | 72 |
73 // content::NotificationObserver | 73 // content::NotificationObserver |
74 virtual void Observe(int type, | 74 void Observe(int type, |
75 const content::NotificationSource& source, | 75 const content::NotificationSource& source, |
76 const content::NotificationDetails& details) override; | 76 const content::NotificationDetails& details) override; |
77 | 77 |
78 void Init(); | 78 void Init(); |
79 | 79 |
80 // When StateStore is constructed with |deferred_load| its initialization is | 80 // When StateStore is constructed with |deferred_load| its initialization is |
81 // delayed to avoid slowing down startup. | 81 // delayed to avoid slowing down startup. |
82 void InitAfterDelay(); | 82 void InitAfterDelay(); |
83 | 83 |
84 // Removes all keys registered for the given extension. | 84 // Removes all keys registered for the given extension. |
85 void RemoveKeysForExtension(const std::string& extension_id); | 85 void RemoveKeysForExtension(const std::string& extension_id); |
86 | 86 |
87 // ExtensionRegistryObserver implementation. | 87 // ExtensionRegistryObserver implementation. |
88 virtual void OnExtensionUninstalled( | 88 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
89 content::BrowserContext* browser_context, | 89 const Extension* extension, |
90 const Extension* extension, | 90 extensions::UninstallReason reason) override; |
91 extensions::UninstallReason reason) override; | 91 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
92 virtual void OnExtensionWillBeInstalled( | 92 const Extension* extension, |
93 content::BrowserContext* browser_context, | 93 bool is_update, |
94 const Extension* extension, | 94 bool from_ephemeral, |
95 bool is_update, | 95 const std::string& old_name) override; |
96 bool from_ephemeral, | |
97 const std::string& old_name) override; | |
98 | 96 |
99 // Path to our database, on disk. Empty during testing. | 97 // Path to our database, on disk. Empty during testing. |
100 base::FilePath db_path_; | 98 base::FilePath db_path_; |
101 | 99 |
102 // The store that holds our key/values. | 100 // The store that holds our key/values. |
103 ValueStoreFrontend store_; | 101 ValueStoreFrontend store_; |
104 | 102 |
105 // List of all known keys. They will be cleared for each extension when it is | 103 // List of all known keys. They will be cleared for each extension when it is |
106 // (un)installed. | 104 // (un)installed. |
107 std::set<std::string> registered_keys_; | 105 std::set<std::string> registered_keys_; |
108 | 106 |
109 // Keeps track of tasks we have delayed while starting up. | 107 // Keeps track of tasks we have delayed while starting up. |
110 scoped_ptr<DelayedTaskQueue> task_queue_; | 108 scoped_ptr<DelayedTaskQueue> task_queue_; |
111 | 109 |
112 content::NotificationRegistrar registrar_; | 110 content::NotificationRegistrar registrar_; |
113 | 111 |
114 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 112 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
115 extension_registry_observer_; | 113 extension_registry_observer_; |
116 }; | 114 }; |
117 | 115 |
118 } // namespace extensions | 116 } // namespace extensions |
119 | 117 |
120 #endif // EXTENSIONS_BROWSER_STATE_STORE_H_ | 118 #endif // EXTENSIONS_BROWSER_STATE_STORE_H_ |
OLD | NEW |