blob: fd86dde0a24dd986dde5576bd1bc2d2020254493 [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_PREFS_H_
6#define UPDATE_ENGINE_PREFS_H_
Darin Petkov30030592010-07-27 13:53:20 -07007
Alex Vakulenkod2779df2014-06-16 13:19:00 -07008#include <string>
9
Alex Vakulenko75039d72014-03-25 12:36:28 -070010#include <base/files/file_path.h>
Darin Petkov30030592010-07-27 13:53:20 -070011#include "gtest/gtest_prod.h" // for FRIEND_TEST
12#include "update_engine/prefs_interface.h"
13
14namespace 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
20class Prefs : public PrefsInterface {
21 public:
Darin Petkov1cbd78f2010-07-29 12:38:34 -070022 Prefs() {}
23
Darin Petkov30030592010-07-27 13:53:20 -070024 // Initializes the store by associating this object with |prefs_dir|
25 // as the preference store directory. Returns true on success, false
26 // otherwise.
Alex Vakulenko75039d72014-03-25 12:36:28 -070027 bool Init(const base::FilePath& prefs_dir);
Darin Petkov30030592010-07-27 13:53:20 -070028
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 Deymoefb7c4c2013-07-09 14:34:00 -070034 bool GetBoolean(const std::string& key, bool* value);
35 bool SetBoolean(const std::string& key, const bool value);
Darin Petkov30030592010-07-27 13:53:20 -070036
Jay Srinivasan480ddfa2012-06-01 19:15:26 -070037 bool Exists(const std::string& key);
38 bool Delete(const std::string& key);
39
Darin Petkov30030592010-07-27 13:53:20 -070040 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 Vakulenko75039d72014-03-25 12:36:28 -070047 bool GetFileNameForKey(const std::string& key, base::FilePath* filename);
Darin Petkov30030592010-07-27 13:53:20 -070048
49 // Preference store directory.
Alex Vakulenko75039d72014-03-25 12:36:28 -070050 base::FilePath prefs_dir_;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070051
52 DISALLOW_COPY_AND_ASSIGN(Prefs);
Darin Petkov30030592010-07-27 13:53:20 -070053};
54
55} // namespace chromeos_update_engine
56
Gilad Arnoldcf175a02014-07-10 16:48:47 -070057#endif // UPDATE_ENGINE_PREFS_H_