blob: 6c0a7413c537572651a2300b8132fc199f4e5210 [file] [log] [blame]
Darin Petkov4f0a07b2011-05-25 16:47:20 -07001// Copyright (c) 2011 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_INTERFACE_H_
6#define UPDATE_ENGINE_PREFS_INTERFACE_H_
Darin Petkov30030592010-07-27 13:53:20 -07007
Ben Chan9abb7632014-08-07 00:10:53 -07008#include <stdint.h>
9
Darin Petkov30030592010-07-27 13:53:20 -070010#include <string>
11
12namespace chromeos_update_engine {
13
14// The prefs interface allows access to a persistent preferences
15// store. The two reasons for providing this as an interface are
16// testing as well as easier switching to a new implementation in the
17// future, if necessary.
18
19class PrefsInterface {
20 public:
21 // Gets a string |value| associated with |key|. Returns true on
22 // success, false on failure (including when the |key| is not
23 // present in the store).
24 virtual bool GetString(const std::string& key, std::string* value) = 0;
25
26 // Associates |key| with a string |value|. Returns true on success,
27 // false otherwise.
28 virtual bool SetString(const std::string& key, const std::string& value) = 0;
29
Ben Chan9abb7632014-08-07 00:10:53 -070030 // Gets an int64_t |value| associated with |key|. Returns true on
Darin Petkov30030592010-07-27 13:53:20 -070031 // success, false on failure (including when the |key| is not
32 // present in the store).
33 virtual bool GetInt64(const std::string& key, int64_t* value) = 0;
34
Ben Chan9abb7632014-08-07 00:10:53 -070035 // Associates |key| with an int64_t |value|. Returns true on success,
Darin Petkov30030592010-07-27 13:53:20 -070036 // false otherwise.
37 virtual bool SetInt64(const std::string& key, const int64_t value) = 0;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070038
Alex Deymoefb7c4c2013-07-09 14:34:00 -070039 // Gets a boolean |value| associated with |key|. Returns true on
40 // success, false on failure (including when the |key| is not
41 // present in the store).
42 virtual bool GetBoolean(const std::string& key, bool* value) = 0;
43
44 // Associates |key| with a boolean |value|. Returns true on success,
45 // false otherwise.
46 virtual bool SetBoolean(const std::string& key, const bool value) = 0;
47
Jay Srinivasan480ddfa2012-06-01 19:15:26 -070048 // Returns true if the setting exists (i.e. a file with the given key
49 // exists in the prefs directory)
50 virtual bool Exists(const std::string& key) = 0;
51
52 // Returns true if successfully deleted the file corresponding to
53 // this key. Calling with non-existent keys does nothing.
54 virtual bool Delete(const std::string& key) = 0;
55
Darin Petkov1cbd78f2010-07-29 12:38:34 -070056 virtual ~PrefsInterface() {}
Darin Petkov30030592010-07-27 13:53:20 -070057};
58
59} // namespace chromeos_update_engine
60
Gilad Arnoldcf175a02014-07-10 16:48:47 -070061#endif // UPDATE_ENGINE_PREFS_INTERFACE_H_