OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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."; | |
40 | 39 |
41 // Add ourselves as a pref observer so we can keep our local value in sync. | 40 // Add ourselves as a pref observer so we can keep our local value in sync. |
42 prefs_->AddPrefObserver(pref_name, this); | 41 prefs_->AddPrefObserver(pref_name, this); |
43 } | 42 } |
44 | 43 |
45 void PrefMemberBase::Destroy() { | 44 void PrefMemberBase::Destroy() { |
46 if (prefs_ && !pref_name_.empty()) { | 45 if (prefs_ && !pref_name_.empty()) { |
47 prefs_->RemovePrefObserver(pref_name_.c_str(), this); | 46 prefs_->RemovePrefObserver(pref_name_.c_str(), this); |
48 prefs_ = NULL; | 47 prefs_ = NULL; |
49 } | 48 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 template <> | 162 template <> |
164 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { | 163 void PrefMember<FilePath>::UpdatePref(const FilePath& value) { |
165 prefs()->SetFilePath(pref_name().c_str(), value); | 164 prefs()->SetFilePath(pref_name().c_str(), value); |
166 } | 165 } |
167 | 166 |
168 template <> | 167 template <> |
169 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) | 168 bool PrefMember<FilePath>::Internal::UpdateValueInternal(const Value& value) |
170 const { | 169 const { |
171 return base::GetValueAsFilePath(value, &value_); | 170 return base::GetValueAsFilePath(value, &value_); |
172 } | 171 } |
OLD | NEW |