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 <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.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/sequence_checker.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 extensions { | 19 namespace extensions { |
20 class ValueStoreFactory; | 20 class ValueStoreFactory; |
21 } // namespace extensions | 21 } // namespace extensions |
22 | 22 |
23 // A frontend for a LeveldbValueStore, for use on the UI thread. | 23 // A frontend for a LeveldbValueStore, for use on the UI thread. |
Devlin
2017/05/30 19:06:47
Since this is only designed to be used on the UI t
gab
2017/05/31 17:52:28
I don't see thread-affinity requirements in ValueS
| |
24 class ValueStoreFrontend | 24 class ValueStoreFrontend : public base::SupportsWeakPtr<ValueStoreFrontend> { |
25 : public base::SupportsWeakPtr<ValueStoreFrontend>, | |
26 public base::NonThreadSafe { | |
27 public: | 25 public: |
28 // The kind of extensions data stored in a backend. | 26 // The kind of extensions data stored in a backend. |
29 enum class BackendType { RULES, STATE }; | 27 enum class BackendType { RULES, STATE }; |
30 | 28 |
31 typedef base::Callback<void(std::unique_ptr<base::Value>)> ReadCallback; | 29 typedef base::Callback<void(std::unique_ptr<base::Value>)> ReadCallback; |
32 | 30 |
33 ValueStoreFrontend( | 31 ValueStoreFrontend( |
34 const scoped_refptr<extensions::ValueStoreFactory>& store_factory, | 32 const scoped_refptr<extensions::ValueStoreFactory>& store_factory, |
35 BackendType backend_type); | 33 BackendType backend_type); |
36 ~ValueStoreFrontend(); | 34 ~ValueStoreFrontend(); |
37 | 35 |
38 // Retrieves a value from the database asynchronously, passing a copy to | 36 // Retrieves a value from the database asynchronously, passing a copy to |
39 // |callback| when ready. NULL is passed if no matching entry is found. | 37 // |callback| when ready. NULL is passed if no matching entry is found. |
40 void Get(const std::string& key, const ReadCallback& callback); | 38 void Get(const std::string& key, const ReadCallback& callback); |
41 | 39 |
42 // Sets a value with the given key. | 40 // Sets a value with the given key. |
43 void Set(const std::string& key, std::unique_ptr<base::Value> value); | 41 void Set(const std::string& key, std::unique_ptr<base::Value> value); |
44 | 42 |
45 // Removes the value with the given key. | 43 // Removes the value with the given key. |
46 void Remove(const std::string& key); | 44 void Remove(const std::string& key); |
47 | 45 |
48 private: | 46 private: |
49 class Backend; | 47 class Backend; |
50 | 48 |
51 // A helper class to manage lifetime of the backing ValueStore, which lives | 49 // A helper class to manage lifetime of the backing ValueStore, which lives |
52 // on the FILE thread. | 50 // on the FILE thread. |
53 scoped_refptr<Backend> backend_; | 51 scoped_refptr<Backend> backend_; |
54 | 52 |
53 SEQUENCE_CHECKER(sequence_checker_); | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(ValueStoreFrontend); | 55 DISALLOW_COPY_AND_ASSIGN(ValueStoreFrontend); |
56 }; | 56 }; |
57 | 57 |
58 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ | 58 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_ |
OLD | NEW |