summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 11:31:15 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 11:31:15 +0000
commit13167fff3ada75bd8c8dd8c6acc558d64ecde053 (patch)
treeca27eb32a3340db4ac10c077583c3a7082423ec9 /content
parent251ca36b35f7a9faef360c70acc84fc9a3ad1c40 (diff)
downloadchromium_src-13167fff3ada75bd8c8dd8c6acc558d64ecde053.zip
chromium_src-13167fff3ada75bd8c8dd8c6acc558d64ecde053.tar.gz
chromium_src-13167fff3ada75bd8c8dd8c6acc558d64ecde053.tar.bz2
Move SpeechRecognizer delegate into its own header file and put it in the content namespace.
This reverts commit 3942a25369d4e15de6c47b0c1df59827eec49a5e. This avoids having a nested class as it leads to too many includes in headers. This fixes the two issues raised by Win bots: - It includes speech_recognizer.h in certain source files to silence the warnings. - It tags SpeechRecognizerDelegate with CONTENT_EXPORT because SpeechInputManager is deriving from it and it's tagged with CONTENT_EXPORT, so we have to export the base class to silence the warning on Windows. BUG=98716 R=jam@chromium.org Review URL: https://chromiumcodereview.appspot.com/9388038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122276 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc1
-rw-r--r--content/browser/speech/speech_input_browsertest.cc1
-rw-r--r--content/browser/speech/speech_input_dispatcher_host.cc1
-rw-r--r--content/browser/speech/speech_input_manager.cc1
-rw-r--r--content/browser/speech/speech_input_manager.h17
-rw-r--r--content/browser/speech/speech_recognizer.cc5
-rw-r--r--content/browser/speech/speech_recognizer.h67
-rw-r--r--content/browser/speech/speech_recognizer_unittest.cc5
-rw-r--r--content/content_browser.gypi1
-rw-r--r--content/public/browser/speech_recognizer_delegate.h65
10 files changed, 98 insertions, 66 deletions
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 327a396..26b8f35 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -75,6 +75,7 @@
#include "content/browser/renderer_host/text_input_client_message_filter.h"
#include "content/browser/resolve_proxy_msg_helper.h"
#include "content/browser/speech/speech_input_dispatcher_host.h"
+#include "content/browser/speech/speech_recognizer.h"
#include "content/browser/trace_message_filter.h"
#include "content/browser/worker_host/worker_message_filter.h"
#include "content/common/child_process_host_impl.h"
diff --git a/content/browser/speech/speech_input_browsertest.cc b/content/browser/speech/speech_input_browsertest.cc
index 83e5c01..b7f24a0 100644
--- a/content/browser/speech/speech_input_browsertest.cc
+++ b/content/browser/speech/speech_input_browsertest.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/string_number_conversions.h"
+#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
diff --git a/content/browser/speech/speech_input_dispatcher_host.cc b/content/browser/speech/speech_input_dispatcher_host.cc
index ab28e17..7ad7798 100644
--- a/content/browser/speech/speech_input_dispatcher_host.cc
+++ b/content/browser/speech/speech_input_dispatcher_host.cc
@@ -5,6 +5,7 @@
#include "content/browser/speech/speech_input_dispatcher_host.h"
#include "base/lazy_instance.h"
+#include "content/browser/speech/speech_recognizer.h"
#include "content/common/speech_input_messages.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/resource_context.h"
diff --git a/content/browser/speech/speech_input_manager.cc b/content/browser/speech/speech_input_manager.cc
index 7f0ae43..b30abed 100644
--- a/content/browser/speech/speech_input_manager.cc
+++ b/content/browser/speech/speech_input_manager.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "content/browser/renderer_host/render_view_host.h"
+#include "content/browser/speech/speech_recognizer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host_delegate.h"
#include "content/public/browser/resource_context.h"
diff --git a/content/browser/speech/speech_input_manager.h b/content/browser/speech/speech_input_manager.h
index 33ec9a5..45cc71f 100644
--- a/content/browser/speech/speech_input_manager.h
+++ b/content/browser/speech/speech_input_manager.h
@@ -9,23 +9,34 @@
#include <string>
#include "base/basictypes.h"
-#include "content/browser/speech/speech_recognizer.h"
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "content/public/browser/speech_recognizer_delegate.h"
#include "content/common/content_export.h"
#include "ui/gfx/rect.h"
+class AudioManager;
+
namespace content {
class ResourceContext;
class SpeechInputPreferences;
struct SpeechInputResult;
}
+namespace net {
+class URLRequestContextGetter;
+}
+
namespace speech_input {
+class SpeechRecognizer;
+
// This is the gatekeeper for speech recognition in the browser process. It
// handles requests received from various render views and makes sure only one
// of them can use speech recognition at a time. It also sends recognition
// results and status events to the render views when required.
-class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate {
+class CONTENT_EXPORT SpeechInputManager
+ : public NON_EXPORTED_BASE(content::SpeechRecognizerDelegate) {
public:
// Implemented by the dispatcher host to relay events to the render views.
class Delegate {
@@ -84,7 +95,7 @@ class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate {
virtual void CancelAllRequestsWithDelegate(Delegate* delegate);
virtual void StopRecording(int caller_id);
- // SpeechRecognizerDelegate methods.
+ // Overridden from content::SpeechRecognizerDelegate:
virtual void DidStartReceivingAudio(int caller_id) OVERRIDE;
virtual void SetRecognitionResult(
int caller_id,
diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc
index 92cc02d..550aea9 100644
--- a/content/browser/speech/speech_recognizer.cc
+++ b/content/browser/speech/speech_recognizer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/time.h"
+#include "content/public/browser/speech_recognizer_delegate.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/speech_input_result.h"
#include "net/url_request/url_request_context_getter.h"
@@ -56,7 +57,7 @@ const int SpeechRecognizer::kNumBitsPerAudioSample = 16;
const int SpeechRecognizer::kNoSpeechTimeoutSec = 8;
const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300;
-SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
+SpeechRecognizer::SpeechRecognizer(content::SpeechRecognizerDelegate* delegate,
int caller_id,
const std::string& language,
const std::string& grammar,
diff --git a/content/browser/speech/speech_recognizer.h b/content/browser/speech/speech_recognizer.h
index 1e26754..67b1732 100644
--- a/content/browser/speech/speech_recognizer.h
+++ b/content/browser/speech/speech_recognizer.h
@@ -18,6 +18,10 @@
#include "content/public/common/speech_input_result.h"
#include "media/audio/audio_input_controller.h"
+namespace content {
+class SpeechRecognizerDelegate;
+}
+
namespace net {
class URLRequestContextGetter;
}
@@ -31,57 +35,7 @@ class CONTENT_EXPORT SpeechRecognizer
public media::AudioInputController::EventHandler,
public SpeechRecognitionRequestDelegate {
public:
- // Implemented by the caller to receive recognition events.
- class CONTENT_EXPORT Delegate {
- public:
- virtual void SetRecognitionResult(
- int caller_id,
- const content::SpeechInputResult& result) = 0;
-
- // Invoked when the first audio packet was received from the audio capture
- // device.
- virtual void DidStartReceivingAudio(int caller_id) = 0;
-
- // Invoked when audio recording stops, either due to the end pointer
- // detecting silence in user input or if |StopRecording| was called. The
- // delegate has to wait until |DidCompleteRecognition| is invoked before
- // destroying the |SpeechRecognizer| object.
- virtual void DidCompleteRecording(int caller_id) = 0;
-
- // This is guaranteed to be the last method invoked in the recognition
- // sequence and the |SpeechRecognizer| object can be freed up if necessary.
- virtual void DidCompleteRecognition(int caller_id) = 0;
-
- // Informs that the end pointer has started detecting speech.
- virtual void DidStartReceivingSpeech(int caller_id) = 0;
-
- // Informs that the end pointer has stopped detecting speech.
- virtual void DidStopReceivingSpeech(int caller_id) = 0;
-
- // Invoked if there was an error while recording or recognizing audio. The
- // session has already been cancelled when this call is made and the DidXxxx
- // callbacks will not be issued. It is safe to destroy/release the
- // |SpeechRecognizer| object while processing this call.
- virtual void OnRecognizerError(int caller_id,
- content::SpeechInputError error) = 0;
-
- // At the start of recognition, a short amount of audio is recorded to
- // estimate the environment/background noise and this callback is issued
- // after that is complete. Typically the delegate brings up any speech
- // recognition UI once this callback is received.
- virtual void DidCompleteEnvironmentEstimation(int caller_id) = 0;
-
- // Informs of a change in the captured audio level, useful if displaying
- // a microphone volume indicator while recording.
- // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range.
- virtual void SetInputVolume(int caller_id, float volume,
- float noise_volume) = 0;
-
- protected:
- virtual ~Delegate() {}
- };
-
- SpeechRecognizer(Delegate* delegate,
+ SpeechRecognizer(content::SpeechRecognizerDelegate* delegate,
int caller_id,
const std::string& language,
const std::string& grammar,
@@ -96,7 +50,8 @@ class CONTENT_EXPORT SpeechRecognizer
// Starts audio recording and does recognition after recording ends. The same
// SpeechRecognizer instance can be used multiple times for speech recognition
// though each recognition request can be made only after the previous one
- // completes (i.e. after receiving Delegate::DidCompleteRecognition).
+ // completes (i.e. after receiving
+ // SpeechRecognizerDelegate::DidCompleteRecognition).
bool StartRecording();
// Stops recording audio and starts recognition.
@@ -140,7 +95,7 @@ class CONTENT_EXPORT SpeechRecognizer
// Helper method which closes the audio controller and blocks until done.
void CloseAudioControllerSynchronously();
- Delegate* delegate_;
+ content::SpeechRecognizerDelegate* delegate_;
int caller_id_;
std::string language_;
std::string grammar_;
@@ -161,12 +116,6 @@ class CONTENT_EXPORT SpeechRecognizer
DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer);
};
-// This typedef is to workaround the issue with certain versions of
-// Visual Studio where it gets confused between multiple Delegate
-// classes and gives a C2500 error. (I saw this error on the try bots -
-// the workaround was not needed for my machine).
-typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate;
-
} // namespace speech_input
#endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_
diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc
index 953fcb0..17a18c9 100644
--- a/content/browser/speech/speech_recognizer_unittest.cc
+++ b/content/browser/speech/speech_recognizer_unittest.cc
@@ -6,6 +6,7 @@
#include "content/browser/browser_thread_impl.h"
#include "content/browser/speech/speech_recognizer.h"
+#include "content/public/browser/speech_recognizer_delegate.h"
#include "content/test/test_url_fetcher_factory.h"
#include "media/audio/audio_manager.h"
#include "media/audio/test_audio_input_controller_factory.h"
@@ -21,7 +22,7 @@ using media::TestAudioInputControllerFactory;
namespace speech_input {
-class SpeechRecognizerTest : public SpeechRecognizerDelegate,
+class SpeechRecognizerTest : public content::SpeechRecognizerDelegate,
public testing::Test {
public:
SpeechRecognizerTest()
@@ -44,7 +45,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
audio_packet_.resize(audio_packet_length_bytes);
}
- // SpeechRecognizer::Delegate methods.
+ // Overridden from content::SpeechRecognizerDelegate:
virtual void SetRecognitionResult(
int caller_id,
const content::SpeechInputResult& result) OVERRIDE {
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index d792939..63508f6 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -105,6 +105,7 @@
'public/browser/sensors_provider.h',
'public/browser/site_instance.h',
'public/browser/speech_input_preferences.h',
+ 'public/browser/speech_recognizer_delegate.h',
'public/browser/user_metrics.h',
'public/browser/utility_process_host.h',
'public/browser/web_contents.h',
diff --git a/content/public/browser/speech_recognizer_delegate.h b/content/public/browser/speech_recognizer_delegate.h
new file mode 100644
index 0000000..daf482a
--- /dev/null
+++ b/content/public/browser/speech_recognizer_delegate.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_
+#define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_
+#pragma once
+
+#include "content/public/common/speech_input_result.h"
+
+namespace content {
+
+// An interface to be implemented by consumers interested in receiving
+// recognition events.
+class SpeechRecognizerDelegate {
+ public:
+ virtual void SetRecognitionResult(int caller_id,
+ const SpeechInputResult& result) = 0;
+
+ // Invoked when the first audio packet was received from the audio capture
+ // device.
+ virtual void DidStartReceivingAudio(int caller_id) = 0;
+
+ // Invoked when audio recording stops, either due to the end pointer
+ // detecting silence in user input or if |StopRecording| was called. The
+ // delegate has to wait until |DidCompleteRecognition| is invoked before
+ // destroying the |SpeechRecognizer| object.
+ virtual void DidCompleteRecording(int caller_id) = 0;
+
+ // This is guaranteed to be the last method invoked in the recognition
+ // sequence and the |SpeechRecognizer| object can be freed up if necessary.
+ virtual void DidCompleteRecognition(int caller_id) = 0;
+
+ // Informs that the end pointer has started detecting speech.
+ virtual void DidStartReceivingSpeech(int caller_id) = 0;
+
+ // Informs that the end pointer has stopped detecting speech.
+ virtual void DidStopReceivingSpeech(int caller_id) = 0;
+
+ // Invoked if there was an error while recording or recognizing audio. The
+ // session has already been cancelled when this call is made and the DidXxxx
+ // callbacks will not be issued. It is safe to destroy/release the
+ // |SpeechRecognizer| object while processing this call.
+ virtual void OnRecognizerError(int caller_id, SpeechInputError error) = 0;
+
+ // At the start of recognition, a short amount of audio is recorded to
+ // estimate the environment/background noise and this callback is issued
+ // after that is complete. Typically the delegate brings up any speech
+ // recognition UI once this callback is received.
+ virtual void DidCompleteEnvironmentEstimation(int caller_id) = 0;
+
+ // Informs of a change in the captured audio level, useful if displaying
+ // a microphone volume indicator while recording.
+ // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range.
+ virtual void SetInputVolume(int caller_id,
+ float volume,
+ float noise_volume) = 0;
+
+ protected:
+ virtual ~SpeechRecognizerDelegate() {}
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_