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_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: |
| 18 | // Load the device registration configuration from storage. |
| 19 | // If it fails (e.g. the storage container [file?] doesn't exist), then |
| 20 | // it returns empty unique_ptr (aka nullptr). |
| 21 | virtual std::unique_ptr<base::Value> Load() = 0; |
| 22 | |
| 23 | // Save the device registration configuration to storage. |
| 24 | // If saved successfully, returns true. Could fail when writing to |
| 25 | // physical storage like file system for various reasons (out of disk space, |
| 26 | // access permissions, etc). |
| 27 | virtual bool Save(const base::Value* config) = 0; |
| 28 | }; |
| 29 | |
| 30 | } // namespace buffet |
| 31 | |
| 32 | #endif // BUFFET_STORAGE_INTERFACE_H_ |