summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefs/pref_change_registrar.h
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 13:55:18 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 13:55:18 +0000
commit492d214950b16d229ced62021486e9e0ec859e40 (patch)
treeac098e0dc234b894433b13d409ddb198cd9d24b1 /chrome/browser/prefs/pref_change_registrar.h
parent0ef5163fe4f9a76f516f09f7aa9d19c322e79691 (diff)
downloadchromium_src-492d214950b16d229ced62021486e9e0ec859e40.zip
chromium_src-492d214950b16d229ced62021486e9e0ec859e40.tar.gz
chromium_src-492d214950b16d229ced62021486e9e0ec859e40.tar.bz2
Policy: plugins disabled by policy should honor policy changes without Chrome relaunch.
BUG=54620 TEST=PrefChangeRegistrarTest.* Review URL: http://codereview.chromium.org/3316007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs/pref_change_registrar.h')
-rw-r--r--chrome/browser/prefs/pref_change_registrar.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/chrome/browser/prefs/pref_change_registrar.h b/chrome/browser/prefs/pref_change_registrar.h
new file mode 100644
index 0000000..cd8f5eb
--- /dev/null
+++ b/chrome/browser/prefs/pref_change_registrar.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2010 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_PREFS_PREF_CHANGE_REGISTRAR_H_
+#define CHROME_BROWSER_PREFS_PREF_CHANGE_REGISTRAR_H_
+#pragma once
+
+#include <set>
+#include <string>
+
+#include "base/basictypes.h"
+
+class PrefService;
+class NotificationObserver;
+
+// Automatically manages the registration of one or more pref change observers
+// with a PrefStore. Functions much like NotificationRegistrar, but specifically
+// manages observers of preference changes. When the Registrar is destroyed,
+// all registered observers are automatically unregistered with the PrefStore.
+class PrefChangeRegistrar {
+ public:
+ PrefChangeRegistrar();
+ virtual ~PrefChangeRegistrar();
+
+ // Must be called before adding or removing observers.
+ void Init(PrefService* service);
+
+ // Adds an pref observer for the specified pref |path| and |obs| observer
+ // object. All registered observers will be automatically unregistered
+ // when the registrar's destructor is called unless the observer has been
+ // explicitly removed by a call to Remove beforehand.
+ void Add(const char* path,
+ NotificationObserver* obs);
+
+ // Removes a preference observer that has previously been added with a call to
+ // Add.
+ void Remove(const char* path,
+ NotificationObserver* obs);
+
+ private:
+ typedef std::pair<std::string, NotificationObserver*> ObserverRegistration;
+
+ std::set<ObserverRegistration> observers_;
+ PrefService* service_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefChangeRegistrar);
+};
+
+#endif // CHROME_BROWSER_PREFS_PREF_CHANGE_REGISTRAR_H_