blob: b7aeca2bbd222da938d035accf31214bfd689f09 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_STORE_IMPL_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_STORE_IMPL_H_
#include <map>
#include <memory>
#include <string>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/sequence_checker.h"
#include "base/strings/string_piece.h"
#include "components/data_reduction_proxy/core/browser/data_store.h"
namespace leveldb {
class DB;
}
namespace data_reduction_proxy {
// Implementation of |DataStore| using LevelDB.
class DataStoreImpl : public DataStore {
public:
explicit DataStoreImpl(const base::FilePath& profile_path);
~DataStoreImpl() override;
// Overrides of DataStore.
void InitializeOnDBThread() override;
Status Get(base::StringPiece key, std::string* value) override;
Status Put(const std::map<std::string, std::string>& map) override;
Status Delete(base::StringPiece key) override;
private:
// Opens the underlying LevelDB for read and write.
Status OpenDB();
// Deletes the LevelDB and recreates it. This method is called if any DB call
// returns a |CORRUPTED| status.
void RecreateDB();
// The underlying LevelDB used by this implementation.
std::unique_ptr<leveldb::DB> db_;
// Path to the profile using this store.
const base::FilePath profile_path_;
base::SequenceChecker sequence_checker_;
DISALLOW_COPY_AND_ASSIGN(DataStoreImpl);
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_STORE_IMPL_H_
|