Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/browser/chromeos/cros_settings.h

Issue 3143009: Reenabled ChromeOS system setting for timezone selection.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11
12 #include "base/hash_tables.h"
13 #include "base/non_thread_safe.h"
14 #include "base/observer_list.h"
11 #include "base/singleton.h" 15 #include "base/singleton.h"
12
13 #include "chrome/browser/chromeos/cros_settings_names.h" 16 #include "chrome/browser/chromeos/cros_settings_names.h"
17 #include "chrome/common/notification_observer.h"
14 18
15 class Value; 19 class Value;
16 20
17 namespace chromeos { 21 namespace chromeos {
18 22
19 class CrosSettingsProvider; 23 class CrosSettingsProvider;
20 24
21 // A class manages per-device/global settings. 25 // A class manages per-device/global settings.
22 class CrosSettings { 26 class CrosSettings : public NonThreadSafe {
23 public: 27 public:
24 // Class factory. 28 // Class factory.
25 static CrosSettings* Get(); 29 static CrosSettings* Get();
26 30
27 // Helper function to test if given path is a value cros settings name. 31 // Helper function to test if given path is a value cros settings name.
28 static bool IsCrosSettings(const std::string& path); 32 static bool IsCrosSettings(const std::string& path);
29 33
30 // Sets |in_value| to given |path| in cros settings. 34 // Sets |in_value| to given |path| in cros settings.
31 // Note that this takes ownership of |in_value|. 35 // Note that this takes ownership of |in_value|.
32 void Set(const std::string& path, Value* in_value); 36 void Set(const std::string& path, Value* in_value);
33 37
38 // Fires system setting change notification.
39 void FireObservers(const char* path);
40
34 // Gets settings value of given |path| to |out_value|. 41 // Gets settings value of given |path| to |out_value|.
35 // Note that |out_value| is still owned by this class. 42 // Note that |out_value| is still owned by this class.
36 bool Get(const std::string& path, Value** out_value) const; 43 bool Get(const std::string& path, Value** out_value) const;
37 44
38 // Convenience forms of Set(). These methods will replace any existing 45 // Convenience forms of Set(). These methods will replace any existing
39 // value at that path, even if it has a different type. 46 // value at that path, even if it has a different type.
40 void SetBoolean(const std::string& path, bool in_value); 47 void SetBoolean(const std::string& path, bool in_value);
41 void SetInteger(const std::string& path, int in_value); 48 void SetInteger(const std::string& path, int in_value);
42 void SetReal(const std::string& path, double in_value); 49 void SetReal(const std::string& path, double in_value);
43 void SetString(const std::string& path, const std::string& in_value); 50 void SetString(const std::string& path, const std::string& in_value);
44 51
45 // These are convenience forms of Get(). The value will be retrieved 52 // 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 53 // 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. 54 // the end of the path can be returned in the form specified.
48 bool GetBoolean(const std::string& path, bool* out_value) const; 55 bool GetBoolean(const std::string& path, bool* out_value) const;
49 bool GetInteger(const std::string& path, int* out_value) const; 56 bool GetInteger(const std::string& path, int* out_value) const;
50 bool GetReal(const std::string& path, double* out_value) const; 57 bool GetReal(const std::string& path, double* out_value) const;
51 bool GetString(const std::string& path, std::string* out_value) const; 58 bool GetString(const std::string& path, std::string* out_value) const;
52 59
60 // adding/removing of providers
61 bool AddSettingsProvider(CrosSettingsProvider* provider);
62 bool RemoveSettingsProvider(CrosSettingsProvider* provider);
63
64 // 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
53 private: 69 private:
54 // adding/removing of providers 70 // List of ChromeOS system settings providers.
55 bool AddProvider(CrosSettingsProvider* provider); 71 std::vector<CrosSettingsProvider*> providers_;
56 bool RemoveProvider(CrosSettingsProvider* provider);
57 72
58 std::vector<CrosSettingsProvider*> providers_; 73 // 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_;
59 79
60 CrosSettings(); 80 CrosSettings();
61 ~CrosSettings(); 81 ~CrosSettings();
62 CrosSettingsProvider* GetProvider(const std::string& path) const; 82 CrosSettingsProvider* GetProvider(const std::string& path) const;
63 friend struct DefaultSingletonTraits<CrosSettings>; 83 friend struct DefaultSingletonTraits<CrosSettings>;
84
64 DISALLOW_COPY_AND_ASSIGN(CrosSettings); 85 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
65 }; 86 };
66 87
67 } // namespace chromeos 88 } // namespace chromeos
68 89
69 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_ 90 #endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698