Christopher Wiley | 6d4db22 | 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_INTERFACE_H_ |
| 6 | #define BUFFET_STORAGE_INTERFACE_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include <base/values.h> |
| 11 | |
| 12 | namespace buffet { |
| 13 | |
| 14 | // We need to persist data in a couple places, and it is convenient to hide |
| 15 | // the details of this storage behind an interface for test purposes. |
| 16 | class StorageInterface { |
| 17 | public: |
Vitaly Buka | 0faceef | 2015-05-18 09:28:54 -0700 | [diff] [blame] | 18 | virtual ~StorageInterface() = default; |
| 19 | |
Vitaly Buka | d0ec5b0 | 2015-05-14 17:06:18 -0700 | [diff] [blame] | 20 | // Load the dictionary from storage. If it fails (e.g. the storage container |
| 21 | // [file?] doesn't exist), then it returns empty unique_ptr (aka nullptr). |
| 22 | virtual std::unique_ptr<base::DictionaryValue> Load() = 0; |
Christopher Wiley | 6d4db22 | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 23 | |
Vitaly Buka | d0ec5b0 | 2015-05-14 17:06:18 -0700 | [diff] [blame] | 24 | // Save the dictionary to storage. If saved successfully, returns true. Could |
| 25 | // fail when writing to physical storage like file system for various reasons |
| 26 | // (out of disk space,access permissions, etc). |
| 27 | virtual bool Save(const base::DictionaryValue& config) = 0; |
Christopher Wiley | 6d4db22 | 2014-05-02 13:44:48 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | } // namespace buffet |
| 31 | |
| 32 | #endif // BUFFET_STORAGE_INTERFACE_H_ |