| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_manager.h" | 5 #include "chrome/browser/speech/speech_input_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/lock.h" | 11 #include "base/lock.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/singleton.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_thread.h" | 15 #include "chrome/browser/browser_thread.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/speech/speech_input_bubble_controller.h" | 17 #include "chrome/browser/speech/speech_input_bubble_controller.h" |
| 18 #include "chrome/browser/speech/speech_recognizer.h" | 18 #include "chrome/browser/speech/speech_recognizer.h" |
| 19 #include "chrome/browser/tab_contents/infobar_delegate.h" | 19 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 virtual void InfoBubbleFocusChanged(int caller_id); | 117 virtual void InfoBubbleFocusChanged(int caller_id); |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 struct SpeechInputRequest { | 120 struct SpeechInputRequest { |
| 121 SpeechInputManagerDelegate* delegate; | 121 SpeechInputManagerDelegate* delegate; |
| 122 scoped_refptr<SpeechRecognizer> recognizer; | 122 scoped_refptr<SpeechRecognizer> recognizer; |
| 123 bool is_active; // Set to true when recording or recognition is going on. | 123 bool is_active; // Set to true when recording or recognition is going on. |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 // Private constructor to enforce singleton. | 126 // Private constructor to enforce singleton. |
| 127 friend struct DefaultSingletonTraits<SpeechInputManagerImpl>; | 127 friend struct base::DefaultLazyInstanceTraits<SpeechInputManagerImpl>; |
| 128 SpeechInputManagerImpl(); | 128 SpeechInputManagerImpl(); |
| 129 virtual ~SpeechInputManagerImpl(); | 129 virtual ~SpeechInputManagerImpl(); |
| 130 | 130 |
| 131 bool HasPendingRequest(int caller_id) const; | 131 bool HasPendingRequest(int caller_id) const; |
| 132 SpeechInputManagerDelegate* GetDelegate(int caller_id) const; | 132 SpeechInputManagerDelegate* GetDelegate(int caller_id) const; |
| 133 | 133 |
| 134 void CancelRecognitionAndInformDelegate(int caller_id); | 134 void CancelRecognitionAndInformDelegate(int caller_id); |
| 135 | 135 |
| 136 // Starts/restarts recognition for an existing request. | 136 // Starts/restarts recognition for an existing request. |
| 137 void StartRecognitionForRequest(int caller_id); | 137 void StartRecognitionForRequest(int caller_id); |
| 138 | 138 |
| 139 SpeechInputManagerDelegate* delegate_; | 139 SpeechInputManagerDelegate* delegate_; |
| 140 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | 140 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; |
| 141 SpeechRecognizerMap requests_; | 141 SpeechRecognizerMap requests_; |
| 142 int recording_caller_id_; | 142 int recording_caller_id_; |
| 143 scoped_refptr<SpeechInputBubbleController> bubble_controller_; | 143 scoped_refptr<SpeechInputBubbleController> bubble_controller_; |
| 144 scoped_refptr<HardwareInfo> hardware_info_; | 144 scoped_refptr<HardwareInfo> hardware_info_; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 static ::base::LazyInstance<SpeechInputManagerImpl> g_speech_input_manager_impl( |
| 148 base::LINKER_INITIALIZED); |
| 149 |
| 147 SpeechInputManager* SpeechInputManager::Get() { | 150 SpeechInputManager* SpeechInputManager::Get() { |
| 148 return Singleton<SpeechInputManagerImpl>::get(); | 151 return g_speech_input_manager_impl.Pointer(); |
| 149 } | 152 } |
| 150 | 153 |
| 151 SpeechInputManagerImpl::SpeechInputManagerImpl() | 154 SpeechInputManagerImpl::SpeechInputManagerImpl() |
| 152 : recording_caller_id_(0), | 155 : recording_caller_id_(0), |
| 153 bubble_controller_(new SpeechInputBubbleController( | 156 bubble_controller_(new SpeechInputBubbleController( |
| 154 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { | 157 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { |
| 155 } | 158 } |
| 156 | 159 |
| 157 SpeechInputManagerImpl::~SpeechInputManagerImpl() { | 160 SpeechInputManagerImpl::~SpeechInputManagerImpl() { |
| 158 while (requests_.begin() != requests_.end()) | 161 while (requests_.begin() != requests_.end()) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 // to the user, abort it since user has switched focus. Otherwise | 332 // to the user, abort it since user has switched focus. Otherwise |
| 330 // recognition has started and keep that going so user can start speaking to | 333 // recognition has started and keep that going so user can start speaking to |
| 331 // another element while this gets the results in parallel. | 334 // another element while this gets the results in parallel. |
| 332 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { | 335 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { |
| 333 CancelRecognitionAndInformDelegate(caller_id); | 336 CancelRecognitionAndInformDelegate(caller_id); |
| 334 } | 337 } |
| 335 } | 338 } |
| 336 } | 339 } |
| 337 | 340 |
| 338 } // namespace speech_input | 341 } // namespace speech_input |
| OLD | NEW |