Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / value_store / value_store_frontend.h
blob223441e1ad17370f6ac4c71f82bd24e637ff2b0f
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.
5 #ifndef CHROME_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_
6 #define CHROME_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_
8 #include <string>
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 "chrome/browser/value_store/value_store.h"
18 namespace base {
19 class FilePath;
22 // A frontend for a LeveldbValueStore, for use on the UI thread.
23 class ValueStoreFrontend
24 : public base::SupportsWeakPtr<ValueStoreFrontend>,
25 public base::NonThreadSafe {
26 public:
27 typedef base::Callback<void(scoped_ptr<base::Value>)> ReadCallback;
29 ValueStoreFrontend();
30 explicit ValueStoreFrontend(const base::FilePath& db_path);
31 // This variant is useful for testing (using a mock ValueStore).
32 explicit ValueStoreFrontend(scoped_ptr<ValueStore> value_store);
33 ~ValueStoreFrontend();
35 void Init(const base::FilePath& db_path);
37 // Retrieves a value from the database asynchronously, passing a copy to
38 // |callback| when ready. NULL is passed if no matching entry is found.
39 void Get(const std::string& key, const ReadCallback& callback);
41 // Sets a value with the given key.
42 void Set(const std::string& key, scoped_ptr<base::Value> value);
44 // Removes the value with the given key.
45 void Remove(const std::string& key);
47 private:
48 class Backend;
50 // A helper class to manage lifetime of the backing ValueStore, which lives
51 // on the FILE thread.
52 scoped_refptr<Backend> backend_;
54 DISALLOW_COPY_AND_ASSIGN(ValueStoreFrontend);
57 #endif // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_FRONTEND_H_