OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/prefs/pref_set_observer.h" | 5 #include "chrome/browser/prefs/pref_set_observer.h" |
6 | 6 |
7 #include "chrome/common/notification_type.h" | 7 #include "chrome/common/notification_type.h" |
8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
9 | 9 |
10 PrefSetObserver::PrefSetObserver(PrefService* pref_service, | 10 PrefSetObserver::PrefSetObserver(PrefService* pref_service, |
11 NotificationObserver* observer) | 11 NotificationObserver* observer) |
12 : pref_service_(pref_service), | 12 : pref_service_(pref_service), |
13 observer_(observer) { | 13 observer_(observer) { |
14 registrar_.Init(pref_service); | 14 registrar_.Init(pref_service); |
15 } | 15 } |
16 | 16 |
| 17 PrefSetObserver::~PrefSetObserver() {} |
| 18 |
17 void PrefSetObserver::AddPref(const std::string& pref) { | 19 void PrefSetObserver::AddPref(const std::string& pref) { |
18 if (!prefs_.count(pref) && pref_service_->FindPreference(pref.c_str())) { | 20 if (!prefs_.count(pref) && pref_service_->FindPreference(pref.c_str())) { |
19 prefs_.insert(pref); | 21 prefs_.insert(pref); |
20 registrar_.Add(pref.c_str(), this); | 22 registrar_.Add(pref.c_str(), this); |
21 } | 23 } |
22 } | 24 } |
23 | 25 |
24 void PrefSetObserver::RemovePref(const std::string& pref) { | 26 void PrefSetObserver::RemovePref(const std::string& pref) { |
25 if (prefs_.erase(pref)) | 27 if (prefs_.erase(pref)) |
26 registrar_.Remove(pref.c_str(), this); | 28 registrar_.Remove(pref.c_str(), this); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 71 |
70 return pref_set; | 72 return pref_set; |
71 } | 73 } |
72 | 74 |
73 void PrefSetObserver::Observe(NotificationType type, | 75 void PrefSetObserver::Observe(NotificationType type, |
74 const NotificationSource& source, | 76 const NotificationSource& source, |
75 const NotificationDetails& details) { | 77 const NotificationDetails& details) { |
76 if (observer_) | 78 if (observer_) |
77 observer_->Observe(type, source, details); | 79 observer_->Observe(type, source, details); |
78 } | 80 } |
OLD | NEW |