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