Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H__ |
| 7 | |
| 8 | #include "base/file_path.h" |
| 9 | #include "gtest/gtest_prod.h" // for FRIEND_TEST |
| 10 | #include "update_engine/prefs_interface.h" |
| 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | // Implements a preference store by storing the value associated with |
| 15 | // a key in a separate file named after the key under a preference |
| 16 | // store directory. |
| 17 | |
| 18 | class Prefs : public PrefsInterface { |
| 19 | public: |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 20 | Prefs() {} |
| 21 | |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 22 | // Initializes the store by associating this object with |prefs_dir| |
| 23 | // as the preference store directory. Returns true on success, false |
| 24 | // otherwise. |
| 25 | bool Init(const FilePath& prefs_dir); |
| 26 | |
| 27 | // PrefsInterface methods. |
| 28 | bool GetString(const std::string& key, std::string* value); |
| 29 | bool SetString(const std::string& key, const std::string& value); |
| 30 | bool GetInt64(const std::string& key, int64_t* value); |
| 31 | bool SetInt64(const std::string& key, const int64_t value); |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 32 | bool GetBoolean(const std::string& key, bool* value); |
| 33 | bool SetBoolean(const std::string& key, const bool value); |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 34 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 35 | bool Exists(const std::string& key); |
| 36 | bool Delete(const std::string& key); |
| 37 | |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 38 | private: |
| 39 | FRIEND_TEST(PrefsTest, GetFileNameForKey); |
| 40 | FRIEND_TEST(PrefsTest, GetFileNameForKeyBadCharacter); |
| 41 | FRIEND_TEST(PrefsTest, GetFileNameForKeyEmpty); |
| 42 | |
| 43 | // Sets |filename| to the full path to the file containing the data |
| 44 | // associated with |key|. Returns true on success, false otherwise. |
| 45 | bool GetFileNameForKey(const std::string& key, FilePath* filename); |
| 46 | |
| 47 | // Preference store directory. |
| 48 | FilePath prefs_dir_; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(Prefs); |
Darin Petkov | 3003059 | 2010-07-27 13:53:20 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace chromeos_update_engine |
| 54 | |
| 55 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H__ |