blob: f05da0a318135be3924ca167d047be7d79038dd2 [file] [log] [blame]
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov30030592010-07-27 13:53:20 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Deymo759c2752014-03-17 21:09:36 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H_
Darin Petkov30030592010-07-27 13:53:20 -07007
Alex Vakulenko75039d72014-03-25 12:36:28 -07008#include <base/files/file_path.h>
Darin Petkov30030592010-07-27 13:53:20 -07009#include "gtest/gtest_prod.h" // for FRIEND_TEST
10#include "update_engine/prefs_interface.h"
11
12namespace 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
18class Prefs : public PrefsInterface {
19 public:
Darin Petkov1cbd78f2010-07-29 12:38:34 -070020 Prefs() {}
21
Darin Petkov30030592010-07-27 13:53:20 -070022 // Initializes the store by associating this object with |prefs_dir|
23 // as the preference store directory. Returns true on success, false
24 // otherwise.
Alex Vakulenko75039d72014-03-25 12:36:28 -070025 bool Init(const base::FilePath& prefs_dir);
Darin Petkov30030592010-07-27 13:53:20 -070026
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 Deymoefb7c4c2013-07-09 14:34:00 -070032 bool GetBoolean(const std::string& key, bool* value);
33 bool SetBoolean(const std::string& key, const bool value);
Darin Petkov30030592010-07-27 13:53:20 -070034
Jay Srinivasan480ddfa2012-06-01 19:15:26 -070035 bool Exists(const std::string& key);
36 bool Delete(const std::string& key);
37
Darin Petkov30030592010-07-27 13:53:20 -070038 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.
Alex Vakulenko75039d72014-03-25 12:36:28 -070045 bool GetFileNameForKey(const std::string& key, base::FilePath* filename);
Darin Petkov30030592010-07-27 13:53:20 -070046
47 // Preference store directory.
Alex Vakulenko75039d72014-03-25 12:36:28 -070048 base::FilePath prefs_dir_;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070049
50 DISALLOW_COPY_AND_ASSIGN(Prefs);
Darin Petkov30030592010-07-27 13:53:20 -070051};
52
53} // namespace chromeos_update_engine
54
Alex Deymo759c2752014-03-17 21:09:36 -070055#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H_