OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/value_store/value_store_frontend.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 // A storage area for per-extension state that needs to be persisted to disk. |
| 22 class StateStore |
| 23 : public base::SupportsWeakPtr<StateStore>, |
| 24 public content::NotificationObserver { |
| 25 public: |
| 26 typedef ValueStoreFrontend::ReadCallback ReadCallback; |
| 27 |
| 28 StateStore(Profile* profile, const FilePath& db_path); |
| 29 virtual ~StateStore(); |
| 30 |
| 31 // Register a key for removal upon extension install/uninstall. We remove |
| 32 // for install to reset state when an extension upgrades. |
| 33 void RegisterKey(const std::string& key); |
| 34 |
| 35 // Get the value associated with the given extension and key, and pass |
| 36 // it to |callback| asynchronously. |
| 37 void GetExtensionValue(const std::string& extension_id, |
| 38 const std::string& key, |
| 39 ReadCallback callback); |
| 40 |
| 41 // Sets a value for a given extension and key. |
| 42 void SetExtensionValue(const std::string& extension_id, |
| 43 const std::string& key, |
| 44 scoped_ptr<base::Value> value); |
| 45 |
| 46 private: |
| 47 // content::NotificationObserver |
| 48 virtual void Observe(int type, |
| 49 const content::NotificationSource& source, |
| 50 const content::NotificationDetails& details) OVERRIDE; |
| 51 |
| 52 // The store that holds our key/values. |
| 53 ValueStoreFrontend store_; |
| 54 |
| 55 // List of all known keys. They will be cleared for each extension when it is |
| 56 // (un)installed. |
| 57 std::set<std::string> registered_keys_; |
| 58 |
| 59 content::NotificationRegistrar registrar_; |
| 60 }; |
| 61 |
| 62 } // namespace extensions |
| 63 |
| 64 #endif // CHROME_BROWSER_EXTENSIONS_STATE_STORE_H_ |
OLD | NEW |