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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/hash_tables.h"
12 #include "base/non_thread_safe.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/prefs/pref_notifier.h"
15
16 class PrefService;
17 class NotificationObserver;
18
19 // The PrefNotifier implementation used by the PrefService.
20 class PrefNotifierImpl : public PrefNotifier,
21 public NonThreadSafe {
22 public:
23 explicit PrefNotifierImpl(PrefService* pref_service);
24 virtual ~PrefNotifierImpl();
25
26 // If the pref at the given path changes, we call the observer's Observe
27 // method with PREF_CHANGED.
28 void AddPrefObserver(const char* path, NotificationObserver* obs);
29 void RemovePrefObserver(const char* path, NotificationObserver* obs);
30
31 // PrefNotifier overrides.
32 virtual void OnPreferenceChanged(const std::string& pref_name);
33 virtual void OnInitializationCompleted();
34
35 protected:
36 // A map from pref names to a list of observers. Observers get fired in the
37 // order they are added. These should only be accessed externally for unit
38 // testing.
39 typedef ObserverList<NotificationObserver> NotificationObserverList;
40 typedef base::hash_map<std::string, NotificationObserverList*>
41 PrefObserverMap;
42
43 const PrefObserverMap* pref_observers() const { return &pref_observers_; }
44
45 private:
46 // For the given pref_name, fire any observer of the pref. Virtual so it can
47 // be mocked for unit testing.
48 virtual void FireObservers(const std::string& path);
49
50 // Weak reference; the notifier is owned by the PrefService.
51 PrefService* pref_service_;
52
53 PrefObserverMap pref_observers_;
54
55 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl);
56 };
57
58 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
OLDNEW
« 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