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 #ifndef CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_ |
6 #define CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_ | 6 #define CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
| 13 #include "base/prefs/public/pref_observer.h" |
13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
14 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
15 #include "chrome/browser/profiles/profile_keyed_service.h" | 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
16 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 17 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/speech_recognition_preferences.h" | 18 #include "content/public/browser/speech_recognition_preferences.h" |
19 | 19 |
20 class PrefService; | 20 class PrefService; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class ListValue; | 23 class ListValue; |
24 } | 24 } |
25 | 25 |
26 // Utility class that handles persistent storage of speech recognition | 26 // Utility class that handles persistent storage of speech recognition |
27 // preferences. Instances of this class must be obtained exclusively through the | 27 // preferences. Instances of this class must be obtained exclusively through the |
28 // method ChromeSpeechRecognitionPreferences::GetForProfile(...), so that | 28 // method ChromeSpeechRecognitionPreferences::GetForProfile(...), so that |
29 // preferences are handled within the Profile (if not NULL). The internal | 29 // preferences are handled within the Profile (if not NULL). The internal |
30 // factory class also handles ownership and lifetime of the | 30 // factory class also handles ownership and lifetime of the |
31 // ChromeSpeechRecognitionPreferences instances (through the inner Service | 31 // ChromeSpeechRecognitionPreferences instances (through the inner Service |
32 // class), allowing them to be used in a detached mode (no persistent storage) | 32 // class), allowing them to be used in a detached mode (no persistent storage) |
33 // even when a Profile is not available (or has been shutdown). | 33 // even when a Profile is not available (or has been shutdown). |
34 | 34 |
35 class ChromeSpeechRecognitionPreferences | 35 class ChromeSpeechRecognitionPreferences |
36 : public content::SpeechRecognitionPreferences, | 36 : public content::SpeechRecognitionPreferences, |
37 public content::NotificationObserver { | 37 public PrefObserver { |
38 public: | 38 public: |
39 static void InitializeFactory(); | 39 static void InitializeFactory(); |
40 static scoped_refptr<ChromeSpeechRecognitionPreferences> GetForProfile( | 40 static scoped_refptr<ChromeSpeechRecognitionPreferences> GetForProfile( |
41 Profile* profile); | 41 Profile* profile); |
42 | 42 |
43 // content::NotificationObserver implementation. | 43 // PrefObserver implementation. |
44 virtual void Observe(int type, | 44 virtual void OnPreferenceChanged(PrefServiceBase* service, |
45 const content::NotificationSource& source, | 45 const std::string& pref_name) OVERRIDE; |
46 const content::NotificationDetails& details) OVERRIDE; | |
47 | 46 |
48 | 47 |
49 // content::SpeechRecognitionPreferences implementation. | 48 // content::SpeechRecognitionPreferences implementation. |
50 // Called by both Content (on IO thread) and Chrome (on UI thread). | 49 // Called by both Content (on IO thread) and Chrome (on UI thread). |
51 virtual bool FilterProfanities() const OVERRIDE; | 50 virtual bool FilterProfanities() const OVERRIDE; |
52 | 51 |
53 // Called only by Chrome (on UI thread). | 52 // Called only by Chrome (on UI thread). |
54 void SetFilterProfanities(bool filter_profanities); | 53 void SetFilterProfanities(bool filter_profanities); |
55 void ToggleFilterProfanities(); | 54 void ToggleFilterProfanities(); |
56 bool ShouldShowSecurityNotification(const std::string& context_name) const; | 55 bool ShouldShowSecurityNotification(const std::string& context_name) const; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 scoped_ptr<base::ListValue> notifications_shown_; | 119 scoped_ptr<base::ListValue> notifications_shown_; |
121 | 120 |
122 // Lock used to ensure exclusive access to preference variables that are | 121 // Lock used to ensure exclusive access to preference variables that are |
123 // accessed by both threads (note: mutable is required to keep getters const). | 122 // accessed by both threads (note: mutable is required to keep getters const). |
124 mutable base::Lock preferences_lock_; | 123 mutable base::Lock preferences_lock_; |
125 | 124 |
126 DISALLOW_COPY_AND_ASSIGN(ChromeSpeechRecognitionPreferences); | 125 DISALLOW_COPY_AND_ASSIGN(ChromeSpeechRecognitionPreferences); |
127 }; | 126 }; |
128 | 127 |
129 #endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_ | 128 #endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_ |
OLD | NEW |