blob: 563ee994f14b872ea655b44aeac4512734d2fd3d [file] [log] [blame]
[email protected]2b2820a2011-03-07 22:28:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]73bd67b2010-07-16 16:00:092// 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"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
[email protected]7096f562010-08-16 21:59:0414#include "base/observer_list.h"
[email protected]c9177502011-01-01 04:48:4915#include "base/threading/non_thread_safe.h"
[email protected]73bd67b2010-07-16 16:00:0916#include "chrome/browser/chromeos/cros_settings_names.h"
[email protected]45d32232011-11-22 11:42:3117#include "chrome/browser/chromeos/cros_settings_provider.h"
[email protected]6c2381d2011-10-19 02:52:5318#include "content/public/browser/notification_observer.h"
[email protected]73bd67b2010-07-16 16:00:0919
[email protected]dc8caba2010-12-13 16:52:3520namespace base {
21template <typename T> struct DefaultLazyInstanceTraits;
[email protected]45d32232011-11-22 11:42:3122class ListValue;
[email protected]c02c853d72010-08-07 06:23:2423class Value;
[email protected]f3a1c642011-07-12 19:15:0324}
[email protected]c02c853d72010-08-07 06:23:2425
[email protected]73bd67b2010-07-16 16:00:0926namespace chromeos {
27
28// A class manages per-device/global settings.
[email protected]c9177502011-01-01 04:48:4929class CrosSettings : public base::NonThreadSafe {
[email protected]73bd67b2010-07-16 16:00:0930 public:
31 // Class factory.
32 static CrosSettings* Get();
33
34 // Helper function to test if given path is a value cros settings name.
[email protected]57ecc4b2010-08-11 03:02:5135 static bool IsCrosSettings(const std::string& path);
[email protected]73bd67b2010-07-16 16:00:0936
37 // Sets |in_value| to given |path| in cros settings.
38 // Note that this takes ownership of |in_value|.
[email protected]f3a1c642011-07-12 19:15:0339 void Set(const std::string& path, base::Value* in_value);
[email protected]73bd67b2010-07-16 16:00:0940
[email protected]7096f562010-08-16 21:59:0441 // Fires system setting change notification.
[email protected]45d32232011-11-22 11:42:3142 // TODO(pastarmovj): Consider to remove this function from the public
43 // interface.
[email protected]7096f562010-08-16 21:59:0444 void FireObservers(const char* path);
45
[email protected]73bd67b2010-07-16 16:00:0946 // Gets settings value of given |path| to |out_value|.
[email protected]45d32232011-11-22 11:42:3147 const base::Value* GetPref(const std::string& path) const;
48
49 // Starts a fetch from the trusted store for the value of |path| if not loaded
50 // yet. It will call the |callback| function upon completion if a new fetch
51 // was needed in which case the return value is false. Else it will return
52 // true and won't call the |callback|.
53 bool GetTrusted(const std::string& path,
54 const base::Closure& callback) const;
[email protected]73bd67b2010-07-16 16:00:0955
56 // Convenience forms of Set(). These methods will replace any existing
57 // value at that path, even if it has a different type.
[email protected]57ecc4b2010-08-11 03:02:5158 void SetBoolean(const std::string& path, bool in_value);
59 void SetInteger(const std::string& path, int in_value);
[email protected]fb534c92011-02-01 01:02:0760 void SetDouble(const std::string& path, double in_value);
[email protected]57ecc4b2010-08-11 03:02:5161 void SetString(const std::string& path, const std::string& in_value);
[email protected]73bd67b2010-07-16 16:00:0962
63 // These are convenience forms of Get(). The value will be retrieved
64 // and the return value will be true if the path is valid and the value at
65 // the end of the path can be returned in the form specified.
[email protected]57ecc4b2010-08-11 03:02:5166 bool GetBoolean(const std::string& path, bool* out_value) const;
67 bool GetInteger(const std::string& path, int* out_value) const;
[email protected]fb534c92011-02-01 01:02:0768 bool GetDouble(const std::string& path, double* out_value) const;
[email protected]57ecc4b2010-08-11 03:02:5169 bool GetString(const std::string& path, std::string* out_value) const;
[email protected]45d32232011-11-22 11:42:3170 bool GetList(const std::string& path,
71 const base::ListValue** out_value) const;
[email protected]46ebf0642010-07-24 02:47:4072
[email protected]93a49ae2010-08-03 23:50:4773 // adding/removing of providers
[email protected]7096f562010-08-16 21:59:0474 bool AddSettingsProvider(CrosSettingsProvider* provider);
75 bool RemoveSettingsProvider(CrosSettingsProvider* provider);
[email protected]93a49ae2010-08-03 23:50:4776
[email protected]7096f562010-08-16 21:59:0477 // If the pref at the given path changes, we call the observer's Observe
[email protected]10abd192010-09-30 02:03:4978 // method with PREF_CHANGED.
[email protected]6c2381d2011-10-19 02:52:5379 void AddSettingsObserver(const char* path,
80 content::NotificationObserver* obs);
81 void RemoveSettingsObserver(const char* path,
82 content::NotificationObserver* obs);
[email protected]7096f562010-08-16 21:59:0483
[email protected]c0a2128d92011-07-20 15:04:4684 // Returns the provider that handles settings with the path or prefix.
85 CrosSettingsProvider* GetProvider(const std::string& path) const;
86
[email protected]7096f562010-08-16 21:59:0487 private:
88 // List of ChromeOS system settings providers.
[email protected]93a49ae2010-08-03 23:50:4789 std::vector<CrosSettingsProvider*> providers_;
90
[email protected]7096f562010-08-16 21:59:0491 // A map from settings names to a list of observers. Observers get fired in
92 // the order they are added.
[email protected]6c2381d2011-10-19 02:52:5393 typedef ObserverList<content::NotificationObserver> NotificationObserverList;
[email protected]7096f562010-08-16 21:59:0494 typedef base::hash_map<std::string, NotificationObserverList*>
95 SettingsObserverMap;
96 SettingsObserverMap settings_observers_;
97
[email protected]93a49ae2010-08-03 23:50:4798 CrosSettings();
99 ~CrosSettings();
[email protected]dc8caba2010-12-13 16:52:35100 friend struct base::DefaultLazyInstanceTraits<CrosSettings>;
[email protected]7096f562010-08-16 21:59:04101
[email protected]93a49ae2010-08-03 23:50:47102 DISALLOW_COPY_AND_ASSIGN(CrosSettings);
[email protected]73bd67b2010-07-16 16:00:09103};
104
105} // namespace chromeos
106
107#endif // CHROME_BROWSER_CHROMEOS_CROS_SETTINGS_H_