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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/command_line.h" | 8 #include "base/ref_counted.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/singleton.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
11 #include "chrome/browser/prefs/pref_service.h" | |
12 #include "chrome/browser/speech/speech_input_bubble_controller.h" | 11 #include "chrome/browser/speech/speech_input_bubble_controller.h" |
13 #include "chrome/browser/speech/speech_recognizer.h" | 12 #include "chrome/browser/speech/speech_recognizer.h" |
14 #include "chrome/browser/tab_contents/infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/infobar_delegate.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/browser/tab_contents/tab_util.h" | 15 #include "chrome/browser/tab_contents/tab_util.h" |
17 #include "chrome/common/chrome_switches.h" | |
18 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
19 #include "media/audio/audio_manager.h" | 17 #include "media/audio/audio_manager.h" |
20 #include <map> | 18 #include <map> |
21 | 19 |
22 namespace speech_input { | 20 namespace speech_input { |
23 | 21 |
24 class SpeechInputManagerImpl : public SpeechInputManager, | 22 class SpeechInputManagerImpl : public SpeechInputManager, |
25 public SpeechInputBubbleControllerDelegate, | 23 public SpeechInputBubbleControllerDelegate, |
26 public SpeechRecognizerDelegate { | 24 public SpeechRecognizerDelegate { |
27 public: | 25 public: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; | 71 typedef std::map<int, SpeechInputRequest> SpeechRecognizerMap; |
74 SpeechRecognizerMap requests_; | 72 SpeechRecognizerMap requests_; |
75 int recording_caller_id_; | 73 int recording_caller_id_; |
76 scoped_refptr<SpeechInputBubbleController> bubble_controller_; | 74 scoped_refptr<SpeechInputBubbleController> bubble_controller_; |
77 }; | 75 }; |
78 | 76 |
79 SpeechInputManager* SpeechInputManager::Get() { | 77 SpeechInputManager* SpeechInputManager::Get() { |
80 return Singleton<SpeechInputManagerImpl>::get(); | 78 return Singleton<SpeechInputManagerImpl>::get(); |
81 } | 79 } |
82 | 80 |
83 bool SpeechInputManager::IsFeatureEnabled() { | |
84 bool enabled = true; | |
85 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
86 | |
87 if (command_line.HasSwitch(switches::kDisableSpeechInput)) { | |
88 enabled = false; | |
89 #if defined(GOOGLE_CHROME_BUILD) | |
90 } else if (!command_line.HasSwitch(switches::kEnableSpeechInput)) { | |
91 // We need to evaluate whether IO is OK here. http://crbug.com/63335. | |
92 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
93 // Official Chrome builds have speech input enabled by default only in the | |
94 // dev channel. | |
95 std::string channel = platform_util::GetVersionStringModifier(); | |
96 enabled = (channel == "dev"); | |
97 #endif | |
98 } | |
99 | |
100 return enabled; | |
101 } | |
102 | |
103 SpeechInputManagerImpl::SpeechInputManagerImpl() | 81 SpeechInputManagerImpl::SpeechInputManagerImpl() |
104 : recording_caller_id_(0), | 82 : recording_caller_id_(0), |
105 bubble_controller_(new SpeechInputBubbleController( | 83 bubble_controller_(new SpeechInputBubbleController( |
106 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { | 84 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { |
107 } | 85 } |
108 | 86 |
109 SpeechInputManagerImpl::~SpeechInputManagerImpl() { | 87 SpeechInputManagerImpl::~SpeechInputManagerImpl() { |
110 while (requests_.begin() != requests_.end()) | 88 while (requests_.begin() != requests_.end()) |
111 CancelRecognition(requests_.begin()->first); | 89 CancelRecognition(requests_.begin()->first); |
112 } | 90 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // to the user, abort it since user has switched focus. Otherwise | 246 // to the user, abort it since user has switched focus. Otherwise |
269 // recognition has started and keep that going so user can start speaking to | 247 // recognition has started and keep that going so user can start speaking to |
270 // another element while this gets the results in parallel. | 248 // another element while this gets the results in parallel. |
271 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { | 249 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) { |
272 CancelRecognitionAndInformDelegate(caller_id); | 250 CancelRecognitionAndInformDelegate(caller_id); |
273 } | 251 } |
274 } | 252 } |
275 } | 253 } |
276 | 254 |
277 } // namespace speech_input | 255 } // namespace speech_input |
OLD | NEW |