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

Unified Diff: chrome/browser/search/hotword_service.cc

Issue 654613004: [Hotword] Delay checking for audio devices until needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/search/hotword_service_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/hotword_service.cc
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc
index 4a6f2c90d88f35ccf94215fc8f9d9529f63df8af..1e9c86d5b81357b365473dba41dd358dd210ca79 100644
--- a/chrome/browser/search/hotword_service.cc
+++ b/chrome/browser/search/hotword_service.cc
@@ -215,10 +215,6 @@ HotwordService::HotwordService(Profile* profile)
base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
base::Unretained(this)));
- registrar_.Add(this,
- chrome::NOTIFICATION_BROWSER_WINDOW_READY,
- content::NotificationService::AllSources());
-
extensions::ExtensionSystem::Get(profile_)->ready().Post(
FROM_HERE,
base::Bind(base::IgnoreResult(
@@ -236,25 +232,6 @@ HotwordService::HotwordService(Profile* profile)
HotwordService::~HotwordService() {
}
-void HotwordService::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) {
- // The microphone monitor must be initialized as the page is loading
- // so that the state of the microphone is available when the page
- // loads. The Ok Google Hotword setting will display an error if there
- // is no microphone but this information will not be up-to-date unless
- // the monitor had already been started. Furthermore, the pop up to
- // opt in to hotwording won't be available if it thinks there is no
- // microphone. There is no hard guarantee that the monitor will actually
- // be up by the time it's needed, but this is the best we can do without
- // starting it at start up which slows down start up too much.
- // The content/media for microphone uses the same observer design and
- // makes use of the same audio device monitor.
- HotwordServiceFactory::GetInstance()->UpdateMicrophoneState();
- }
-}
-
void HotwordService::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
@@ -417,10 +394,20 @@ bool HotwordService::IsServiceAvailable() {
RecordErrorMetrics(error_message_);
// Determine if the proper audio capabilities exist.
- bool audio_capture_allowed =
- profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed);
- if (!audio_capture_allowed || !HotwordServiceFactory::IsMicrophoneAvailable())
- error_message_ = IDS_HOTWORD_MICROPHONE_ERROR_MESSAGE;
+ // The first time this is called, it probably won't return in time, but that's
+ // why it won't be included in the error calculation (i.e., the call to
+ // IsAudioDeviceStateUpdated()). However, this use case is rare and typically
+ // the devices will be initialized by the time a user goes to settings.
+ bool audio_device_state_updated =
+ HotwordServiceFactory::IsAudioDeviceStateUpdated();
+ HotwordServiceFactory::GetInstance()->UpdateMicrophoneState();
+ if (audio_device_state_updated) {
+ bool audio_capture_allowed =
+ profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed);
+ if (!audio_capture_allowed ||
+ !HotwordServiceFactory::IsMicrophoneAvailable())
+ error_message_ = IDS_HOTWORD_MICROPHONE_ERROR_MESSAGE;
+ }
return (error_message_ == 0) && IsHotwordAllowed();
}
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/browser/search/hotword_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698