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

Side by Side Diff: chrome/browser/search/hotword_service_factory.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_FACTORY_H_ 5 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_ 6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_
7 7
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
10 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" 9 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
11 10
12 class HotwordService; 11 class HotwordService;
13 class Profile; 12 class Profile;
14 13
15 // Singleton that owns all HotwordServices and associates them with Profiles. 14 // Singleton that owns all HotwordServices and associates them with Profiles.
16 class HotwordServiceFactory : public MediaCaptureDevicesDispatcher::Observer, 15 class HotwordServiceFactory : public BrowserContextKeyedServiceFactory {
17 public BrowserContextKeyedServiceFactory {
18 public: 16 public:
19 // Returns the HotwordService for |context|. 17 // Returns the HotwordService for |context|.
20 static HotwordService* GetForProfile(content::BrowserContext* context); 18 static HotwordService* GetForProfile(content::BrowserContext* context);
21 19
22 static HotwordServiceFactory* GetInstance(); 20 static HotwordServiceFactory* GetInstance();
23 21
24 // Returns true if the hotwording service is available for |context|. 22 // Returns true if the hotwording service is available for |context|.
25 static bool IsServiceAvailable(content::BrowserContext* context); 23 static bool IsServiceAvailable(content::BrowserContext* context);
26 24
27 // Returns true if hotwording is allowed for |context|. 25 // Returns true if hotwording is allowed for |context|.
28 static bool IsHotwordAllowed(content::BrowserContext* context); 26 static bool IsHotwordAllowed(content::BrowserContext* context);
29 27
30 // Returns whether always-on hotwording is available. 28 // Returns whether always-on hotwording is available.
31 static bool IsAlwaysOnAvailable(); 29 static bool IsAlwaysOnAvailable();
32 30
33 // Returns the current error message for the service for |context|. 31 // Returns the current error message for the service for |context|.
34 // A value of 0 indicates no error. 32 // A value of 0 indicates no error.
35 static int GetCurrentError(content::BrowserContext* context); 33 static int GetCurrentError(content::BrowserContext* context);
36 34
37 // Returns the current known state of the microphone. Since this state
38 // is browser (not profile) specific, it resides in the factory.
39 static bool IsMicrophoneAvailable();
40
41 // Returns whether the state of the audio devices has been updated.
42 // Essentially it indicates the validity of the return value from
43 // IsMicrophoneAvailable().
44 static bool IsAudioDeviceStateUpdated();
45
46 // Overridden from MediaCaptureDevicesDispatcher::Observer
47 void OnUpdateAudioDevices(
48 const content::MediaStreamDevices& devices) override;
49
50 // This will kick off the monitor that calls OnUpdateAudioDevices when the 35 // This will kick off the monitor that calls OnUpdateAudioDevices when the
51 // number of audio devices changes (or is initialized). It needs to be a 36 // number of audio devices changes (or is initialized). It needs to be a
52 // separate function so it can be called after the service is initialized 37 // separate function so it can be called after the service is initialized
53 // (i.e., after startup). The monitor can't be initialized during startup 38 // (i.e., after startup). The monitor can't be initialized during startup
54 // because it would slow down startup too much so it is delayed and not 39 // because it would slow down startup too much so it is delayed and not
55 // called until it's needed by the webui in browser_options_handler. 40 // called until it's needed by the webui in browser_options_handler.
56 void UpdateMicrophoneState(); 41 void UpdateMicrophoneState();
57 42
58 private: 43 private:
59 friend struct DefaultSingletonTraits<HotwordServiceFactory>; 44 friend struct DefaultSingletonTraits<HotwordServiceFactory>;
60 45
61 HotwordServiceFactory(); 46 HotwordServiceFactory();
62 ~HotwordServiceFactory() override; 47 ~HotwordServiceFactory() override;
63 48
64 // Overrides from BrowserContextKeyedServiceFactory: 49 // Overrides from BrowserContextKeyedServiceFactory:
65 void RegisterProfilePrefs( 50 void RegisterProfilePrefs(
66 user_prefs::PrefRegistrySyncable* registry) override; 51 user_prefs::PrefRegistrySyncable* registry) override;
67 KeyedService* BuildServiceInstanceFor( 52 KeyedService* BuildServiceInstanceFor(
68 content::BrowserContext* context) const override; 53 content::BrowserContext* context) const override;
69 54
70 // Must be called from the UI thread since the instance of
71 // MediaCaptureDevicesDispatcher can only be accessed on the UI thread.
72 void InitializeMicrophoneObserver();
73
74 bool microphone_available() { return microphone_available_; }
75
76 bool microphone_available_;
77
78 // Indicates if the check for audio devices has been run such that it can be
79 // included in the error checking. Audio checking is not done immediately
80 // upon start up because of the negative impact on performance.
81 bool audio_device_state_updated_;
82
83 bool audio_device_state_updated() { return audio_device_state_updated_; }
84
85 DISALLOW_COPY_AND_ASSIGN(HotwordServiceFactory); 55 DISALLOW_COPY_AND_ASSIGN(HotwordServiceFactory);
86 }; 56 };
87 57
88 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_ 58 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service.cc ('k') | chrome/browser/search/hotword_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698