OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_STATE_STORE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/scoped_observer.h" | |
13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 #include "extensions/browser/extension_registry_observer.h" | |
15 #include "extensions/browser/value_store/value_store_frontend.h" | 17 #include "extensions/browser/value_store/value_store_frontend.h" |
16 | 18 |
17 class Profile; | 19 class Profile; |
18 | 20 |
19 namespace extensions { | 21 namespace extensions { |
20 | 22 |
23 class ExtensionRegistry; | |
24 | |
21 // A storage area for per-extension state that needs to be persisted to disk. | 25 // A storage area for per-extension state that needs to be persisted to disk. |
22 class StateStore | 26 class StateStore |
23 : public base::SupportsWeakPtr<StateStore>, | 27 : public base::SupportsWeakPtr<StateStore>, |
28 public ExtensionRegistryObserver, | |
24 public content::NotificationObserver { | 29 public content::NotificationObserver { |
25 public: | 30 public: |
26 typedef ValueStoreFrontend::ReadCallback ReadCallback; | 31 typedef ValueStoreFrontend::ReadCallback ReadCallback; |
27 | 32 |
28 // If |deferred_load| is true, we won't load the database until the first | 33 // If |deferred_load| is true, we won't load the database until the first |
29 // page has been loaded. | 34 // page has been loaded. |
30 StateStore(Profile* profile, const base::FilePath& db_path, | 35 StateStore(Profile* profile, const base::FilePath& db_path, |
31 bool deferred_load); | 36 bool deferred_load); |
32 // This variant is useful for testing (using a mock ValueStore). | 37 // This variant is useful for testing (using a mock ValueStore). |
33 StateStore(Profile* profile, scoped_ptr<ValueStore> store); | 38 StateStore(Profile* profile, scoped_ptr<ValueStore> store); |
(...skipping 27 matching lines...) Expand all Loading... | |
61 // content::NotificationObserver | 66 // content::NotificationObserver |
62 virtual void Observe(int type, | 67 virtual void Observe(int type, |
63 const content::NotificationSource& source, | 68 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) OVERRIDE; | 69 const content::NotificationDetails& details) OVERRIDE; |
65 | 70 |
66 void Init(); | 71 void Init(); |
67 | 72 |
68 // Removes all keys registered for the given extension. | 73 // Removes all keys registered for the given extension. |
69 void RemoveKeysForExtension(const std::string& extension_id); | 74 void RemoveKeysForExtension(const std::string& extension_id); |
70 | 75 |
76 // ExtensionRegistryObserver implementation. | |
77 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, | |
78 const Extension* extension) OVERRIDE; | |
79 | |
limasdf
2014/06/08 07:01:35
remove this empty line
| |
80 virtual void OnExtensionWillBeInstalled( | |
81 content::BrowserContext* browser_context, | |
82 const Extension* extension, | |
83 bool is_update, | |
84 bool from_ephemeral, | |
85 const std::string& old_name) OVERRIDE; | |
86 | |
71 // Path to our database, on disk. Empty during testing. | 87 // Path to our database, on disk. Empty during testing. |
72 base::FilePath db_path_; | 88 base::FilePath db_path_; |
73 | 89 |
74 // The store that holds our key/values. | 90 // The store that holds our key/values. |
75 ValueStoreFrontend store_; | 91 ValueStoreFrontend store_; |
76 | 92 |
77 // List of all known keys. They will be cleared for each extension when it is | 93 // List of all known keys. They will be cleared for each extension when it is |
78 // (un)installed. | 94 // (un)installed. |
79 std::set<std::string> registered_keys_; | 95 std::set<std::string> registered_keys_; |
80 | 96 |
81 // Keeps track of tasks we have delayed while starting up. | 97 // Keeps track of tasks we have delayed while starting up. |
82 scoped_ptr<DelayedTaskQueue> task_queue_; | 98 scoped_ptr<DelayedTaskQueue> task_queue_; |
83 | 99 |
84 content::NotificationRegistrar registrar_; | 100 content::NotificationRegistrar registrar_; |
101 | |
102 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | |
103 extension_registry_observer_; | |
85 }; | 104 }; |
86 | 105 |
87 } // namespace extensions | 106 } // namespace extensions |
88 | 107 |
89 #endif // CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
OLD | NEW |