OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/speech/speech_input_extension_manager.h" | 5 #include "chrome/browser/speech/speech_input_extension_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/extension_event_router.h" | 11 #include "chrome/browser/extensions/extension_event_router.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_dependency_manager.h" | 15 #include "chrome/browser/profiles/profile_dependency_manager.h" |
16 #include "chrome/browser/profiles/profile_keyed_service.h" | 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
17 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 17 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
18 #include "chrome/browser/speech/speech_input_extension_notification.h" | 18 #include "chrome/browser/speech/speech_input_extension_notification.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/speech_recognition_manager.h" | 25 #include "content/public/browser/speech_recognition_manager.h" |
26 #include "content/public/browser/speech_recognizer.h" | 26 #include "content/public/browser/speech_recognizer.h" |
| 27 #include "content/public/common/speech_recognition_error.h" |
27 #include "content/public/common/speech_recognition_result.h" | 28 #include "content/public/common/speech_recognition_result.h" |
28 | 29 |
29 using content::BrowserThread; | 30 using content::BrowserThread; |
30 using content::SpeechRecognitionHypothesis; | 31 using content::SpeechRecognitionHypothesis; |
31 using content::SpeechRecognitionManager; | 32 using content::SpeechRecognitionManager; |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 const char kErrorNoRecordingDeviceFound[] = "noRecordingDeviceFound"; | 36 const char kErrorNoRecordingDeviceFound[] = "noRecordingDeviceFound"; |
36 const char kErrorRecordingDeviceInUse[] = "recordingDeviceInUse"; | 37 const char kErrorRecordingDeviceInUse[] = "recordingDeviceInUse"; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 334 } |
334 | 335 |
335 VLOG(1) << "Sending start notification"; | 336 VLOG(1) << "Sending start notification"; |
336 content::NotificationService::current()->Notify( | 337 content::NotificationService::current()->Notify( |
337 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STARTED, | 338 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STARTED, |
338 content::Source<Profile>(profile_), | 339 content::Source<Profile>(profile_), |
339 content::Details<std::string>(&extension_id_in_use_)); | 340 content::Details<std::string>(&extension_id_in_use_)); |
340 } | 341 } |
341 | 342 |
342 void SpeechInputExtensionManager::OnRecognitionError( | 343 void SpeechInputExtensionManager::OnRecognitionError( |
343 int caller_id, const content::SpeechRecognitionErrorCode& error) { | 344 int caller_id, const content::SpeechRecognitionError& error) { |
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
345 DCHECK_EQ(caller_id, kSpeechCallerId); | 346 DCHECK_EQ(caller_id, kSpeechCallerId); |
346 VLOG(1) << "OnRecognitionError: " << error; | 347 VLOG(1) << "OnRecognitionError: " << error.code; |
347 | 348 |
348 base::AutoLock auto_lock(state_lock_); | 349 base::AutoLock auto_lock(state_lock_); |
349 if (state_ == kShutdown) | 350 if (state_ == kShutdown) |
350 return; | 351 return; |
351 | 352 |
352 // Release the recognizer object. | 353 // Release the recognizer object. |
353 GetSpeechInputExtensionInterface()->StopRecording(true); | 354 GetSpeechInputExtensionInterface()->StopRecording(true); |
354 | 355 |
355 std::string event_error_code; | 356 std::string event_error_code; |
356 bool report_to_event = true; | 357 bool report_to_event = true; |
357 | 358 |
358 switch (error) { | 359 switch (error.code) { |
359 case content::SPEECH_RECOGNITION_ERROR_NONE: | 360 case content::SPEECH_RECOGNITION_ERROR_NONE: |
360 break; | 361 break; |
361 | 362 |
362 case content::SPEECH_RECOGNITION_ERROR_AUDIO: | 363 case content::SPEECH_RECOGNITION_ERROR_AUDIO: |
363 if (state_ == kStarting) { | 364 if (state_ == kStarting) { |
364 event_error_code = kErrorUnableToStart; | 365 event_error_code = kErrorUnableToStart; |
365 report_to_event = false; | 366 report_to_event = false; |
366 } else { | 367 } else { |
367 event_error_code = kErrorCaptureError; | 368 event_error_code = kErrorCaptureError; |
368 } | 369 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, | 722 base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, |
722 this, volume)); | 723 this, volume)); |
723 } | 724 } |
724 | 725 |
725 void SpeechInputExtensionManager::SetInputVolumeOnUIThread( | 726 void SpeechInputExtensionManager::SetInputVolumeOnUIThread( |
726 float volume) { | 727 float volume) { |
727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
728 DCHECK(notification_.get()); | 729 DCHECK(notification_.get()); |
729 notification_->SetVUMeterVolume(volume); | 730 notification_->SetVUMeterVolume(volume); |
730 } | 731 } |
OLD | NEW |