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/pref_change_registrar.h" | 5 #include "base/prefs/pref_change_registrar.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 // TODO(battre): Delete this. See crbug.com/373435. |
| 9 #include "base/debug/alias.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
10 | 12 |
11 PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} | 13 PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} |
12 | 14 |
13 PrefChangeRegistrar::~PrefChangeRegistrar() { | 15 PrefChangeRegistrar::~PrefChangeRegistrar() { |
14 // If you see an invalid memory access in this destructor, this | 16 // If you see an invalid memory access in this destructor, this |
15 // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that | 17 // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that |
16 // has been destroyed. This should not happen any more but be warned. | 18 // has been destroyed. This should not happen any more but be warned. |
17 // Feel free to contact battre@chromium.org in case this happens. | 19 // Feel free to contact battre@chromium.org in case this happens. |
(...skipping 23 matching lines...) Expand all Loading... |
41 } | 43 } |
42 | 44 |
43 void PrefChangeRegistrar::Remove(const char* path) { | 45 void PrefChangeRegistrar::Remove(const char* path) { |
44 DCHECK(IsObserved(path)); | 46 DCHECK(IsObserved(path)); |
45 | 47 |
46 observers_.erase(path); | 48 observers_.erase(path); |
47 service_->RemovePrefObserver(path, this); | 49 service_->RemovePrefObserver(path, this); |
48 } | 50 } |
49 | 51 |
50 void PrefChangeRegistrar::RemoveAll() { | 52 void PrefChangeRegistrar::RemoveAll() { |
| 53 // TODO(battre): Delete this. See crbug.com/373435. |
| 54 if (!observers_.empty() && !pref_service_destruction_.empty()) { |
| 55 // The PrefService is already destroyed, so the following call to |
| 56 // service_->RemovePrefObserver would crash anyway. When the PrefService |
| 57 // was destroyed, it stored a stack trace of the destruction in |
| 58 // pref_service_destruction_. We save this on the stack in the minidump to |
| 59 // understand what happens. |
| 60 char tmp[2048] = {}; |
| 61 strncat(tmp, pref_service_destruction_.c_str(), sizeof(tmp) - 1u); |
| 62 base::debug::Alias(tmp); |
| 63 CHECK(false) << tmp; |
| 64 } |
| 65 |
51 for (ObserverMap::const_iterator it = observers_.begin(); | 66 for (ObserverMap::const_iterator it = observers_.begin(); |
52 it != observers_.end(); ++it) { | 67 it != observers_.end(); ++it) { |
53 service_->RemovePrefObserver(it->first.c_str(), this); | 68 service_->RemovePrefObserver(it->first.c_str(), this); |
54 } | 69 } |
55 | 70 |
56 observers_.clear(); | 71 observers_.clear(); |
57 } | 72 } |
58 | 73 |
59 bool PrefChangeRegistrar::IsEmpty() const { | 74 bool PrefChangeRegistrar::IsEmpty() const { |
60 return observers_.empty(); | 75 return observers_.empty(); |
(...skipping 13 matching lines...) Expand all Loading... |
74 } | 89 } |
75 return false; | 90 return false; |
76 } | 91 } |
77 | 92 |
78 void PrefChangeRegistrar::OnPreferenceChanged(PrefService* service, | 93 void PrefChangeRegistrar::OnPreferenceChanged(PrefService* service, |
79 const std::string& pref) { | 94 const std::string& pref) { |
80 if (IsObserved(pref)) | 95 if (IsObserved(pref)) |
81 observers_[pref].Run(pref); | 96 observers_[pref].Run(pref); |
82 } | 97 } |
83 | 98 |
| 99 // TODO(battre): Delete this. See crbug.com/373435. |
| 100 void PrefChangeRegistrar::SetPrefServiceDestructionTrace( |
| 101 const std::string& stack_trace) { |
| 102 pref_service_destruction_ = stack_trace; |
| 103 } |
| 104 |
84 void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback, | 105 void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback, |
85 const std::string& pref_name) { | 106 const std::string& pref_name) { |
86 callback.Run(); | 107 callback.Run(); |
87 } | 108 } |
88 | 109 |
89 PrefService* PrefChangeRegistrar::prefs() { | 110 PrefService* PrefChangeRegistrar::prefs() { |
90 return service_; | 111 return service_; |
91 } | 112 } |
92 | 113 |
93 const PrefService* PrefChangeRegistrar::prefs() const { | 114 const PrefService* PrefChangeRegistrar::prefs() const { |
94 return service_; | 115 return service_; |
95 } | 116 } |
OLD | NEW |