| 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" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 DictionaryValue* js_hypothesis_object = new DictionaryValue(); | 271 DictionaryValue* js_hypothesis_object = new DictionaryValue(); |
| 272 js_hypothesis_array->Append(js_hypothesis_object); | 272 js_hypothesis_array->Append(js_hypothesis_object); |
| 273 | 273 |
| 274 js_hypothesis_object->SetString(kUtteranceKey, | 274 js_hypothesis_object->SetString(kUtteranceKey, |
| 275 UTF16ToUTF8(hypothesis.utterance)); | 275 UTF16ToUTF8(hypothesis.utterance)); |
| 276 js_hypothesis_object->SetDouble(kConfidenceKey, | 276 js_hypothesis_object->SetDouble(kConfidenceKey, |
| 277 hypothesis.confidence); | 277 hypothesis.confidence); |
| 278 } | 278 } |
| 279 | 279 |
| 280 std::string json_args; | 280 std::string json_args; |
| 281 base::JSONWriter::Write(&args, false, &json_args); | 281 base::JSONWriter::Write(&args, &json_args); |
| 282 VLOG(1) << "Results: " << json_args; | 282 VLOG(1) << "Results: " << json_args; |
| 283 DispatchEventToExtension(extension_id, kOnResultEvent, json_args); | 283 DispatchEventToExtension(extension_id, kOnResultEvent, json_args); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void SpeechInputExtensionManager::OnRecognitionStart(int caller_id) { | 286 void SpeechInputExtensionManager::OnRecognitionStart(int caller_id) { |
| 287 DCHECK_EQ(caller_id, kSpeechCallerId); | 287 DCHECK_EQ(caller_id, kSpeechCallerId); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void SpeechInputExtensionManager::OnAudioStart(int caller_id) { | 290 void SpeechInputExtensionManager::OnAudioStart(int caller_id) { |
| 291 VLOG(1) << "OnAudioStart"; | 291 VLOG(1) << "OnAudioStart"; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 435 | 435 |
| 436 base::AutoLock auto_lock(state_lock_); | 436 base::AutoLock auto_lock(state_lock_); |
| 437 if (state_ == kShutdown) | 437 if (state_ == kShutdown) |
| 438 return; | 438 return; |
| 439 | 439 |
| 440 if (profile_ && profile_->GetExtensionEventRouter()) { | 440 if (profile_ && profile_->GetExtensionEventRouter()) { |
| 441 std::string final_args; | 441 std::string final_args; |
| 442 if (json_args.empty()) { | 442 if (json_args.empty()) { |
| 443 ListValue args; | 443 ListValue args; |
| 444 base::JSONWriter::Write(&args, false, &final_args); | 444 base::JSONWriter::Write(&args, &final_args); |
| 445 } else { | 445 } else { |
| 446 final_args = json_args; | 446 final_args = json_args; |
| 447 } | 447 } |
| 448 | 448 |
| 449 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 449 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
| 450 extension_id, event, final_args, profile_, GURL()); | 450 extension_id, event, final_args, profile_, GURL()); |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 void SpeechInputExtensionManager::DispatchError( | 454 void SpeechInputExtensionManager::DispatchError( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 477 content::Details<ExtensionError>(&details)); | 477 content::Details<ExtensionError>(&details)); |
| 478 } | 478 } |
| 479 | 479 |
| 480 // Used for errors that are also reported via the onError event. | 480 // Used for errors that are also reported via the onError event. |
| 481 if (dispatch_event) { | 481 if (dispatch_event) { |
| 482 ListValue args; | 482 ListValue args; |
| 483 DictionaryValue* js_error = new DictionaryValue(); | 483 DictionaryValue* js_error = new DictionaryValue(); |
| 484 args.Append(js_error); | 484 args.Append(js_error); |
| 485 js_error->SetString(kErrorCodeKey, error); | 485 js_error->SetString(kErrorCodeKey, error); |
| 486 std::string json_args; | 486 std::string json_args; |
| 487 base::JSONWriter::Write(&args, false, &json_args); | 487 base::JSONWriter::Write(&args, &json_args); |
| 488 DispatchEventToExtension(extension_id, | 488 DispatchEventToExtension(extension_id, |
| 489 kOnErrorEvent, json_args); | 489 kOnErrorEvent, json_args); |
| 490 } | 490 } |
| 491 } | 491 } |
| 492 | 492 |
| 493 bool SpeechInputExtensionManager::Start( | 493 bool SpeechInputExtensionManager::Start( |
| 494 const std::string& extension_id, const std::string& language, | 494 const std::string& extension_id, const std::string& language, |
| 495 const std::string& grammar, bool filter_profanities, std::string* error) { | 495 const std::string& grammar, bool filter_profanities, std::string* error) { |
| 496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 497 DCHECK(error); | 497 DCHECK(error); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, | 721 base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, |
| 722 this, volume)); | 722 this, volume)); |
| 723 } | 723 } |
| 724 | 724 |
| 725 void SpeechInputExtensionManager::SetInputVolumeOnUIThread( | 725 void SpeechInputExtensionManager::SetInputVolumeOnUIThread( |
| 726 float volume) { | 726 float volume) { |
| 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 728 DCHECK(notification_.get()); | 728 DCHECK(notification_.get()); |
| 729 notification_->SetVUMeterVolume(volume); | 729 notification_->SetVUMeterVolume(volume); |
| 730 } | 730 } |
| OLD | NEW |