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 stack trace 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 strncat(tmp, pref_service_destruction_.c_str(), sizeof(tmp) - 1u); |
| 61 base::debug::Alias(tmp); |
| 62 CHECK(false) << tmp; |
| 63 } |
50 prefs_->RemovePrefObserver(pref_name_.c_str(), this); | 64 prefs_->RemovePrefObserver(pref_name_.c_str(), this); |
51 prefs_ = NULL; | 65 prefs_ = NULL; |
52 } | 66 } |
53 } | 67 } |
54 | 68 |
55 void PrefMemberBase::MoveToThread( | 69 void PrefMemberBase::MoveToThread( |
56 const scoped_refptr<MessageLoopProxy>& message_loop) { | 70 const scoped_refptr<MessageLoopProxy>& message_loop) { |
57 VerifyValuePrefName(); | 71 VerifyValuePrefName(); |
58 // Load the value from preferences if it hasn't been loaded so far. | 72 // Load the value from preferences if it hasn't been loaded so far. |
59 if (!internal()) | 73 if (!internal()) |
60 UpdateValueFromPref(base::Closure()); | 74 UpdateValueFromPref(base::Closure()); |
61 internal()->MoveToThread(message_loop); | 75 internal()->MoveToThread(message_loop); |
62 } | 76 } |
63 | 77 |
64 void PrefMemberBase::OnPreferenceChanged(PrefService* service, | 78 void PrefMemberBase::OnPreferenceChanged(PrefService* service, |
65 const std::string& pref_name) { | 79 const std::string& pref_name) { |
66 VerifyValuePrefName(); | 80 VerifyValuePrefName(); |
67 UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ? | 81 UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ? |
68 base::Bind(observer_, pref_name) : base::Closure()); | 82 base::Bind(observer_, pref_name) : base::Closure()); |
69 } | 83 } |
70 | 84 |
| 85 // TODO(battre): Delete this. See crbug.com/373435. |
| 86 void PrefMemberBase::SetPrefServiceDestructionTrace( |
| 87 const std::string& stack_trace) { |
| 88 pref_service_destruction_ = stack_trace; |
| 89 } |
| 90 |
71 void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const { | 91 void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const { |
72 VerifyValuePrefName(); | 92 VerifyValuePrefName(); |
73 const PrefService::Preference* pref = | 93 const PrefService::Preference* pref = |
74 prefs_->FindPreference(pref_name_.c_str()); | 94 prefs_->FindPreference(pref_name_.c_str()); |
75 DCHECK(pref); | 95 DCHECK(pref); |
76 if (!internal()) | 96 if (!internal()) |
77 CreateInternal(); | 97 CreateInternal(); |
78 internal()->UpdateValue(pref->GetValue()->DeepCopy(), | 98 internal()->UpdateValue(pref->GetValue()->DeepCopy(), |
79 pref->IsManaged(), | 99 pref->IsManaged(), |
80 pref->IsUserModifiable(), | 100 pref->IsUserModifiable(), |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 base::ListValue list_value; | 237 base::ListValue list_value; |
218 list_value.AppendStrings(value); | 238 list_value.AppendStrings(value); |
219 prefs()->Set(pref_name().c_str(), list_value); | 239 prefs()->Set(pref_name().c_str(), list_value); |
220 } | 240 } |
221 | 241 |
222 template <> | 242 template <> |
223 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( | 243 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( |
224 const base::Value& value) const { | 244 const base::Value& value) const { |
225 return subtle::PrefMemberVectorStringUpdate(value, &value_); | 245 return subtle::PrefMemberVectorStringUpdate(value, &value_); |
226 } | 246 } |
OLD | NEW |