blob: e53caeeeee44fdd5da22b4ea26a17e127506aed0 [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>
[email protected]73bd67b2010-07-16 16:00:0911
[email protected]7096f562010-08-16 21:59:0412#include "base/hash_tables.h"
13#include "base/non_thread_safe.h"
14#include "base/observer_list.h"
15#include "base/singleton.h"
[email protected]73bd67b2010-07-16 16:00:0916#include "chrome/browser/chromeos/cros_settings_names.h"
[email protected]7096f562010-08-16 21:59:0417#include "chrome/common/notification_observer.h"
[email protected]73bd67b2010-07-16 16:00:0918
[email protected]c02c853d72010-08-07 06:23:2419class Value;
20
[email protected]73bd67b2010-07-16 16:00:0921namespace chromeos {
22
[email protected]93a49ae2010-08-03 23:50:4723class CrosSettingsProvider;
24
[email protected]73bd67b2010-07-16 16:00:0925// A class manages per-device/global settings.
[email protected]7096f562010-08-16 21:59:0426class CrosSettings : public NonThreadSafe {
[email protected]73bd67b2010-07-16 16:00:0927 public:
28 // Class factory.
29 static CrosSettings* Get();
30
31 // Helper function to test if given path is a value cros settings name.
[email protected]57ecc4b2010-08-11 03:02:5132 static bool IsCrosSettings(const std::string& path);
[email protected]73bd67b2010-07-16 16:00:0933
34 // Sets |in_value| to given |path| in cros settings.
35 // Note that this takes ownership of |in_value|.
[email protected]57ecc4b2010-08-11 03:02:5136 void Set(const std::string& path, Value* in_value);
[email protected]73bd67b2010-07-16 16:00:0937
[email protected]7096f562010-08-16 21:59:0438 // Fires system setting change notification.
39 void FireObservers(const char* path);
40
[email protected]73bd67b2010-07-16 16:00:0941 // Gets settings value of given |path| to |out_value|.
42 // Note that |out_value| is still owned by this class.
[email protected]57ecc4b2010-08-11 03:02:5143 bool Get(const std::string& path, Value** out_value) const;
[email protected]73bd67b2010-07-16 16:00:0944
45 // Convenience forms of Set(). These methods will replace any existing
46 // value at that path, even if it has a different type.
[email protected]57ecc4b2010-08-11 03:02:5147 void SetBoolean(const std::string& path, bool in_value);
48 void SetInteger(const std::string& path, int in_value);
49 void SetReal(const std::string& path, double in_value);
50 void SetString(const std::string& path, const std::string& in_value);
[email protected]73bd67b2010-07-16 16:00:0951
52 // These are convenience forms of Get(). The value will be retrieved
53 // and the return value will be true if the path is valid and the value at
54 // the end of the path can be returned in the form specified.
[email protected]57ecc4b2010-08-11 03:02:5155 bool GetBoolean(const std::string& path, bool* out_value) const;
56 bool GetInteger(const std::string& path, int* out_value) const;
57 bool GetReal(const std::string& path, double* out_value) const;
58 bool GetString(const std::string& path, std::string* out_value) const;
[email protected]46ebf0642010-07-24 02:47:4059
[email protected]93a49ae2010-08-03 23:50:4760 // adding/removing of providers
[email protected]7096f562010-08-16 21:59:0461 bool AddSettingsProvider(CrosSettingsProvider* provider);
62 bool RemoveSettingsProvider(CrosSettingsProvider* provider);
[email protected]93a49ae2010-08-03 23:50:4763
[email protected]7096f562010-08-16 21:59:0464 // If the pref at the given path changes, we call the observer's Observe
65 // method with NOTIFY_PREF_CHANGED.
66 void AddSettingsObserver(const char* path, NotificationObserver* obs);
67 void RemoveSettingsObserver(const char* path, NotificationObserver* obs);
68
69 private:
70 // List of ChromeOS system settings providers.
[email protected]93a49ae2010-08-03 23:50:4771 std::vector<CrosSettingsProvider*> providers_;
72
[email protected]7096f562010-08-16 21:59:0473 // A map from settings names to a list of observers. Observers get fired in
74 // the order they are added.
75 typedef ObserverList<NotificationObserver> NotificationObserverList;
76 typedef base::hash_map<std::string, NotificationObserverList*>
77 SettingsObserverMap;
78 SettingsObserverMap settings_observers_;
79
[email protected]93a49ae2010-08-03 23:50:4780 CrosSettings();
81 ~CrosSettings();
[email protected]57ecc4b2010-08-11 03:02:5182 CrosSettingsProvider* GetProvider(const std::string& path) const;
[email protected]93a49ae2010-08-03 23:50:4783 friend struct DefaultSingletonTraits<CrosSettings>;
[email protected]7096f562010-08-16 21:59:0484
[email protected]93a49ae2010-08-03 23:50:4785 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
[email protected]73bd67b2010-07-16 16:00:0986};
87
88} // namespace chromeos
89
90#endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_