Darin Petkov | 4f0a07b | 2011-05-25 16:47:20 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_INTERFACE_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_INTERFACE_H__ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | namespace chromeos_update_engine { |
| 11 | |
| 12 | // The prefs interface allows access to a persistent preferences |
| 13 | // store. The two reasons for providing this as an interface are |
| 14 | // testing as well as easier switching to a new implementation in the |
| 15 | // future, if necessary. |
| 16 | |
| 17 | class PrefsInterface { |
| 18 | public: |
| 19 | // Gets a string |value| associated with |key|. Returns true on |
| 20 | // success, false on failure (including when the |key| is not |
| 21 | // present in the store). |
| 22 | virtual bool GetString(const std::string& key, std::string* value) = 0; |
| 23 | |
| 24 | // Associates |key| with a string |value|. Returns true on success, |
| 25 | // false otherwise. |
| 26 | virtual bool SetString(const std::string& key, const std::string& value) = 0; |
| 27 | |
| 28 | // Gets an int64 |value| associated with |key|. Returns true on |
| 29 | // success, false on failure (including when the |key| is not |
| 30 | // present in the store). |
| 31 | virtual bool GetInt64(const std::string& key, int64_t* value) = 0; |
| 32 | |
| 33 | // Associates |key| with an int64 |value|. Returns true on success, |
| 34 | // false otherwise. |
| 35 | virtual bool SetInt64(const std::string& key, const int64_t value) = 0; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 36 | |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame^] | 37 | // Gets a boolean |value| associated with |key|. Returns true on |
| 38 | // success, false on failure (including when the |key| is not |
| 39 | // present in the store). |
| 40 | virtual bool GetBoolean(const std::string& key, bool* value) = 0; |
| 41 | |
| 42 | // Associates |key| with a boolean |value|. Returns true on success, |
| 43 | // false otherwise. |
| 44 | virtual bool SetBoolean(const std::string& key, const bool value) = 0; |
| 45 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 46 | // Returns true if the setting exists (i.e. a file with the given key |
| 47 | // exists in the prefs directory) |
| 48 | virtual bool Exists(const std::string& key) = 0; |
| 49 | |
| 50 | // Returns true if successfully deleted the file corresponding to |
| 51 | // this key. Calling with non-existent keys does nothing. |
| 52 | virtual bool Delete(const std::string& key) = 0; |
| 53 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 54 | virtual ~PrefsInterface() {} |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace chromeos_update_engine |
| 58 | |
| 59 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_INTERFACE_H__ |