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