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

Side by Side Diff: chrome/browser/prefs/pref_notifier_impl.h

Issue 8568019: Introduce per-tab preferences service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ 5 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ 6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
14 #include "chrome/browser/prefs/pref_notifier.h" 14 #include "chrome/browser/prefs/pref_notifier.h"
15 15
16 class PrefModelAssociator;
16 class PrefService; 17 class PrefService;
17 18
18 namespace content { 19 namespace content {
19 class NotificationObserver; 20 class NotificationObserver;
20 } 21 }
21 22
22 // The PrefNotifier implementation used by the PrefService. 23 // The PrefNotifier implementation used by the PrefService.
23 class PrefNotifierImpl : public PrefNotifier, 24 class PrefNotifierImpl : public PrefNotifier,
24 public base::NonThreadSafe { 25 public base::NonThreadSafe {
25 public: 26 public:
26 explicit PrefNotifierImpl(PrefService* pref_service); 27 PrefNotifierImpl();
27 virtual ~PrefNotifierImpl(); 28 virtual ~PrefNotifierImpl();
28 29
30 void SetPrefModelAssociator(PrefModelAssociator* associator);
31 void SetPrefService(PrefService* pref_service);
32
29 // If the pref at the given path changes, we call the observer's Observe 33 // If the pref at the given path changes, we call the observer's Observe
30 // method with PREF_CHANGED. 34 // method with PREF_CHANGED.
31 void AddPrefObserver(const char* path, content::NotificationObserver* obs); 35 void AddPrefObserver(const char* path, content::NotificationObserver* obs);
32 void RemovePrefObserver(const char* path, content::NotificationObserver* obs); 36 void RemovePrefObserver(const char* path, content::NotificationObserver* obs);
33 37
34 // PrefNotifier overrides. 38 // PrefNotifier overrides.
35 virtual void OnPreferenceChanged(const std::string& pref_name); 39 virtual void OnPreferenceChanged(const std::string& pref_name);
36 virtual void OnInitializationCompleted(bool succeeded); 40 virtual void OnInitializationCompleted(bool succeeded);
37 41
38 protected: 42 protected:
39 // A map from pref names to a list of observers. Observers get fired in the 43 // A map from pref names to a list of observers. Observers get fired in the
40 // order they are added. These should only be accessed externally for unit 44 // order they are added. These should only be accessed externally for unit
41 // testing. 45 // testing.
42 typedef ObserverList<content::NotificationObserver> NotificationObserverList; 46 typedef ObserverList<content::NotificationObserver> NotificationObserverList;
43 typedef base::hash_map<std::string, NotificationObserverList*> 47 typedef base::hash_map<std::string, NotificationObserverList*>
44 PrefObserverMap; 48 PrefObserverMap;
45 49
46 const PrefObserverMap* pref_observers() const { return &pref_observers_; } 50 const PrefObserverMap* pref_observers() const { return &pref_observers_; }
47 51
48 private: 52 private:
49 // For the given pref_name, fire any observer of the pref. Virtual so it can 53 // For the given pref_name, fire any observer of the pref. Virtual so it can
50 // be mocked for unit testing. 54 // be mocked for unit testing.
51 virtual void FireObservers(const std::string& path); 55 virtual void FireObservers(const std::string& path);
52 56
53 // Weak reference; the notifier is owned by the PrefService. 57 // Weak reference; the notifier is owned by the PrefService.
54 PrefService* pref_service_; 58 PrefService* pref_service_;
55 59
60 PrefModelAssociator* pref_model_associator_;
61
56 PrefObserverMap pref_observers_; 62 PrefObserverMap pref_observers_;
57 63
58 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); 64 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl);
59 }; 65 };
60 66
61 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ 67 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698