blob: 55f721fed44bc9519cc2f3f55405c9cb05e81052 [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
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
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.
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 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.
45 bool GetFileNameForKey(const std::string& key, FilePath* filename);
46
47 // Preference store directory.
48 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
55#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H__