[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 1 | // 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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 8 | |
| 9 | #include <string> |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 10 | #include <vector> |
| 11 | #include "base/singleton.h" |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 12 | |
| 13 | #include "chrome/browser/chromeos/cros_settings_names.h" |
| 14 | |
[email protected] | c02c853d7 | 2010-08-07 06:23:24 | [diff] [blame] | 15 | class Value; |
| 16 | |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 17 | namespace chromeos { |
| 18 | |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 19 | class CrosSettingsProvider; |
| 20 | |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 21 | // A class manages per-device/global settings. |
| 22 | class 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] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 28 | static bool IsCrosSettings(const std::string& path); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 29 | |
| 30 | // Sets |in_value| to given |path| in cros settings. |
| 31 | // Note that this takes ownership of |in_value|. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 32 | void Set(const std::string& path, Value* in_value); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 33 | |
| 34 | // Gets settings value of given |path| to |out_value|. |
| 35 | // Note that |out_value| is still owned by this class. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 36 | bool Get(const std::string& path, Value** out_value) const; |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 37 | |
| 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] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 40 | 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] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 44 | |
| 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] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 48 | 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] | 46ebf064 | 2010-07-24 02:47:40 | [diff] [blame] | 52 | |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 53 | 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] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 62 | CrosSettingsProvider* GetProvider(const std::string& path) const; |
[email protected] | 93a49ae | 2010-08-03 23:50:47 | [diff] [blame] | 63 | friend struct DefaultSingletonTraits<CrosSettings>; |
| 64 | DISALLOW_COPY_AND_ASSIGN(CrosSettings); |
[email protected] | 73bd67b | 2010-07-16 16:00:09 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace chromeos |
| 68 | |
| 69 | #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ |