OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/speech_input/extension_speech_input_manager.
h" | 5 #include "chrome/browser/extensions/speech_input/extension_speech_input_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/speech_input/extension_speech_input_api_cons
tants.h" | 12 #include "chrome/browser/extensions/speech_input/extension_speech_input_api_cons
tants.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_dependency_manager.h" | 14 #include "chrome/browser/profiles/profile_dependency_manager.h" |
15 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
16 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 16 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
20 #include "content/common/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
21 | 21 |
22 using namespace speech_input; | 22 using namespace speech_input; |
23 | 23 |
24 namespace constants = extension_speech_input_api_constants; | 24 namespace constants = extension_speech_input_api_constants; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Caller id provided to the speech recognizer. Since only one extension can | 28 // Caller id provided to the speech recognizer. Since only one extension can |
29 // be recording on the same time a constant value is enough as id. | 29 // be recording on the same time a constant value is enough as id. |
30 static const int kSpeechCallerId = 1; | 30 static const int kSpeechCallerId = 1; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 265 |
266 base::AutoLock auto_lock(state_lock_); | 266 base::AutoLock auto_lock(state_lock_); |
267 if (state_ == kShutdown) | 267 if (state_ == kShutdown) |
268 return; | 268 return; |
269 | 269 |
270 DCHECK_EQ(state_, kStarting); | 270 DCHECK_EQ(state_, kStarting); |
271 VLOG(1) << "State changed to recording"; | 271 VLOG(1) << "State changed to recording"; |
272 state_ = kRecording; | 272 state_ = kRecording; |
273 | 273 |
274 VLOG(1) << "Sending start notification"; | 274 VLOG(1) << "Sending start notification"; |
275 NotificationService::current()->Notify( | 275 content::NotificationService::current()->Notify( |
276 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STARTED, | 276 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STARTED, |
277 content::Source<Profile>(profile_), | 277 content::Source<Profile>(profile_), |
278 content::Details<std::string>(&extension_id_in_use_)); | 278 content::Details<std::string>(&extension_id_in_use_)); |
279 } | 279 } |
280 | 280 |
281 void ExtensionSpeechInputManager::OnRecognizerError( | 281 void ExtensionSpeechInputManager::OnRecognizerError( |
282 int caller_id, SpeechInputError error) { | 282 int caller_id, SpeechInputError error) { |
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
284 DCHECK_EQ(caller_id, kSpeechCallerId); | 284 DCHECK_EQ(caller_id, kSpeechCallerId); |
285 VLOG(1) << "OnRecognizerError: " << error; | 285 VLOG(1) << "OnRecognizerError: " << error; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 { | 398 { |
399 base::AutoLock auto_lock(state_lock_); | 399 base::AutoLock auto_lock(state_lock_); |
400 if (state_ == kShutdown) | 400 if (state_ == kShutdown) |
401 return; | 401 return; |
402 | 402 |
403 extension_id = extension_id_in_use_; | 403 extension_id = extension_id_in_use_; |
404 ResetToIdleState(); | 404 ResetToIdleState(); |
405 | 405 |
406 // Will set the error property in the ongoing extension function calls. | 406 // Will set the error property in the ongoing extension function calls. |
407 ExtensionError details(extension_id, error); | 407 ExtensionError details(extension_id, error); |
408 NotificationService::current()->Notify( | 408 content::NotificationService::current()->Notify( |
409 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_FAILED, | 409 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_FAILED, |
410 content::Source<Profile>(profile_), | 410 content::Source<Profile>(profile_), |
411 content::Details<ExtensionError>(&details)); | 411 content::Details<ExtensionError>(&details)); |
412 } | 412 } |
413 | 413 |
414 // Used for errors that are also reported via the onError event. | 414 // Used for errors that are also reported via the onError event. |
415 if (dispatch_event) { | 415 if (dispatch_event) { |
416 ListValue args; | 416 ListValue args; |
417 DictionaryValue *js_error = new DictionaryValue(); | 417 DictionaryValue *js_error = new DictionaryValue(); |
418 args.Append(js_error); | 418 args.Append(js_error); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
598 VLOG(1) << "Stop succeeded (UI thread)"; | 598 VLOG(1) << "Stop succeeded (UI thread)"; |
599 | 599 |
600 base::AutoLock auto_lock(state_lock_); | 600 base::AutoLock auto_lock(state_lock_); |
601 if (state_ == kShutdown) | 601 if (state_ == kShutdown) |
602 return; | 602 return; |
603 | 603 |
604 std::string extension_id = extension_id_in_use_; | 604 std::string extension_id = extension_id_in_use_; |
605 ResetToIdleState(); | 605 ResetToIdleState(); |
606 | 606 |
607 NotificationService::current()->Notify( | 607 content::NotificationService::current()->Notify( |
608 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STOPPED, | 608 chrome::NOTIFICATION_EXTENSION_SPEECH_INPUT_RECORDING_STOPPED, |
609 // Guarded by the state_ == kShutdown check. | 609 // Guarded by the state_ == kShutdown check. |
610 content::Source<Profile>(profile_), | 610 content::Source<Profile>(profile_), |
611 content::Details<std::string>(&extension_id)); | 611 content::Details<std::string>(&extension_id)); |
612 } | 612 } |
OLD | NEW |