blob: 6bdf251ecf3412f81be79528c4ec66b293f657dd [file] [log] [blame]
Christopher Wiley006e94e2014-05-02 13:44:48 -07001// Copyright 2014 The Chromium OS 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.
4
5#ifndef BUFFET_STORAGE_IMPLS_H_
6#define BUFFET_STORAGE_IMPLS_H_
7
Ben Chan15260972014-09-05 08:21:06 -07008#include <base/files/file_util.h>
Alex Vakulenko132617a2014-09-04 08:59:43 -07009#include <base/macros.h>
Christopher Wiley006e94e2014-05-02 13:44:48 -070010#include <base/values.h>
11
12#include "buffet/storage_interface.h"
13
14namespace buffet {
15
16// Persists the given Value to an atomically written file.
17class FileStorage : public StorageInterface {
18 public:
Alex Vakulenko33797062014-05-12 15:55:25 -070019 explicit FileStorage(const base::FilePath& file_path);
Alex Vakulenko534a3122015-05-22 15:48:53 -070020 ~FileStorage() override = default;
Vitaly Buka207c1cb2015-05-14 17:06:18 -070021 std::unique_ptr<base::DictionaryValue> Load() override;
22 bool Save(const base::DictionaryValue& config) override;
Christopher Wiley006e94e2014-05-02 13:44:48 -070023
24 private:
25 base::FilePath file_path_;
26 DISALLOW_COPY_AND_ASSIGN(FileStorage);
27};
28
29// StorageInterface for testing. Just stores the values in memory.
30class MemStorage : public StorageInterface {
31 public:
32 MemStorage() = default;
Alex Vakulenko534a3122015-05-22 15:48:53 -070033 ~MemStorage() override = default;
Vitaly Buka207c1cb2015-05-14 17:06:18 -070034 std::unique_ptr<base::DictionaryValue> Load() override;
35 bool Save(const base::DictionaryValue& config) override;
Christopher Wiley006e94e2014-05-02 13:44:48 -070036
37 private:
Vitaly Buka207c1cb2015-05-14 17:06:18 -070038 base::DictionaryValue cache_;
Christopher Wiley006e94e2014-05-02 13:44:48 -070039 DISALLOW_COPY_AND_ASSIGN(MemStorage);
40};
41
42} // namespace buffet
43
44#endif // BUFFET_STORAGE_IMPLS_H_