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 "base/prefs/public/pref_change_registrar.h" | 5 #include "base/prefs/public/pref_change_registrar.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/public/pref_service_base.h" | 8 #include "base/prefs/public/pref_service_base.h" |
9 | 9 |
10 PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} | 10 PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} |
11 | 11 |
12 PrefChangeRegistrar::~PrefChangeRegistrar() { | 12 PrefChangeRegistrar::~PrefChangeRegistrar() { |
13 // If you see an invalid memory access in this destructor, this | 13 // If you see an invalid memory access in this destructor, this |
14 // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that | 14 // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that |
15 // has been destroyed. This should not happen any more but be warned. | 15 // has been destroyed. This should not happen any more but be warned. |
16 // Feel free to contact battre@chromium.org in case this happens. | 16 // Feel free to contact battre@chromium.org in case this happens. |
17 RemoveAll(); | 17 RemoveAll(); |
18 } | 18 } |
19 | 19 |
20 void PrefChangeRegistrar::Init(PrefServiceBase* service) { | 20 void PrefChangeRegistrar::Init(PrefServiceBase* service) { |
21 DCHECK(IsEmpty() || service_ == service); | 21 DCHECK(IsEmpty() || service_ == service); |
22 service_ = service; | 22 service_ = service; |
23 } | 23 } |
24 | 24 |
25 void PrefChangeRegistrar::Add(const char* path, | 25 void PrefChangeRegistrar::Add(const char* path, PrefObserver* obs) { |
26 content::NotificationObserver* obs) { | |
27 if (!service_) { | 26 if (!service_) { |
28 NOTREACHED(); | 27 NOTREACHED(); |
29 return; | 28 return; |
30 } | 29 } |
31 ObserverRegistration registration(path, obs); | 30 ObserverRegistration registration(path, obs); |
32 if (observers_.find(registration) != observers_.end()) { | 31 if (observers_.find(registration) != observers_.end()) { |
33 NOTREACHED(); | 32 NOTREACHED(); |
34 return; | 33 return; |
35 } | 34 } |
36 observers_.insert(registration); | 35 observers_.insert(registration); |
37 service_->AddPrefObserver(path, obs); | 36 service_->AddPrefObserver(path, obs); |
38 } | 37 } |
39 | 38 |
40 void PrefChangeRegistrar::Remove(const char* path, | 39 void PrefChangeRegistrar::Remove(const char* path, PrefObserver* obs) { |
41 content::NotificationObserver* obs) { | |
42 if (!service_) { | 40 if (!service_) { |
43 NOTREACHED(); | 41 NOTREACHED(); |
44 return; | 42 return; |
45 } | 43 } |
46 ObserverRegistration registration(path, obs); | 44 ObserverRegistration registration(path, obs); |
47 std::set<ObserverRegistration>::iterator it = | 45 std::set<ObserverRegistration>::iterator it = |
48 observers_.find(registration); | 46 observers_.find(registration); |
49 if (it == observers_.end()) { | 47 if (it == observers_.end()) { |
50 NOTREACHED(); | 48 NOTREACHED(); |
51 return; | 49 return; |
(...skipping 28 matching lines...) Expand all Loading... |
80 bool PrefChangeRegistrar::IsManaged() { | 78 bool PrefChangeRegistrar::IsManaged() { |
81 for (std::set<ObserverRegistration>::const_iterator it = observers_.begin(); | 79 for (std::set<ObserverRegistration>::const_iterator it = observers_.begin(); |
82 it != observers_.end(); ++it) { | 80 it != observers_.end(); ++it) { |
83 const PrefServiceBase::Preference* pref = | 81 const PrefServiceBase::Preference* pref = |
84 service_->FindPreference(it->first.c_str()); | 82 service_->FindPreference(it->first.c_str()); |
85 if (pref && pref->IsManaged()) | 83 if (pref && pref->IsManaged()) |
86 return true; | 84 return true; |
87 } | 85 } |
88 return false; | 86 return false; |
89 } | 87 } |
OLD | NEW |