| 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 "chrome/browser/api/prefs/pref_member.h" | 5 #include "chrome/browser/api/prefs/pref_member.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/value_conversions.h" | 9 #include "base/value_conversions.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/api/prefs/pref_service_base.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 | 12 |
| 13 using content::BrowserThread; | 13 using content::BrowserThread; |
| 14 | 14 |
| 15 namespace subtle { | 15 namespace subtle { |
| 16 | 16 |
| 17 PrefMemberBase::PrefMemberBase() | 17 PrefMemberBase::PrefMemberBase() |
| 18 : observer_(NULL), | 18 : observer_(NULL), |
| 19 prefs_(NULL), | 19 prefs_(NULL), |
| 20 setting_value_(false) { | 20 setting_value_(false) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 PrefMemberBase::~PrefMemberBase() { | 23 PrefMemberBase::~PrefMemberBase() { |
| 24 Destroy(); | 24 Destroy(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 void PrefMemberBase::Init(const char* pref_name, | 28 void PrefMemberBase::Init(const char* pref_name, |
| 29 PrefService* prefs, | 29 PrefServiceBase* prefs, |
| 30 content::NotificationObserver* observer) { | 30 content::NotificationObserver* observer) { |
| 31 DCHECK(pref_name); | 31 DCHECK(pref_name); |
| 32 DCHECK(prefs); | 32 DCHECK(prefs); |
| 33 DCHECK(pref_name_.empty()); // Check that Init is only called once. | 33 DCHECK(pref_name_.empty()); // Check that Init is only called once. |
| 34 observer_ = observer; | 34 observer_ = observer; |
| 35 prefs_ = prefs; | 35 prefs_ = prefs; |
| 36 pref_name_ = pref_name; | 36 pref_name_ = pref_name; |
| 37 // Check that the preference is registered. | 37 // Check that the preference is registered. |
| 38 DCHECK(prefs_->FindPreference(pref_name_.c_str())) | 38 DCHECK(prefs_->FindPreference(pref_name_.c_str())) |
| 39 << pref_name << " not registered."; | 39 << pref_name << " not registered."; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 62 const content::NotificationDetails& details) { | 62 const content::NotificationDetails& details) { |
| 63 VerifyValuePrefName(); | 63 VerifyValuePrefName(); |
| 64 DCHECK(chrome::NOTIFICATION_PREF_CHANGED == type); | 64 DCHECK(chrome::NOTIFICATION_PREF_CHANGED == type); |
| 65 UpdateValueFromPref(); | 65 UpdateValueFromPref(); |
| 66 if (!setting_value_ && observer_) | 66 if (!setting_value_ && observer_) |
| 67 observer_->Observe(type, source, details); | 67 observer_->Observe(type, source, details); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void PrefMemberBase::UpdateValueFromPref() const { | 70 void PrefMemberBase::UpdateValueFromPref() const { |
| 71 VerifyValuePrefName(); | 71 VerifyValuePrefName(); |
| 72 const PrefService::Preference* pref = | 72 const PrefServiceBase::Preference* pref = |
| 73 prefs_->FindPreference(pref_name_.c_str()); | 73 prefs_->FindPreference(pref_name_.c_str()); |
| 74 DCHECK(pref); | 74 DCHECK(pref); |
| 75 if (!internal()) | 75 if (!internal()) |
| 76 CreateInternal(); | 76 CreateInternal(); |
| 77 internal()->UpdateValue(pref->GetValue()->DeepCopy(), pref->IsManaged()); | 77 internal()->UpdateValue(pref->GetValue()->DeepCopy(), pref->IsManaged()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void PrefMemberBase::VerifyPref() const { | 80 void PrefMemberBase::VerifyPref() const { |
| 81 VerifyValuePrefName(); | 81 VerifyValuePrefName(); |
| 82 if (!internal()) | 82 if (!internal()) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 template <> | 163 template <> |
| 164 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { | 164 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { |
| 165 prefs()->SetFilePath(pref_name().c_str(), value); | 165 prefs()->SetFilePath(pref_name().c_str(), value); |
| 166 } | 166 } |
| 167 | 167 |
| 168 template <> | 168 template <> |
| 169 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) | 169 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) |
| 170 const { | 170 const { |
| 171 return base::GetValueAsFilePath(value, &value_); | 171 return base::GetValueAsFilePath(value, &value_); |
| 172 } | 172 } |
| OLD | NEW |