blob: e128edaa3c938730f21617f2bca2a11677872a76 [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);
32
Jay Srinivasan480ddfa2012-06-01 19:15:26 -070033 bool Exists(const std::string& key);
34 bool Delete(const std::string& key);
35
Darin Petkov30030592010-07-27 13:53:20 -070036 private:
37 FRIEND_TEST(PrefsTest, GetFileNameForKey);
38 FRIEND_TEST(PrefsTest, GetFileNameForKeyBadCharacter);
39 FRIEND_TEST(PrefsTest, GetFileNameForKeyEmpty);
40
41 // Sets |filename| to the full path to the file containing the data
42 // associated with |key|. Returns true on success, false otherwise.
43 bool GetFileNameForKey(const std::string& key, FilePath* filename);
44
45 // Preference store directory.
46 FilePath prefs_dir_;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070047
48 DISALLOW_COPY_AND_ASSIGN(Prefs);
Darin Petkov30030592010-07-27 13:53:20 -070049};
50
51} // namespace chromeos_update_engine
52
53#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H__