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

Side by Side Diff: chrome/browser/search/hotword_service_factory.cc

Issue 654613004: [Hotword] Delay checking for audio devices until needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: redoing logic 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/search/hotword_service_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/search/hotword_service_factory.h" 5 #include "chrome/browser/search/hotword_service_factory.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search/hotword_service.h" 9 #include "chrome/browser/search/hotword_service.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 if (!hotword_service) 45 if (!hotword_service)
46 return 0; 46 return 0;
47 return hotword_service->error_message(); 47 return hotword_service->error_message();
48 } 48 }
49 49
50 // static 50 // static
51 bool HotwordServiceFactory::IsMicrophoneAvailable() { 51 bool HotwordServiceFactory::IsMicrophoneAvailable() {
52 return GetInstance()->microphone_available(); 52 return GetInstance()->microphone_available();
53 } 53 }
54 54
55 // static
56 bool HotwordServiceFactory::IsAudioDeviceStateUpdated() {
57 return GetInstance()->audio_device_state_updated();
58 }
59
55 HotwordServiceFactory::HotwordServiceFactory() 60 HotwordServiceFactory::HotwordServiceFactory()
56 : BrowserContextKeyedServiceFactory( 61 : BrowserContextKeyedServiceFactory(
57 "HotwordService", 62 "HotwordService",
58 BrowserContextDependencyManager::GetInstance()), 63 BrowserContextDependencyManager::GetInstance()),
59 microphone_available_(false) { 64 microphone_available_(false),
65 audio_device_state_updated_(false) {
60 // No dependencies. 66 // No dependencies.
61 67
62 // Register with the device observer list to update the microphone 68 // Register with the device observer list to update the microphone
63 // availability. 69 // availability.
64 BrowserThread::PostTask( 70 BrowserThread::PostTask(
65 BrowserThread::UI, FROM_HERE, 71 BrowserThread::UI, FROM_HERE,
66 base::Bind(&HotwordServiceFactory::InitializeMicrophoneObserver, 72 base::Bind(&HotwordServiceFactory::InitializeMicrophoneObserver,
67 base::Unretained(this))); 73 base::Unretained(this)));
68 } 74 }
69 75
70 HotwordServiceFactory::~HotwordServiceFactory() { 76 HotwordServiceFactory::~HotwordServiceFactory() {
71 } 77 }
72 78
73 void HotwordServiceFactory::InitializeMicrophoneObserver() { 79 void HotwordServiceFactory::InitializeMicrophoneObserver() {
74 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); 80 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
75 } 81 }
76 82
77 void HotwordServiceFactory::OnUpdateAudioDevices( 83 void HotwordServiceFactory::OnUpdateAudioDevices(
78 const content::MediaStreamDevices& devices) { 84 const content::MediaStreamDevices& devices) {
79 microphone_available_ = !devices.empty(); 85 microphone_available_ = !devices.empty();
86 audio_device_state_updated_ = true;
80 } 87 }
81 88
82 void HotwordServiceFactory::UpdateMicrophoneState() { 89 void HotwordServiceFactory::UpdateMicrophoneState() {
83 // In order to trigger the monitor, just call getAudioCaptureDevices. 90 // In order to trigger the monitor, just call getAudioCaptureDevices.
84 content::MediaStreamDevices devices = 91 content::MediaStreamDevices devices =
85 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); 92 MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices();
Anand Mistry (off Chromium) 2014/10/20 07:09:05 I think you've introduced a race here. If this fac
rpetterson 2014/10/20 17:25:07 I disagree. The factory is initialized on startup
Anand Mistry (off Chromium) 2014/10/20 21:22:54 Thanks for the explanation. This makes a lot more
86
87 // If the monitor had not previously been started, there may be 0 devices
88 // even if that is not accurate. However, we can update the microphone
89 // availability state now. Either the number of devices will be correct or
90 // we know that the call above will start the monitor and the microphone
91 // state will be updated very soon and call OnUpdateAudioDevices.
92 OnUpdateAudioDevices(devices);
93 } 93 }
94 94
95 void HotwordServiceFactory::RegisterProfilePrefs( 95 void HotwordServiceFactory::RegisterProfilePrefs(
96 user_prefs::PrefRegistrySyncable* prefs) { 96 user_prefs::PrefRegistrySyncable* prefs) {
97 prefs->RegisterBooleanPref(prefs::kHotwordSearchEnabled, 97 prefs->RegisterBooleanPref(prefs::kHotwordSearchEnabled,
98 false, 98 false,
99 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 99 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
100 // Although this is default true, users will not send back information to 100 // Although this is default true, users will not send back information to
101 // Google unless they have opted-in to Hotwording at which point they must 101 // Google unless they have opted-in to Hotwording at which point they must
102 // also confirm that they wish this preference to be true or opt out of it. 102 // also confirm that they wish this preference to be true or opt out of it.
103 prefs->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled, 103 prefs->RegisterBooleanPref(prefs::kHotwordAudioLoggingEnabled,
104 true, 104 true,
105 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 105 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
106 prefs->RegisterStringPref(prefs::kHotwordPreviousLanguage, 106 prefs->RegisterStringPref(prefs::kHotwordPreviousLanguage,
107 std::string(), 107 std::string(),
108 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 108 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
109 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnSearchEnabled, 109 prefs->RegisterBooleanPref(prefs::kHotwordAlwaysOnSearchEnabled,
110 false, 110 false,
111 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 111 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
112 } 112 }
113 113
114 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor( 114 KeyedService* HotwordServiceFactory::BuildServiceInstanceFor(
115 BrowserContext* context) const { 115 BrowserContext* context) const {
116 return new HotwordService(Profile::FromBrowserContext(context)); 116 return new HotwordService(Profile::FromBrowserContext(context));
117 } 117 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698