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

Unified Diff: chrome/browser/prefs/pref_notifier_impl.h

Issue 5441002: Clean up pref change notification handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix extension prefs breakage Created 10 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/prefs/pref_notifier.cc ('k') | chrome/browser/prefs/pref_notifier_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/pref_notifier_impl.h
diff --git a/chrome/browser/prefs/pref_notifier_impl.h b/chrome/browser/prefs/pref_notifier_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..1d6183019ba041e631f2d7b3c285966ed2358550
--- /dev/null
+++ b/chrome/browser/prefs/pref_notifier_impl.h
@@ -0,0 +1,58 @@
+// 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_NOTIFIER_IMPL_H_
+#define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
+#pragma once
+
+#include <string>
+
+#include "base/hash_tables.h"
+#include "base/non_thread_safe.h"
+#include "base/observer_list.h"
+#include "chrome/browser/prefs/pref_notifier.h"
+
+class PrefService;
+class NotificationObserver;
+
+// The PrefNotifier implementation used by the PrefService.
+class PrefNotifierImpl : public PrefNotifier,
+ public NonThreadSafe {
+ public:
+ explicit PrefNotifierImpl(PrefService* pref_service);
+ virtual ~PrefNotifierImpl();
+
+ // If the pref at the given path changes, we call the observer's Observe
+ // method with PREF_CHANGED.
+ void AddPrefObserver(const char* path, NotificationObserver* obs);
+ void RemovePrefObserver(const char* path, NotificationObserver* obs);
+
+ // PrefNotifier overrides.
+ virtual void OnPreferenceChanged(const std::string& pref_name);
+ virtual void OnInitializationCompleted();
+
+ protected:
+ // A map from pref names to a list of observers. Observers get fired in the
+ // order they are added. These should only be accessed externally for unit
+ // testing.
+ typedef ObserverList<NotificationObserver> NotificationObserverList;
+ typedef base::hash_map<std::string, NotificationObserverList*>
+ PrefObserverMap;
+
+ const PrefObserverMap* pref_observers() const { return &pref_observers_; }
+
+ private:
+ // For the given pref_name, fire any observer of the pref. Virtual so it can
+ // be mocked for unit testing.
+ virtual void FireObservers(const std::string& path);
+
+ // Weak reference; the notifier is owned by the PrefService.
+ PrefService* pref_service_;
+
+ PrefObserverMap pref_observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl);
+};
+
+#endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
« no previous file with comments | « chrome/browser/prefs/pref_notifier.cc ('k') | chrome/browser/prefs/pref_notifier_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698