| 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/command_line.h" | |
| 12 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 13 #include "base/lock.h" | 12 #include "base/lock.h" |
| 14 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 15 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_thread.h" | 16 #include "chrome/browser/browser_thread.h" |
| 18 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/speech/speech_input_bubble_controller.h" | 19 #include "chrome/browser/speech/speech_input_bubble_controller.h" |
| 21 #include "chrome/browser/speech/speech_recognizer.h" | 20 #include "chrome/browser/speech/speech_recognizer.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 scoped_refptr<HardwareInfo> hardware_info_; | 145 scoped_refptr<HardwareInfo> hardware_info_; |
| 147 }; | 146 }; |
| 148 | 147 |
| 149 static ::base::LazyInstance<SpeechInputManagerImpl> g_speech_input_manager_impl( | 148 static ::base::LazyInstance<SpeechInputManagerImpl> g_speech_input_manager_impl( |
| 150 base::LINKER_INITIALIZED); | 149 base::LINKER_INITIALIZED); |
| 151 | 150 |
| 152 SpeechInputManager* SpeechInputManager::Get() { | 151 SpeechInputManager* SpeechInputManager::Get() { |
| 153 return g_speech_input_manager_impl.Pointer(); | 152 return g_speech_input_manager_impl.Pointer(); |
| 154 } | 153 } |
| 155 | 154 |
| 156 bool SpeechInputManager::IsFeatureEnabled() { | |
| 157 bool enabled = true; | |
| 158 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 159 | |
| 160 if (command_line.HasSwitch(switches::kDisableSpeechInput)) { | |
| 161 enabled = false; | |
| 162 #if defined(GOOGLE_CHROME_BUILD) | |
| 163 } else if (!command_line.HasSwitch(switches::kEnableSpeechInput)) { | |
| 164 // We need to evaluate whether IO is OK here. http://crbug.com/63335. | |
| 165 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 166 // Official Chrome builds have speech input enabled by default only in the | |
| 167 // dev channel. | |
| 168 std::string channel = platform_util::GetVersionStringModifier(); | |
| 169 enabled = (channel == "dev"); | |
| 170 #endif | |
| 171 } | |
| 172 | |
| 173 return enabled; | |
| 174 } | |
| 175 | |
| 176 SpeechInputManagerImpl::SpeechInputManagerImpl() | 155 SpeechInputManagerImpl::SpeechInputManagerImpl() |
| 177 : recording_caller_id_(0), | 156 : recording_caller_id_(0), |
| 178 bubble_controller_(new SpeechInputBubbleController( | 157 bubble_controller_(new SpeechInputBubbleController( |
| 179 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { | 158 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { |
| 180 } | 159 } |
| 181 | 160 |
| 182 SpeechInputManagerImpl::~SpeechInputManagerImpl() { | 161 SpeechInputManagerImpl::~SpeechInputManagerImpl() { |
| 183 while (requests_.begin() != requests_.end()) | 162 while (requests_.begin() != requests_.end()) |
| 184 CancelRecognition(requests_.begin()->first); | 163 CancelRecognition(requests_.begin()->first); |
| 185 } | 164 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // to the user, abort it since user has switched focus. Otherwise | 333 // to the user, abort it since user has switched focus. Otherwise |
| 355 // recognition has started and keep that going so user can start speaking to | 334 // recognition has started and keep that going so user can start speaking to |
| 356 // another element while this gets the results in parallel. | 335 // another element while this gets the results in parallel. |
| 357 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { | 336 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { |
| 358 CancelRecognitionAndInformDelegate(caller_id); | 337 CancelRecognitionAndInformDelegate(caller_id); |
| 359 } | 338 } |
| 360 } | 339 } |
| 361 } | 340 } |
| 362 | 341 |
| 363 } // namespace speech_input | 342 } // namespace speech_input |
| OLD | NEW |