blob: cccfed5a5b633708fbc98e89d74cbb46cd47fdb4 [file] [log] [blame]
Darin Petkov30030592010-07-27 13:53:20 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
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
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
33 private:
34 FRIEND_TEST(PrefsTest, GetFileNameForKey);
35 FRIEND_TEST(PrefsTest, GetFileNameForKeyBadCharacter);
36 FRIEND_TEST(PrefsTest, GetFileNameForKeyEmpty);
37
38 // Sets |filename| to the full path to the file containing the data
39 // associated with |key|. Returns true on success, false otherwise.
40 bool GetFileNameForKey(const std::string& key, FilePath* filename);
41
42 // Preference store directory.
43 FilePath prefs_dir_;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070044
45 DISALLOW_COPY_AND_ASSIGN(Prefs);
Darin Petkov30030592010-07-27 13:53:20 -070046};
47
48} // namespace chromeos_update_engine
49
50#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PREFS_H__