Chromium Code Reviews| 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 |
| 19 namespace content { | |
|
limasdf
2014/06/14 03:58:59
please make 'class Profile' come first..
class
Ted Kim
2014/06/14 05:13:53
Done.
| |
| 20 class BrowserContext; | |
| 21 } | |
| 22 | |
| 17 class Profile; | 23 class Profile; |
| 18 | 24 |
| 19 namespace extensions { | 25 namespace extensions { |
| 20 | 26 |
| 27 class ExtensionRegistry; | |
| 28 | |
| 21 // A storage area for per-extension state that needs to be persisted to disk. | 29 // A storage area for per-extension state that needs to be persisted to disk. |
| 22 class StateStore | 30 class StateStore |
| 23 : public base::SupportsWeakPtr<StateStore>, | 31 : public base::SupportsWeakPtr<StateStore>, |
| 32 public ExtensionRegistryObserver, | |
| 24 public content::NotificationObserver { | 33 public content::NotificationObserver { |
| 25 public: | 34 public: |
| 26 typedef ValueStoreFrontend::ReadCallback ReadCallback; | 35 typedef ValueStoreFrontend::ReadCallback ReadCallback; |
| 27 | 36 |
| 28 // If |deferred_load| is true, we won't load the database until the first | 37 // If |deferred_load| is true, we won't load the database until the first |
| 29 // page has been loaded. | 38 // page has been loaded. |
| 30 StateStore(Profile* profile, const base::FilePath& db_path, | 39 StateStore(Profile* profile, const base::FilePath& db_path, |
| 31 bool deferred_load); | 40 bool deferred_load); |
| 32 // This variant is useful for testing (using a mock ValueStore). | 41 // This variant is useful for testing (using a mock ValueStore). |
| 33 StateStore(Profile* profile, scoped_ptr<ValueStore> store); | 42 StateStore(Profile* profile, scoped_ptr<ValueStore> store); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 61 // content::NotificationObserver | 70 // content::NotificationObserver |
| 62 virtual void Observe(int type, | 71 virtual void Observe(int type, |
| 63 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
| 64 const content::NotificationDetails& details) OVERRIDE; | 73 const content::NotificationDetails& details) OVERRIDE; |
| 65 | 74 |
| 66 void Init(); | 75 void Init(); |
| 67 | 76 |
| 68 // Removes all keys registered for the given extension. | 77 // Removes all keys registered for the given extension. |
| 69 void RemoveKeysForExtension(const std::string& extension_id); | 78 void RemoveKeysForExtension(const std::string& extension_id); |
| 70 | 79 |
| 80 // ExtensionRegistryObserver implementation. | |
| 81 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, | |
| 82 const Extension* extension) OVERRIDE; | |
| 83 virtual void OnExtensionWillBeInstalled( | |
| 84 content::BrowserContext* browser_context, | |
| 85 const Extension* extension, | |
| 86 bool is_update, | |
| 87 bool from_ephemeral, | |
| 88 const std::string& old_name) OVERRIDE; | |
| 89 | |
| 71 // Path to our database, on disk. Empty during testing. | 90 // Path to our database, on disk. Empty during testing. |
| 72 base::FilePath db_path_; | 91 base::FilePath db_path_; |
| 73 | 92 |
| 74 // The store that holds our key/values. | 93 // The store that holds our key/values. |
| 75 ValueStoreFrontend store_; | 94 ValueStoreFrontend store_; |
| 76 | 95 |
| 77 // List of all known keys. They will be cleared for each extension when it is | 96 // List of all known keys. They will be cleared for each extension when it is |
| 78 // (un)installed. | 97 // (un)installed. |
| 79 std::set<std::string> registered_keys_; | 98 std::set<std::string> registered_keys_; |
| 80 | 99 |
| 81 // Keeps track of tasks we have delayed while starting up. | 100 // Keeps track of tasks we have delayed while starting up. |
| 82 scoped_ptr<DelayedTaskQueue> task_queue_; | 101 scoped_ptr<DelayedTaskQueue> task_queue_; |
| 83 | 102 |
| 84 content::NotificationRegistrar registrar_; | 103 content::NotificationRegistrar registrar_; |
| 104 | |
| 105 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | |
| 106 extension_registry_observer_; | |
| 85 }; | 107 }; |
| 86 | 108 |
| 87 } // namespace extensions | 109 } // namespace extensions |
| 88 | 110 |
| 89 #endif // CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ | 111 #endif // CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
| OLD | NEW |