Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/search/hotword_service.h

Issue 1047973003: Notify hotwording extension of microphone state change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SEARCH_HOTWORD_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_ 6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/prefs/pref_change_registrar.h" 12 #include "base/prefs/pref_change_registrar.h"
13 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "chrome/browser/extensions/webstore_startup_installer.h" 14 #include "chrome/browser/extensions/webstore_startup_installer.h"
15 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
15 #include "chrome/common/extensions/webstore_install_result.h" 16 #include "chrome/common/extensions/webstore_install_result.h"
16 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
17 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
19 #include "extensions/browser/extension_registry.h" 20 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/extension_registry_observer.h" 21 #include "extensions/browser/extension_registry_observer.h"
21 22
22 class ExtensionService; 23 class ExtensionService;
23 class HotwordAudioHistoryHandler; 24 class HotwordAudioHistoryHandler;
24 class HotwordClient; 25 class HotwordClient;
25 class Profile; 26 class Profile;
26 27
27 namespace extensions { 28 namespace extensions {
28 class Extension; 29 class Extension;
29 } // namespace extensions 30 } // namespace extensions
30 31
31 namespace hotword_internal { 32 namespace hotword_internal {
32 // Constants for the hotword field trial. 33 // Constants for the hotword field trial.
33 extern const char kHotwordFieldTrialName[]; 34 extern const char kHotwordFieldTrialName[];
34 extern const char kHotwordFieldTrialDisabledGroupName[]; 35 extern const char kHotwordFieldTrialDisabledGroupName[];
35 // String passed to indicate the training state has changed. 36 // String passed to indicate the training state has changed.
36 extern const char kHotwordTrainingEnabled[]; 37 extern const char kHotwordTrainingEnabled[];
37 } // namespace hotword_internal 38 } // namespace hotword_internal
38 39
39 // Provides an interface for the Hotword component that does voice triggered 40 // Provides an interface for the Hotword component that does voice triggered
40 // search. 41 // search.
41 class HotwordService : public extensions::ExtensionRegistryObserver, 42 class HotwordService : public MediaCaptureDevicesDispatcher::Observer,
43 public extensions::ExtensionRegistryObserver,
42 public KeyedService { 44 public KeyedService {
43 public: 45 public:
44 // A simple subclass to allow for aborting an install during shutdown. 46 // A simple subclass to allow for aborting an install during shutdown.
45 // HotwordWebstoreInstaller class is public for testing. 47 // HotwordWebstoreInstaller class is public for testing.
46 class HotwordWebstoreInstaller : public extensions::WebstoreStartupInstaller { 48 class HotwordWebstoreInstaller : public extensions::WebstoreStartupInstaller {
47 public: 49 public:
48 HotwordWebstoreInstaller(const std::string& webstore_item_id, 50 HotwordWebstoreInstaller(const std::string& webstore_item_id,
49 Profile* profile, 51 Profile* profile,
50 const Callback& callback) 52 const Callback& callback)
51 : extensions::WebstoreStartupInstaller(webstore_item_id, 53 : extensions::WebstoreStartupInstaller(webstore_item_id,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 virtual bool UninstallHotwordExtension(ExtensionService* extension_service); 120 virtual bool UninstallHotwordExtension(ExtensionService* extension_service);
119 virtual void InstallHotwordExtensionFromWebstore(int num_tries); 121 virtual void InstallHotwordExtensionFromWebstore(int num_tries);
120 122
121 // Sets the pref value of the previous language. 123 // Sets the pref value of the previous language.
122 void SetPreviousLanguagePref(); 124 void SetPreviousLanguagePref();
123 125
124 // Returns the current error message id. A value of 0 indicates 126 // Returns the current error message id. A value of 0 indicates
125 // no error. 127 // no error.
126 int error_message() { return error_message_; } 128 int error_message() { return error_message_; }
127 129
130 bool microphone_available() { return microphone_available_; }
131
128 // These methods are for launching, and getting and setting the launch mode of 132 // These methods are for launching, and getting and setting the launch mode of
129 // the Hotword Audio Verification App. 133 // the Hotword Audio Verification App.
130 // 134 //
131 // OptIntoHotwording first determines if the app needs to be launched, and if 135 // OptIntoHotwording first determines if the app needs to be launched, and if
132 // so, launches the app (if Audio History is on and a speaker model exists, 136 // so, launches the app (if Audio History is on and a speaker model exists,
133 // then we don't need to launch the app). 137 // then we don't need to launch the app).
134 // 138 //
135 // LaunchHotwordAudioVerificationApp launches the app without the above 139 // LaunchHotwordAudioVerificationApp launches the app without the above
136 // check in the specified |launch_mode|. 140 // check in the specified |launch_mode|.
137 enum LaunchMode { 141 enum LaunchMode {
(...skipping 29 matching lines...) Expand all
167 171
168 // Returns a pointer to the audio history handler. 172 // Returns a pointer to the audio history handler.
169 HotwordAudioHistoryHandler* GetAudioHistoryHandler(); 173 HotwordAudioHistoryHandler* GetAudioHistoryHandler();
170 174
171 // Sets the audio history handler. Used for tests. 175 // Sets the audio history handler. Used for tests.
172 void SetAudioHistoryHandler(HotwordAudioHistoryHandler* handler); 176 void SetAudioHistoryHandler(HotwordAudioHistoryHandler* handler);
173 177
174 // Turn off the currently enabled version of hotwording if one exists. 178 // Turn off the currently enabled version of hotwording if one exists.
175 void DisableHotwordPreferences(); 179 void DisableHotwordPreferences();
176 180
181 // Overridden from MediaCaptureDevicesDispatcher::Observer
182 void OnUpdateAudioDevices(
183 const content::MediaStreamDevices& devices) override;
184
177 protected: 185 protected:
178 // Used in test subclasses. 186 // Used in test subclasses.
179 scoped_refptr<HotwordWebstoreInstaller> installer_; 187 scoped_refptr<HotwordWebstoreInstaller> installer_;
180 188
181 private: 189 private:
182 class HotwordUserSessionStateObserver; 190 class HotwordUserSessionStateObserver;
183 191
192 // Must be called from the UI thread since the instance of
193 // MediaCaptureDevicesDispatcher can only be accessed on the UI thread.
194 void InitializeMicrophoneObserver();
195
184 // Callback for webstore extension installer. 196 // Callback for webstore extension installer.
185 void InstalledFromWebstoreCallback( 197 void InstalledFromWebstoreCallback(
186 int num_tries, 198 int num_tries,
187 bool success, 199 bool success,
188 const std::string& error, 200 const std::string& error,
189 extensions::webstore_install::Result result); 201 extensions::webstore_install::Result result);
190 202
191 // Returns the ID of the extension that may need to be reinstalled. 203 // Returns the ID of the extension that may need to be reinstalled.
192 std::string ReinstalledExtensionId(); 204 std::string ReinstalledExtensionId();
193 205
194 // Creates a notification for always-on hotwording. 206 // Creates a notification for always-on hotwording.
195 void ShowHotwordNotification(); 207 void ShowHotwordNotification();
196 208
197 Profile* profile_; 209 Profile* profile_;
198 210
199 PrefChangeRegistrar pref_registrar_; 211 PrefChangeRegistrar pref_registrar_;
200 212
201 content::NotificationRegistrar registrar_; 213 content::NotificationRegistrar registrar_;
202 214
203 // For observing the ExtensionRegistry. 215 // For observing the ExtensionRegistry.
204 ScopedObserver<extensions::ExtensionRegistry, 216 ScopedObserver<extensions::ExtensionRegistry,
205 extensions::ExtensionRegistryObserver> 217 extensions::ExtensionRegistryObserver>
206 extension_registry_observer_; 218 extension_registry_observer_;
207 219
208 scoped_ptr<HotwordAudioHistoryHandler> audio_history_handler_; 220 scoped_ptr<HotwordAudioHistoryHandler> audio_history_handler_;
209 221
222 bool microphone_available_;
223
224 // Indicates if the check for audio devices has been run such that it can be
225 // included in the error checking. Audio checking is not done immediately
226 // upon start up because of the negative impact on performance.
227 bool audio_device_state_updated_;
228
210 HotwordClient* client_; 229 HotwordClient* client_;
211 int error_message_; 230 int error_message_;
212 bool reinstall_pending_; 231 bool reinstall_pending_;
213 // Whether we are currently in the process of training the speaker model. 232 // Whether we are currently in the process of training the speaker model.
214 bool training_; 233 bool training_;
215 scoped_ptr<HotwordUserSessionStateObserver> session_observer_; 234 scoped_ptr<HotwordUserSessionStateObserver> session_observer_;
216 235
217 // Stores the launch mode for the Hotword Audio Verification App. 236 // Stores the launch mode for the Hotword Audio Verification App.
218 LaunchMode hotword_audio_verification_launch_mode_; 237 LaunchMode hotword_audio_verification_launch_mode_;
219 238
220 // The WeakPtrFactory should be the last member, so the weak pointer 239 // The WeakPtrFactory should be the last member, so the weak pointer
221 // gets invalidated before the destructors for other members run, 240 // gets invalidated before the destructors for other members run,
222 // to avoid callbacks into a half-destroyed object. 241 // to avoid callbacks into a half-destroyed object.
223 base::WeakPtrFactory<HotwordService> weak_factory_; 242 base::WeakPtrFactory<HotwordService> weak_factory_;
224 243
225 DISALLOW_COPY_AND_ASSIGN(HotwordService); 244 DISALLOW_COPY_AND_ASSIGN(HotwordService);
226 }; 245 };
227 246
228 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_ 247 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/resources/hotword/page_audio_manager.js ('k') | chrome/browser/search/hotword_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698