Christopher Wiley | 006e94e | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 1 | // 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 Chan | 1526097 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 8 | #include <base/files/file_util.h> |
Alex Vakulenko | 132617a | 2014-09-04 08:59:43 -0700 | [diff] [blame] | 9 | #include <base/macros.h> |
Christopher Wiley | 006e94e | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 10 | #include <base/values.h> |
| 11 | |
| 12 | #include "buffet/storage_interface.h" |
| 13 | |
| 14 | namespace buffet { |
| 15 | |
| 16 | // Persists the given Value to an atomically written file. |
| 17 | class FileStorage : public StorageInterface { |
| 18 | public: |
Alex Vakulenko | 3379706 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 19 | explicit FileStorage(const base::FilePath& file_path); |
Alex Vakulenko | 534a312 | 2015-05-22 15:48:53 -0700 | [diff] [blame] | 20 | ~FileStorage() override = default; |
Vitaly Buka | 207c1cb | 2015-05-14 17:06:18 -0700 | [diff] [blame] | 21 | std::unique_ptr<base::DictionaryValue> Load() override; |
| 22 | bool Save(const base::DictionaryValue& config) override; |
Christopher Wiley | 006e94e | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 23 | |
| 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. |
| 30 | class MemStorage : public StorageInterface { |
| 31 | public: |
| 32 | MemStorage() = default; |
Alex Vakulenko | 534a312 | 2015-05-22 15:48:53 -0700 | [diff] [blame] | 33 | ~MemStorage() override = default; |
Vitaly Buka | 207c1cb | 2015-05-14 17:06:18 -0700 | [diff] [blame] | 34 | std::unique_ptr<base::DictionaryValue> Load() override; |
| 35 | bool Save(const base::DictionaryValue& config) override; |
Christopher Wiley | 006e94e | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 36 | |
| 37 | private: |
Vitaly Buka | 207c1cb | 2015-05-14 17:06:18 -0700 | [diff] [blame] | 38 | base::DictionaryValue cache_; |
Christopher Wiley | 006e94e | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 39 | DISALLOW_COPY_AND_ASSIGN(MemStorage); |
| 40 | }; |
| 41 | |
| 42 | } // namespace buffet |
| 43 | |
| 44 | #endif // BUFFET_STORAGE_IMPLS_H_ |