OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_member.h" | 5 #include "base/prefs/pref_member.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 // TODO(battre): Delete this. See crbug.com/373435. |
| 10 #include "base/debug/alias.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
11 #include "base/value_conversions.h" | 13 #include "base/value_conversions.h" |
12 | 14 |
13 using base::MessageLoopProxy; | 15 using base::MessageLoopProxy; |
14 | 16 |
15 namespace subtle { | 17 namespace subtle { |
16 | 18 |
17 PrefMemberBase::PrefMemberBase() | 19 PrefMemberBase::PrefMemberBase() |
18 : prefs_(NULL), | 20 : prefs_(NULL), |
(...skipping 21 matching lines...) Expand all Loading... |
40 // Check that the preference is registered. | 42 // Check that the preference is registered. |
41 DCHECK(prefs_->FindPreference(pref_name_.c_str())) | 43 DCHECK(prefs_->FindPreference(pref_name_.c_str())) |
42 << pref_name << " not registered."; | 44 << pref_name << " not registered."; |
43 | 45 |
44 // Add ourselves as a pref observer so we can keep our local value in sync. | 46 // Add ourselves as a pref observer so we can keep our local value in sync. |
45 prefs_->AddPrefObserver(pref_name, this); | 47 prefs_->AddPrefObserver(pref_name, this); |
46 } | 48 } |
47 | 49 |
48 void PrefMemberBase::Destroy() { | 50 void PrefMemberBase::Destroy() { |
49 if (prefs_ && !pref_name_.empty()) { | 51 if (prefs_ && !pref_name_.empty()) { |
| 52 // TODO(battre): Delete this. See crbug.com/373435. |
| 53 if (!pref_service_destruction_.empty()) { |
| 54 // The PrefService is already destroyed, so the following call to |
| 55 // service_->RemovePrefObserver would crash anyway. When the PrefService |
| 56 // was destroyed, it stored a stacktrack of the destruction in |
| 57 // pref_service_destruction_. We save this on the stack in the minidump to |
| 58 // understand what happens. |
| 59 char tmp[2048]; |
| 60 const int copy = |
| 61 std::min<int>(sizeof(tmp) - 1, pref_service_destruction_.length()); |
| 62 memcpy(tmp, pref_service_destruction_.c_str(), copy); |
| 63 tmp[copy] = '\0'; |
| 64 base::debug::Alias(tmp); |
| 65 CHECK(false) << tmp; |
| 66 } |
50 prefs_->RemovePrefObserver(pref_name_.c_str(), this); | 67 prefs_->RemovePrefObserver(pref_name_.c_str(), this); |
51 prefs_ = NULL; | 68 prefs_ = NULL; |
52 } | 69 } |
53 } | 70 } |
54 | 71 |
55 void PrefMemberBase::MoveToThread( | 72 void PrefMemberBase::MoveToThread( |
56 const scoped_refptr<MessageLoopProxy>& message_loop) { | 73 const scoped_refptr<MessageLoopProxy>& message_loop) { |
57 VerifyValuePrefName(); | 74 VerifyValuePrefName(); |
58 // Load the value from preferences if it hasn't been loaded so far. | 75 // Load the value from preferences if it hasn't been loaded so far. |
59 if (!internal()) | 76 if (!internal()) |
60 UpdateValueFromPref(base::Closure()); | 77 UpdateValueFromPref(base::Closure()); |
61 internal()->MoveToThread(message_loop); | 78 internal()->MoveToThread(message_loop); |
62 } | 79 } |
63 | 80 |
64 void PrefMemberBase::OnPreferenceChanged(PrefService* service, | 81 void PrefMemberBase::OnPreferenceChanged(PrefService* service, |
65 const std::string& pref_name) { | 82 const std::string& pref_name) { |
66 VerifyValuePrefName(); | 83 VerifyValuePrefName(); |
67 UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ? | 84 UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ? |
68 base::Bind(observer_, pref_name) : base::Closure()); | 85 base::Bind(observer_, pref_name) : base::Closure()); |
69 } | 86 } |
70 | 87 |
| 88 // TODO(battre): Delete this. See crbug.com/373435. |
| 89 void PrefMemberBase::SetPrefServiceDestructionTrace( |
| 90 const std::string& stacktrace) { |
| 91 pref_service_destruction_ = stacktrace; |
| 92 } |
| 93 |
71 void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const { | 94 void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const { |
72 VerifyValuePrefName(); | 95 VerifyValuePrefName(); |
73 const PrefService::Preference* pref = | 96 const PrefService::Preference* pref = |
74 prefs_->FindPreference(pref_name_.c_str()); | 97 prefs_->FindPreference(pref_name_.c_str()); |
75 DCHECK(pref); | 98 DCHECK(pref); |
76 if (!internal()) | 99 if (!internal()) |
77 CreateInternal(); | 100 CreateInternal(); |
78 internal()->UpdateValue(pref->GetValue()->DeepCopy(), | 101 internal()->UpdateValue(pref->GetValue()->DeepCopy(), |
79 pref->IsManaged(), | 102 pref->IsManaged(), |
80 pref->IsUserModifiable(), | 103 pref->IsUserModifiable(), |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 base::ListValue list_value; | 240 base::ListValue list_value; |
218 list_value.AppendStrings(value); | 241 list_value.AppendStrings(value); |
219 prefs()->Set(pref_name().c_str(), list_value); | 242 prefs()->Set(pref_name().c_str(), list_value); |
220 } | 243 } |
221 | 244 |
222 template <> | 245 template <> |
223 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( | 246 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( |
224 const base::Value& value) const { | 247 const base::Value& value) const { |
225 return subtle::PrefMemberVectorStringUpdate(value, &value_); | 248 return subtle::PrefMemberVectorStringUpdate(value, &value_); |
226 } | 249 } |
OLD | NEW |