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 | |
engedy
2014/05/16 15:19:58
nit: period to the end of the comment.
battre
2014/05/16 15:58:37
Done.
| |
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 stacktrack of the destruction in | |
engedy
2014/05/16 15:19:58
nit: s/stacktrack/stack trace
battre
2014/05/16 15:58:37
Done.
| |
58 // pref_service_destruction_. We save this on the stack in the minidump to | |
59 // understand what happens. | |
60 char tmp[2048]; | |
61 const int copy = | |
62 std::min<int>(sizeof(tmp) - 1, pref_service_destruction_.length()); | |
engedy
2014/05/16 15:19:58
Could we use strncat() here, like so:
char tmp[20
battre
2014/05/16 15:58:37
Done.
| |
63 memcpy(tmp, pref_service_destruction_.c_str(), copy); | |
64 tmp[copy] = '\0'; | |
65 base::debug::Alias(tmp); | |
66 CHECK(false) << tmp; | |
67 } | |
68 | |
51 for (ObserverMap::const_iterator it = observers_.begin(); | 69 for (ObserverMap::const_iterator it = observers_.begin(); |
52 it != observers_.end(); ++it) { | 70 it != observers_.end(); ++it) { |
53 service_->RemovePrefObserver(it->first.c_str(), this); | 71 service_->RemovePrefObserver(it->first.c_str(), this); |
54 } | 72 } |
55 | 73 |
56 observers_.clear(); | 74 observers_.clear(); |
57 } | 75 } |
58 | 76 |
59 bool PrefChangeRegistrar::IsEmpty() const { | 77 bool PrefChangeRegistrar::IsEmpty() const { |
60 return observers_.empty(); | 78 return observers_.empty(); |
(...skipping 13 matching lines...) Expand all Loading... | |
74 } | 92 } |
75 return false; | 93 return false; |
76 } | 94 } |
77 | 95 |
78 void PrefChangeRegistrar::OnPreferenceChanged(PrefService* service, | 96 void PrefChangeRegistrar::OnPreferenceChanged(PrefService* service, |
79 const std::string& pref) { | 97 const std::string& pref) { |
80 if (IsObserved(pref)) | 98 if (IsObserved(pref)) |
81 observers_[pref].Run(pref); | 99 observers_[pref].Run(pref); |
82 } | 100 } |
83 | 101 |
102 // TODO(battre): Delete this. See crbug.com/373435. | |
103 void PrefChangeRegistrar::SetPrefServiceDestructionTrace( | |
104 const std::string& stacktrace) { | |
engedy
2014/05/16 15:19:58
nit: stack_trace.
battre
2014/05/16 15:58:37
Done.
| |
105 pref_service_destruction_ = stacktrace; | |
106 } | |
107 | |
84 void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback, | 108 void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback, |
85 const std::string& pref_name) { | 109 const std::string& pref_name) { |
86 callback.Run(); | 110 callback.Run(); |
87 } | 111 } |
88 | 112 |
89 PrefService* PrefChangeRegistrar::prefs() { | 113 PrefService* PrefChangeRegistrar::prefs() { |
90 return service_; | 114 return service_; |
91 } | 115 } |
92 | 116 |
93 const PrefService* PrefChangeRegistrar::prefs() const { | 117 const PrefService* PrefChangeRegistrar::prefs() const { |
94 return service_; | 118 return service_; |
95 } | 119 } |
OLD | NEW |