Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/api/hotword_private/hotword_private_api.h" | 5 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 } | 57 } |
| 58 | 58 |
| 59 // static | 59 // static |
| 60 const char* HotwordPrivateEventService::service_name() { | 60 const char* HotwordPrivateEventService::service_name() { |
| 61 return "HotwordPrivateEventService"; | 61 return "HotwordPrivateEventService"; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void HotwordPrivateEventService::OnEnabledChanged( | 64 void HotwordPrivateEventService::OnEnabledChanged( |
| 65 const std::string& pref_name) { | 65 const std::string& pref_name) { |
| 66 DCHECK(pref_name == std::string(prefs::kHotwordSearchEnabled) || | 66 DCHECK(pref_name == std::string(prefs::kHotwordSearchEnabled) || |
| 67 pref_name == std::string(prefs::kHotwordAlwaysOnSearchEnabled)); | 67 pref_name == std::string(prefs::kHotwordAlwaysOnSearchEnabled) || |
| 68 pref_name == std::string( | |
|
rpetterson
2014/10/30 19:48:36
Why is this a part of OnEnabledChanged? I would ex
kcarattini
2014/10/30 23:44:18
Changed the comment in hotword_private.idl, as dis
| |
| 69 hotword_internal::kHotwordTrainingEnabled)); | |
| 68 SignalEvent(OnEnabledChanged::kEventName); | 70 SignalEvent(OnEnabledChanged::kEventName); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void HotwordPrivateEventService::OnHotwordSessionRequested() { | 73 void HotwordPrivateEventService::OnHotwordSessionRequested() { |
| 72 SignalEvent(api::hotword_private::OnHotwordSessionRequested::kEventName); | 74 SignalEvent(api::hotword_private::OnHotwordSessionRequested::kEventName); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void HotwordPrivateEventService::OnHotwordSessionStopped() { | 77 void HotwordPrivateEventService::OnHotwordSessionStopped() { |
| 76 SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName); | 78 SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName); |
| 77 } | 79 } |
| 78 | 80 |
| 81 void HotwordPrivateEventService::OnFinalizeSpeakerModel() { | |
| 82 SignalEvent(api::hotword_private::OnFinalizeSpeakerModel::kEventName); | |
| 83 } | |
| 84 | |
| 85 void HotwordPrivateEventService::OnHotwordTriggered() { | |
| 86 SignalEvent(api::hotword_private::OnHotwordTriggered::kEventName); | |
| 87 } | |
| 88 | |
| 79 void HotwordPrivateEventService::SignalEvent(const std::string& event_name) { | 89 void HotwordPrivateEventService::SignalEvent(const std::string& event_name) { |
| 80 EventRouter* router = EventRouter::Get(profile_); | 90 EventRouter* router = EventRouter::Get(profile_); |
| 81 if (!router || !router->HasEventListener(event_name)) | 91 if (!router || !router->HasEventListener(event_name)) |
| 82 return; | 92 return; |
| 83 scoped_ptr<base::ListValue> args(new base::ListValue()); | 93 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 84 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 94 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
| 85 router->BroadcastEvent(event.Pass()); | 95 router->BroadcastEvent(event.Pass()); |
| 86 } | 96 } |
| 87 | 97 |
| 88 bool HotwordPrivateSetEnabledFunction::RunSync() { | 98 bool HotwordPrivateSetEnabledFunction::RunSync() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 140 |
| 131 PrefService* prefs = GetProfile()->GetPrefs(); | 141 PrefService* prefs = GetProfile()->GetPrefs(); |
| 132 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); | 142 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); |
| 133 result.enabled = prefs->GetBoolean(prefs::kHotwordSearchEnabled); | 143 result.enabled = prefs->GetBoolean(prefs::kHotwordSearchEnabled); |
| 134 result.always_on_enabled = | 144 result.always_on_enabled = |
| 135 prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled); | 145 prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled); |
| 136 result.audio_logging_enabled = false; | 146 result.audio_logging_enabled = false; |
| 137 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 147 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 138 result.experimental_hotword_enabled = command_line->HasSwitch( | 148 result.experimental_hotword_enabled = command_line->HasSwitch( |
| 139 switches::kEnableExperimentalHotwording); | 149 switches::kEnableExperimentalHotwording); |
| 140 if (hotword_service) | 150 if (hotword_service) { |
|
rpetterson
2014/10/30 19:48:35
Group this if statement with the one above.
kcarattini
2014/10/30 23:44:18
Done.
| |
| 141 result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging(); | 151 result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging(); |
| 152 result.training_enabled = hotword_service->IsTraining(); | |
| 153 } | |
| 142 | 154 |
| 143 SetResult(result.ToValue().release()); | 155 SetResult(result.ToValue().release()); |
| 144 return true; | 156 return true; |
| 145 } | 157 } |
| 146 | 158 |
| 147 bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() { | 159 bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() { |
| 148 scoped_ptr<api::hotword_private::SetHotwordSessionState::Params> params( | 160 scoped_ptr<api::hotword_private::SetHotwordSessionState::Params> params( |
| 149 api::hotword_private::SetHotwordSessionState::Params::Create(*args_)); | 161 api::hotword_private::SetHotwordSessionState::Params::Create(*args_)); |
| 150 EXTENSION_FUNCTION_VALIDATE(params.get()); | 162 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 151 | 163 |
| 152 HotwordService* hotword_service = | 164 HotwordService* hotword_service = |
| 153 HotwordServiceFactory::GetForProfile(GetProfile()); | 165 HotwordServiceFactory::GetForProfile(GetProfile()); |
| 154 if (hotword_service && hotword_service->client()) | 166 if (hotword_service && |
| 167 hotword_service->client() && | |
| 168 !hotword_service->IsTraining()) | |
| 155 hotword_service->client()->OnHotwordStateChanged(params->started); | 169 hotword_service->client()->OnHotwordStateChanged(params->started); |
| 156 return true; | 170 return true; |
| 157 } | 171 } |
| 158 | 172 |
| 159 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { | 173 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { |
| 160 HotwordService* hotword_service = | 174 HotwordService* hotword_service = |
| 161 HotwordServiceFactory::GetForProfile(GetProfile()); | 175 HotwordServiceFactory::GetForProfile(GetProfile()); |
| 162 if (hotword_service) { | 176 if (hotword_service) { |
| 163 if (hotword_service->client()) { | 177 if (hotword_service->IsTraining()) { |
| 178 hotword_service->NotifyHotwordTriggered(); | |
| 179 } else if (hotword_service->client()) { | |
| 164 hotword_service->client()->OnHotwordRecognized(); | 180 hotword_service->client()->OnHotwordRecognized(); |
| 165 } else if (HotwordService::IsExperimentalHotwordingEnabled() && | 181 } else if (HotwordService::IsExperimentalHotwordingEnabled() && |
| 166 hotword_service->IsAlwaysOnEnabled()) { | 182 hotword_service->IsAlwaysOnEnabled()) { |
| 167 Browser* browser = GetCurrentBrowser(); | 183 Browser* browser = GetCurrentBrowser(); |
| 168 // If a Browser does not exist, fall back to the universally available, | 184 // If a Browser does not exist, fall back to the universally available, |
| 169 // but not recommended, way. | 185 // but not recommended, way. |
| 170 AppListService* app_list_service = AppListService::Get( | 186 AppListService* app_list_service = AppListService::Get( |
| 171 browser ? browser->host_desktop_type() : chrome::GetActiveDesktop()); | 187 browser ? browser->host_desktop_type() : chrome::GetActiveDesktop()); |
| 172 CHECK(app_list_service); | 188 CHECK(app_list_service); |
| 173 app_list_service->ShowForVoiceSearch(GetProfile()); | 189 app_list_service->ShowForVoiceSearch(GetProfile()); |
| 174 } | 190 } |
| 175 } | 191 } |
| 176 return true; | 192 return true; |
| 177 } | 193 } |
| 178 | 194 |
| 179 bool HotwordPrivateGetLaunchStateFunction::RunSync() { | 195 bool HotwordPrivateGetLaunchStateFunction::RunSync() { |
| 180 api::hotword_private::LaunchState result; | |
| 181 | |
| 182 HotwordService* hotword_service = | 196 HotwordService* hotword_service = |
| 183 HotwordServiceFactory::GetForProfile(GetProfile()); | 197 HotwordServiceFactory::GetForProfile(GetProfile()); |
| 184 if (!hotword_service) { | 198 if (!hotword_service) { |
| 185 error_ = hotword_private_constants::kHotwordServiceUnavailable; | 199 error_ = hotword_private_constants::kHotwordServiceUnavailable; |
| 186 return false; | 200 return false; |
| 187 } else { | |
| 188 result.launch_mode = | |
| 189 hotword_service->GetHotwordAudioVerificationLaunchMode(); | |
| 190 } | 201 } |
| 191 | 202 |
| 203 api::hotword_private::LaunchState result; | |
| 204 result.launch_mode = | |
| 205 hotword_service->GetHotwordAudioVerificationLaunchMode(); | |
| 192 SetResult(result.ToValue().release()); | 206 SetResult(result.ToValue().release()); |
| 193 return true; | 207 return true; |
| 194 } | 208 } |
| 195 | 209 |
| 210 bool HotwordPrivateStartTrainingFunction::RunSync() { | |
| 211 HotwordService* hotword_service = | |
| 212 HotwordServiceFactory::GetForProfile(GetProfile()); | |
| 213 if (!hotword_service) { | |
| 214 error_ = hotword_private_constants::kHotwordServiceUnavailable; | |
| 215 return false; | |
| 216 } | |
| 217 | |
| 218 hotword_service->StartTraining(); | |
| 219 return true; | |
| 220 } | |
| 221 | |
| 222 bool HotwordPrivateFinalizeSpeakerModelFunction::RunSync() { | |
| 223 HotwordService* hotword_service = | |
| 224 HotwordServiceFactory::GetForProfile(GetProfile()); | |
| 225 if (!hotword_service) { | |
| 226 error_ = hotword_private_constants::kHotwordServiceUnavailable; | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 230 hotword_service->FinalizeSpeakerModel(); | |
| 231 return true; | |
| 232 } | |
| 233 | |
| 234 bool HotwordPrivateStopTrainingFunction::RunSync() { | |
| 235 HotwordService* hotword_service = | |
| 236 HotwordServiceFactory::GetForProfile(GetProfile()); | |
| 237 if (!hotword_service) { | |
| 238 error_ = hotword_private_constants::kHotwordServiceUnavailable; | |
| 239 return false; | |
| 240 } | |
| 241 | |
| 242 hotword_service->StopTraining(); | |
| 243 return true; | |
| 244 } | |
| 245 | |
| 196 } // namespace extensions | 246 } // namespace extensions |
| OLD | NEW |