| 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_VALUE_STORE_VALUE_STORE_FRONTEND_H_ | 5 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ |
| 6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ | 6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "extensions/browser/value_store/value_store.h" | 17 #include "extensions/browser/value_store/value_store.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class FilePath; | 20 class FilePath; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 class ValueStoreFactory; | 24 class ValueStoreFactory; |
| 25 } // namespace extensions | 25 } // namespace extensions |
| 26 | 26 |
| 27 // A frontend for a LeveldbValueStore, for use on the UI thread. | 27 // A frontend for a LeveldbValueStore, for use on the UI thread. |
| 28 class ValueStoreFrontend | 28 class ValueStoreFrontend |
| 29 : public base::SupportsWeakPtr<ValueStoreFrontend>, | 29 : public base::SupportsWeakPtr<ValueStoreFrontend>, |
| 30 public base::NonThreadSafe { | 30 public base::NonThreadSafe { |
| 31 public: | 31 public: |
| 32 // The kind of extensions data stored in a backend. | 32 // The kind of extensions data stored in a backend. |
| 33 enum class BackendType { RULES, STATE }; | 33 enum class BackendType { RULES, STATE }; |
| 34 | 34 |
| 35 typedef base::Callback<void(scoped_ptr<base::Value>)> ReadCallback; | 35 typedef base::Callback<void(std::unique_ptr<base::Value>)> ReadCallback; |
| 36 | 36 |
| 37 ValueStoreFrontend( | 37 ValueStoreFrontend( |
| 38 const scoped_refptr<extensions::ValueStoreFactory>& store_factory, | 38 const scoped_refptr<extensions::ValueStoreFactory>& store_factory, |
| 39 BackendType backend_type); | 39 BackendType backend_type); |
| 40 ~ValueStoreFrontend(); | 40 ~ValueStoreFrontend(); |
| 41 | 41 |
| 42 // Retrieves a value from the database asynchronously, passing a copy to | 42 // Retrieves a value from the database asynchronously, passing a copy to |
| 43 // |callback| when ready. NULL is passed if no matching entry is found. | 43 // |callback| when ready. NULL is passed if no matching entry is found. |
| 44 void Get(const std::string& key, const ReadCallback& callback); | 44 void Get(const std::string& key, const ReadCallback& callback); |
| 45 | 45 |
| 46 // Sets a value with the given key. | 46 // Sets a value with the given key. |
| 47 void Set(const std::string& key, scoped_ptr<base::Value> value); | 47 void Set(const std::string& key, std::unique_ptr<base::Value> value); |
| 48 | 48 |
| 49 // Removes the value with the given key. | 49 // Removes the value with the given key. |
| 50 void Remove(const std::string& key); | 50 void Remove(const std::string& key); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 class Backend; | 53 class Backend; |
| 54 | 54 |
| 55 // A helper class to manage lifetime of the backing ValueStore, which lives | 55 // A helper class to manage lifetime of the backing ValueStore, which lives |
| 56 // on the FILE thread. | 56 // on the FILE thread. |
| 57 scoped_refptr<Backend> backend_; | 57 scoped_refptr<Backend> backend_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ValueStoreFrontend); | 59 DISALLOW_COPY_AND_ASSIGN(ValueStoreFrontend); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ | 62 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ |
| OLD | NEW |