OLD | NEW |
1 // Copyright (c) 2011 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/prefs/pref_member.h" | 5 #include "chrome/browser/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/prefs/pref_service.h" |
11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
(...skipping 16 matching lines...) Expand all Loading... |
28 void PrefMemberBase::Init(const char* pref_name, | 28 void PrefMemberBase::Init(const char* pref_name, |
29 PrefService* prefs, | 29 PrefService* 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 | 40 |
40 // Add ourselves as a pref observer so we can keep our local value in sync. | 41 // Add ourselves as a pref observer so we can keep our local value in sync. |
41 prefs_->AddPrefObserver(pref_name, this); | 42 prefs_->AddPrefObserver(pref_name, this); |
42 } | 43 } |
43 | 44 |
44 void PrefMemberBase::Destroy() { | 45 void PrefMemberBase::Destroy() { |
45 if (prefs_ && !pref_name_.empty()) { | 46 if (prefs_ && !pref_name_.empty()) { |
46 prefs_->RemovePrefObserver(pref_name_.c_str(), this); | 47 prefs_->RemovePrefObserver(pref_name_.c_str(), this); |
47 prefs_ = NULL; | 48 prefs_ = NULL; |
48 } | 49 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 template <> | 163 template <> |
163 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { | 164 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { |
164 prefs()->SetFilePath(pref_name().c_str(), value); | 165 prefs()->SetFilePath(pref_name().c_str(), value); |
165 } | 166 } |
166 | 167 |
167 template <> | 168 template <> |
168 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) | 169 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) |
169 const { | 170 const { |
170 return base::GetValueAsFilePath(value, &value_); | 171 return base::GetValueAsFilePath(value, &value_); |
171 } | 172 } |
OLD | NEW |