Prevent chrome://net-internals/#export from flickering
[chromium-blink-merge.git] / chrome / browser / search / hotword_service_factory.h
blobbb6f3cb0170f1d94b1f92b567948dd3632ed3741
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_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"
12 class HotwordService;
13 class Profile;
15 // Singleton that owns all HotwordServices and associates them with Profiles.
16 class HotwordServiceFactory : public MediaCaptureDevicesDispatcher::Observer,
17 public BrowserContextKeyedServiceFactory {
18 public:
19 // Returns the HotwordService for |context|.
20 static HotwordService* GetForProfile(content::BrowserContext* context);
22 static HotwordServiceFactory* GetInstance();
24 // Returns true if the hotwording service is available for |context|.
25 static bool IsServiceAvailable(content::BrowserContext* context);
27 // Returns true if hotwording is allowed for |context|.
28 static bool IsHotwordAllowed(content::BrowserContext* context);
30 // Returns whether specialized hotword hardware exists.
31 static bool IsHotwordHardwareAvailable();
33 // Returns the current error message for the service for |context|.
34 // A value of 0 indicates no error.
35 static int GetCurrentError(content::BrowserContext* context);
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();
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();
46 // Overridden from MediaCaptureDevicesDispatcher::Observer
47 void OnUpdateAudioDevices(
48 const content::MediaStreamDevices& devices) override;
50 // 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
52 // 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
54 // 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.
56 void UpdateMicrophoneState();
58 private:
59 friend struct DefaultSingletonTraits<HotwordServiceFactory>;
61 HotwordServiceFactory();
62 ~HotwordServiceFactory() override;
64 // Overrides from BrowserContextKeyedServiceFactory:
65 void RegisterProfilePrefs(
66 user_prefs::PrefRegistrySyncable* registry) override;
67 KeyedService* BuildServiceInstanceFor(
68 content::BrowserContext* context) const override;
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();
74 bool microphone_available() { return microphone_available_; }
76 bool microphone_available_;
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_;
83 bool audio_device_state_updated() { return audio_device_state_updated_; }
85 DISALLOW_COPY_AND_ASSIGN(HotwordServiceFactory);
88 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_FACTORY_H_