| 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 <utility> |
| 8 |
| 7 #include "base/callback.h" | 9 #include "base/callback.h" |
| 8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.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/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/value_conversions.h" | 14 #include "base/value_conversions.h" |
| 13 | 15 |
| 14 using base::SingleThreadTaskRunner; | 16 using base::SingleThreadTaskRunner; |
| 15 | 17 |
| 16 namespace subtle { | 18 namespace subtle { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 prefs_ = NULL; | 51 prefs_ = NULL; |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 void PrefMemberBase::MoveToThread( | 55 void PrefMemberBase::MoveToThread( |
| 54 scoped_refptr<SingleThreadTaskRunner> task_runner) { | 56 scoped_refptr<SingleThreadTaskRunner> task_runner) { |
| 55 VerifyValuePrefName(); | 57 VerifyValuePrefName(); |
| 56 // Load the value from preferences if it hasn't been loaded so far. | 58 // Load the value from preferences if it hasn't been loaded so far. |
| 57 if (!internal()) | 59 if (!internal()) |
| 58 UpdateValueFromPref(base::Closure()); | 60 UpdateValueFromPref(base::Closure()); |
| 59 internal()->MoveToThread(task_runner.Pass()); | 61 internal()->MoveToThread(std::move(task_runner)); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void PrefMemberBase::OnPreferenceChanged(PrefService* service, | 64 void PrefMemberBase::OnPreferenceChanged(PrefService* service, |
| 63 const std::string& pref_name) { | 65 const std::string& pref_name) { |
| 64 VerifyValuePrefName(); | 66 VerifyValuePrefName(); |
| 65 UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ? | 67 UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ? |
| 66 base::Bind(observer_, pref_name) : base::Closure()); | 68 base::Bind(observer_, pref_name) : base::Closure()); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const { | 71 void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 FROM_HERE, base::Bind(&PrefMemberBase::Internal::UpdateValue, this, | 119 FROM_HERE, base::Bind(&PrefMemberBase::Internal::UpdateValue, this, |
| 118 value.release(), is_managed, is_user_modifiable, | 120 value.release(), is_managed, is_user_modifiable, |
| 119 closure_runner.Release())); | 121 closure_runner.Release())); |
| 120 DCHECK(may_run); | 122 DCHECK(may_run); |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 124 void PrefMemberBase::Internal::MoveToThread( | 126 void PrefMemberBase::Internal::MoveToThread( |
| 125 scoped_refptr<SingleThreadTaskRunner> task_runner) { | 127 scoped_refptr<SingleThreadTaskRunner> task_runner) { |
| 126 CheckOnCorrectThread(); | 128 CheckOnCorrectThread(); |
| 127 thread_task_runner_ = task_runner.Pass(); | 129 thread_task_runner_ = std::move(task_runner); |
| 128 } | 130 } |
| 129 | 131 |
| 130 bool PrefMemberVectorStringUpdate(const base::Value& value, | 132 bool PrefMemberVectorStringUpdate(const base::Value& value, |
| 131 std::vector<std::string>* string_vector) { | 133 std::vector<std::string>* string_vector) { |
| 132 if (!value.IsType(base::Value::TYPE_LIST)) | 134 if (!value.IsType(base::Value::TYPE_LIST)) |
| 133 return false; | 135 return false; |
| 134 const base::ListValue* list = static_cast<const base::ListValue*>(&value); | 136 const base::ListValue* list = static_cast<const base::ListValue*>(&value); |
| 135 | 137 |
| 136 std::vector<std::string> local_vector; | 138 std::vector<std::string> local_vector; |
| 137 for (base::ListValue::const_iterator it = list->begin(); | 139 for (base::ListValue::const_iterator it = list->begin(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 base::ListValue list_value; | 214 base::ListValue list_value; |
| 213 list_value.AppendStrings(value); | 215 list_value.AppendStrings(value); |
| 214 prefs()->Set(pref_name(), list_value); | 216 prefs()->Set(pref_name(), list_value); |
| 215 } | 217 } |
| 216 | 218 |
| 217 template <> | 219 template <> |
| 218 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( | 220 bool PrefMember<std::vector<std::string> >::Internal::UpdateValueInternal( |
| 219 const base::Value& value) const { | 221 const base::Value& value) const { |
| 220 return subtle::PrefMemberVectorStringUpdate(value, &value_); | 222 return subtle::PrefMemberVectorStringUpdate(value, &value_); |
| 221 } | 223 } |
| OLD | NEW |