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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_
6 #define EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/values.h"
16 #include "extensions/browser/value_store/value_store.h"
22 // A frontend for a LeveldbValueStore, for use on the UI thread.
23 class ValueStoreFrontend
24 : public base::SupportsWeakPtr
<ValueStoreFrontend
>,
25 public base::NonThreadSafe
{
27 typedef base::Callback
<void(scoped_ptr
<base::Value
>)> ReadCallback
;
30 ValueStoreFrontend(const std::string
& uma_client_name
,
31 const base::FilePath
& db_path
);
32 // This variant is useful for testing (using a mock ValueStore).
33 explicit ValueStoreFrontend(scoped_ptr
<ValueStore
> value_store
);
34 ~ValueStoreFrontend();
36 void Init(const std::string
& uma_client_name
, const base::FilePath
& db_path
);
38 // Retrieves a value from the database asynchronously, passing a copy to
39 // |callback| when ready. NULL is passed if no matching entry is found.
40 void Get(const std::string
& key
, const ReadCallback
& callback
);
42 // Sets a value with the given key.
43 void Set(const std::string
& key
, scoped_ptr
<base::Value
> value
);
45 // Removes the value with the given key.
46 void Remove(const std::string
& key
);
51 // A helper class to manage lifetime of the backing ValueStore, which lives
52 // on the FILE thread.
53 scoped_refptr
<Backend
> backend_
;
55 DISALLOW_COPY_AND_ASSIGN(ValueStoreFrontend
);
58 #endif // EXTENSIONS_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_