summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/preference/chrome_direct_setting_api.h
diff options
context:
space:
mode:
authorrobliao@chromium.org <robliao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-18 09:40:47 +0000
committerrobliao@chromium.org <robliao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-18 09:40:47 +0000
commit4ad4ce089223e144fb240751ba7a48f7c9064d27 (patch)
tree1c9cb30afd770376443e67c97a79a968ba7531f5 /chrome/browser/extensions/api/preference/chrome_direct_setting_api.h
parente631a5f7df3aceff6307e04d36073f01412fbb3c (diff)
downloadchromium_src-4ad4ce089223e144fb240751ba7a48f7c9064d27.zip
chromium_src-4ad4ce089223e144fb240751ba7a48f7c9064d27.tar.gz
chromium_src-4ad4ce089223e144fb240751ba7a48f7c9064d27.tar.bz2
Implemented types.private.ChromeDirectSetting.onChange
This delta links up the onChange event machinery to the property change notification machinery. It follows a pattern established in PreferencesAPI and the PreferenceEventRouter. * Given a list of preferences, register event listener added observers to each preference. * On the first added event listener, unregister all observers and register all property change listeners. * On property changes, forward an event to each component extension that has a property listener added. BUG=164227 Review URL: https://chromiumcodereview.appspot.com/18100007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/preference/chrome_direct_setting_api.h')
-rw-r--r--chrome/browser/extensions/api/preference/chrome_direct_setting_api.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/preference/chrome_direct_setting_api.h b/chrome/browser/extensions/api/preference/chrome_direct_setting_api.h
new file mode 100644
index 0000000..0fd6207
--- /dev/null
+++ b/chrome/browser/extensions/api/preference/chrome_direct_setting_api.h
@@ -0,0 +1,60 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_API_H__
+#define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_API_H__
+
+#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
+#include "chrome/browser/extensions/event_router.h"
+
+class PrefChangeRegistrar;
+class Profile;
+
+namespace extensions {
+namespace chromedirectsetting {
+
+class ChromeDirectSettingAPI : public ProfileKeyedAPI,
+ public EventRouter::Observer {
+ public:
+ explicit ChromeDirectSettingAPI(Profile* profile);
+
+ virtual ~ChromeDirectSettingAPI();
+
+ // BrowserContextKeyedService implementation.
+ virtual void Shutdown() OVERRIDE;
+
+ // ProfileKeyedAPI implementation.
+ static ProfileKeyedAPIFactory<ChromeDirectSettingAPI>* GetFactoryInstance();
+
+ // EventRouter::Observer implementation.
+ virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
+
+ // Returns true if the preference is on the whitelist.
+ bool IsPreferenceOnWhitelist(const std::string& pref_key);
+
+ // Convenience method to get the ChromeDirectSettingAPI for a profile.
+ static ChromeDirectSettingAPI* Get(Profile* profile);
+
+ private:
+ friend class ProfileKeyedAPIFactory<ChromeDirectSettingAPI>;
+
+ // ProfileKeyedAPI implementation.
+ static const char* service_name();
+
+ void OnPrefChanged(PrefService* pref_service, const std::string& pref_key);
+
+ static const bool kServiceIsNULLWhileTesting = true;
+ static const bool kServiceRedirectedInIncognito = false;
+
+ PrefChangeRegistrar registrar_;
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeDirectSettingAPI);
+};
+
+} // namespace chromedirectsetting
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_API_H__
+