blob: 0cf52ab4311c7204899918ab6cd05de603886fa3 [file] [log] [blame]
[email protected]73bd67b2010-07-16 16:00:091// Copyright (c) 2010 The Chromium 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 CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
6#define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]73bd67b2010-07-16 16:00:098
9#include <string>
[email protected]93a49ae2010-08-03 23:50:4710#include <vector>
11#include "base/singleton.h"
[email protected]73bd67b2010-07-16 16:00:0912
13#include "chrome/browser/chromeos/cros_settings_names.h"
14
[email protected]c02c853d72010-08-07 06:23:2415class Value;
16
[email protected]73bd67b2010-07-16 16:00:0917namespace chromeos {
18
[email protected]93a49ae2010-08-03 23:50:4719class CrosSettingsProvider;
20
[email protected]73bd67b2010-07-16 16:00:0921// A class manages per-device/global settings.
22class CrosSettings {
23 public:
24 // Class factory.
25 static CrosSettings* Get();
26
27 // Helper function to test if given path is a value cros settings name.
[email protected]57ecc4b2010-08-11 03:02:5128 static bool IsCrosSettings(const std::string& path);
[email protected]73bd67b2010-07-16 16:00:0929
30 // Sets |in_value| to given |path| in cros settings.
31 // Note that this takes ownership of |in_value|.
[email protected]57ecc4b2010-08-11 03:02:5132 void Set(const std::string& path, Value* in_value);
[email protected]73bd67b2010-07-16 16:00:0933
34 // Gets settings value of given |path| to |out_value|.
35 // Note that |out_value| is still owned by this class.
[email protected]57ecc4b2010-08-11 03:02:5136 bool Get(const std::string& path, Value** out_value) const;
[email protected]73bd67b2010-07-16 16:00:0937
38 // Convenience forms of Set(). These methods will replace any existing
39 // value at that path, even if it has a different type.
[email protected]57ecc4b2010-08-11 03:02:5140 void SetBoolean(const std::string& path, bool in_value);
41 void SetInteger(const std::string& path, int in_value);
42 void SetReal(const std::string& path, double in_value);
43 void SetString(const std::string& path, const std::string& in_value);
[email protected]73bd67b2010-07-16 16:00:0944
45 // These are convenience forms of Get(). The value will be retrieved
46 // and the return value will be true if the path is valid and the value at
47 // the end of the path can be returned in the form specified.
[email protected]57ecc4b2010-08-11 03:02:5148 bool GetBoolean(const std::string& path, bool* out_value) const;
49 bool GetInteger(const std::string& path, int* out_value) const;
50 bool GetReal(const std::string& path, double* out_value) const;
51 bool GetString(const std::string& path, std::string* out_value) const;
[email protected]46ebf0642010-07-24 02:47:4052
[email protected]93a49ae2010-08-03 23:50:4753 private:
54 // adding/removing of providers
55 bool AddProvider(CrosSettingsProvider* provider);
56 bool RemoveProvider(CrosSettingsProvider* provider);
57
58 std::vector<CrosSettingsProvider*> providers_;
59
60 CrosSettings();
61 ~CrosSettings();
[email protected]57ecc4b2010-08-11 03:02:5162 CrosSettingsProvider* GetProvider(const std::string& path) const;
[email protected]93a49ae2010-08-03 23:50:4763 friend struct DefaultSingletonTraits<CrosSettings>;
64 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
[email protected]73bd67b2010-07-16 16:00:0965};
66
67} // namespace chromeos
68
69#endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_