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/speech/chrome_speech_recognition_preferences.h" | 5 #include "chrome/browser/speech/chrome_speech_recognition_preferences.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 ChromeSpeechRecognitionPreferences::Service::Service( | 91 ChromeSpeechRecognitionPreferences::Service::Service( |
92 Profile* profile) | 92 Profile* profile) |
93 : preferences_(new ChromeSpeechRecognitionPreferences(profile)) { | 93 : preferences_(new ChromeSpeechRecognitionPreferences(profile)) { |
94 } | 94 } |
95 | 95 |
96 ChromeSpeechRecognitionPreferences::Service::~Service() { | 96 ChromeSpeechRecognitionPreferences::Service::~Service() { |
97 } | 97 } |
98 | 98 |
99 void ChromeSpeechRecognitionPreferences::Service::Shutdown() { | 99 void ChromeSpeechRecognitionPreferences::Service::Shutdown() { |
100 DCHECK(preferences_); | 100 DCHECK(preferences_.get()); |
101 preferences_->DetachFromProfile(); | 101 preferences_->DetachFromProfile(); |
102 } | 102 } |
103 | 103 |
104 scoped_refptr<ChromeSpeechRecognitionPreferences> | 104 scoped_refptr<ChromeSpeechRecognitionPreferences> |
105 ChromeSpeechRecognitionPreferences::Service::GetPreferences() const { | 105 ChromeSpeechRecognitionPreferences::Service::GetPreferences() const { |
106 return preferences_; | 106 return preferences_; |
107 } | 107 } |
108 | 108 |
109 scoped_refptr<ChromeSpeechRecognitionPreferences> | 109 scoped_refptr<ChromeSpeechRecognitionPreferences> |
110 ChromeSpeechRecognitionPreferences::GetForProfile(Profile* profile) { | 110 ChromeSpeechRecognitionPreferences::GetForProfile(Profile* profile) { |
111 scoped_refptr<ChromeSpeechRecognitionPreferences> ret; | 111 scoped_refptr<ChromeSpeechRecognitionPreferences> ret; |
112 if (profile) { | 112 if (profile) { |
113 // Note that when in incognito, GetForProfile will return NULL. | 113 // Note that when in incognito, GetForProfile will return NULL. |
114 // We catch that case below and return the default preferences. | 114 // We catch that case below and return the default preferences. |
115 ret = Factory::GetInstance()->GetForProfile(profile); | 115 ret = Factory::GetInstance()->GetForProfile(profile); |
116 } | 116 } |
117 | 117 |
118 if (!ret) { | 118 if (!ret.get()) { |
119 // Create a detached preferences object if no profile is provided. | 119 // Create a detached preferences object if no profile is provided. |
120 ret = new ChromeSpeechRecognitionPreferences(NULL); | 120 ret = new ChromeSpeechRecognitionPreferences(NULL); |
121 } | 121 } |
122 | 122 |
123 return ret; | 123 return ret; |
124 } | 124 } |
125 | 125 |
126 ChromeSpeechRecognitionPreferences::ChromeSpeechRecognitionPreferences( | 126 ChromeSpeechRecognitionPreferences::ChromeSpeechRecognitionPreferences( |
127 Profile* profile) | 127 Profile* profile) |
128 : profile_(profile), | 128 : profile_(profile), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 prefs::kSpeechRecognitionFilterProfanities); | 210 prefs::kSpeechRecognitionFilterProfanities); |
211 } | 211 } |
212 | 212 |
213 void ChromeSpeechRecognitionPreferences::ReloadNotificationsShown() { | 213 void ChromeSpeechRecognitionPreferences::ReloadNotificationsShown() { |
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
215 base::AutoLock write_lock(preferences_lock_); | 215 base::AutoLock write_lock(preferences_lock_); |
216 const base::ListValue* pref_list = profile_->GetPrefs()->GetList( | 216 const base::ListValue* pref_list = profile_->GetPrefs()->GetList( |
217 prefs::kSpeechRecognitionTrayNotificationShownContexts); | 217 prefs::kSpeechRecognitionTrayNotificationShownContexts); |
218 notifications_shown_.reset(pref_list->DeepCopy()); | 218 notifications_shown_.reset(pref_list->DeepCopy()); |
219 } | 219 } |
OLD | NEW |