| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/public/pref_service_base.h" | 9 #include "base/prefs/public/pref_service_base.h" |
| 10 | 10 |
| 11 PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} | 11 PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} |
| 12 | 12 |
| 13 PrefChangeRegistrar::~PrefChangeRegistrar() { | 13 PrefChangeRegistrar::~PrefChangeRegistrar() { |
| 14 // If you see an invalid memory access in this destructor, this | 14 // If you see an invalid memory access in this destructor, this |
| 15 // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that | 15 // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that |
| 16 // has been destroyed. This should not happen any more but be warned. | 16 // has been destroyed. This should not happen any more but be warned. |
| 17 // Feel free to contact battre@chromium.org in case this happens. | 17 // Feel free to contact battre@chromium.org in case this happens. |
| 18 RemoveAll(); | 18 RemoveAll(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 void PrefChangeRegistrar::Init(PrefServiceBase* service) { | 21 void PrefChangeRegistrar::Init(PrefServiceBase* service) { |
| 22 DCHECK(IsEmpty() || service_ == service); | 22 DCHECK(IsEmpty() || service_ == service); |
| 23 service_ = service; | 23 service_ = service; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void PrefChangeRegistrar::Add(const char* path, PrefObserver* obs) { | |
| 27 DCHECK(obs); | |
| 28 return Add(path, base::Bind(&PrefObserver::OnPreferenceChanged, | |
| 29 base::Unretained(obs), service_)); | |
| 30 } | |
| 31 | |
| 32 void PrefChangeRegistrar::Add(const char* path, | 26 void PrefChangeRegistrar::Add(const char* path, |
| 33 const base::Closure& obs) { | 27 const base::Closure& obs) { |
| 34 Add(path, base::Bind(&PrefChangeRegistrar::InvokeUnnamedCallback, obs)); | 28 Add(path, base::Bind(&PrefChangeRegistrar::InvokeUnnamedCallback, obs)); |
| 35 } | 29 } |
| 36 | 30 |
| 37 void PrefChangeRegistrar::Add(const char* path, | 31 void PrefChangeRegistrar::Add(const char* path, |
| 38 const NamedChangeCallback& obs) { | 32 const NamedChangeCallback& obs) { |
| 39 if (!service_) { | 33 if (!service_) { |
| 40 NOTREACHED(); | 34 NOTREACHED(); |
| 41 return; | 35 return; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 82 } |
| 89 | 83 |
| 90 void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback, | 84 void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback, |
| 91 const std::string& pref_name) { | 85 const std::string& pref_name) { |
| 92 callback.Run(); | 86 callback.Run(); |
| 93 } | 87 } |
| 94 | 88 |
| 95 PrefServiceBase* PrefChangeRegistrar::prefs() { | 89 PrefServiceBase* PrefChangeRegistrar::prefs() { |
| 96 return service_; | 90 return service_; |
| 97 } | 91 } |
| OLD | NEW |