summaryrefslogtreecommitdiffstats
path: root/chrome/browser/speech
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/speech')
-rw-r--r--chrome/browser/speech/speech_input_browsertest.cc3
-rw-r--r--chrome/browser/speech/speech_input_dispatcher_host.cc41
-rw-r--r--chrome/browser/speech/speech_input_dispatcher_host.h8
-rw-r--r--chrome/browser/speech/speech_input_manager.cc53
-rw-r--r--chrome/browser/speech/speech_input_manager.h5
-rw-r--r--chrome/browser/speech/speech_recognition_request.cc2
-rw-r--r--chrome/browser/speech/speech_recognition_request.h1
-rw-r--r--chrome/browser/speech/speech_recognition_request_unittest.cc2
-rw-r--r--chrome/browser/speech/speech_recognizer.cc8
-rw-r--r--chrome/browser/speech/speech_recognizer.h4
-rw-r--r--chrome/browser/speech/speech_recognizer_unittest.cc3
11 files changed, 74 insertions, 56 deletions
diff --git a/chrome/browser/speech/speech_input_browsertest.cc b/chrome/browser/speech/speech_input_browsertest.cc
index 5563fe9..e0b2aff 100644
--- a/chrome/browser/speech/speech_input_browsertest.cc
+++ b/chrome/browser/speech/speech_input_browsertest.cc
@@ -48,7 +48,8 @@ class FakeSpeechInputManager : public SpeechInputManager {
int render_view_id,
const gfx::Rect& element_rect,
const std::string& language,
- const std::string& grammar) {
+ const std::string& grammar,
+ const std::string& origin_url) {
VLOG(1) << "StartRecognition invoked.";
EXPECT_EQ(0, caller_id_);
EXPECT_EQ(NULL, delegate_);
diff --git a/chrome/browser/speech/speech_input_dispatcher_host.cc b/chrome/browser/speech/speech_input_dispatcher_host.cc
index 50b9aec..cfcbed7 100644
--- a/chrome/browser/speech/speech_input_dispatcher_host.cc
+++ b/chrome/browser/speech/speech_input_dispatcher_host.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/speech/speech_input_dispatcher_host.h"
#include "base/lazy_instance.h"
-#include "chrome/common/render_messages.h"
+#include "chrome/common/speech_input_messages.h"
namespace speech_input {
@@ -123,9 +123,9 @@ bool SpeechInputDispatcherHost::OnMessageReceived(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
uint32 message_type = message.type();
- if (message_type == ViewHostMsg_SpeechInput_StartRecognition::ID ||
- message_type == ViewHostMsg_SpeechInput_CancelRecognition::ID ||
- message_type == ViewHostMsg_SpeechInput_StopRecording::ID) {
+ if (message_type == SpeechInputHostMsg_StartRecognition::ID ||
+ message_type == SpeechInputHostMsg_CancelRecognition::ID ||
+ message_type == SpeechInputHostMsg_StopRecording::ID) {
if (!SpeechInputManager::IsFeatureEnabled()) {
*message_was_ok = false;
return true;
@@ -133,11 +133,11 @@ bool SpeechInputDispatcherHost::OnMessageReceived(
IPC_BEGIN_MESSAGE_MAP_EX(SpeechInputDispatcherHost, message,
*message_was_ok)
- IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StartRecognition,
+ IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StartRecognition,
OnStartRecognition)
- IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_CancelRecognition,
+ IPC_MESSAGE_HANDLER(SpeechInputHostMsg_CancelRecognition,
OnCancelRecognition)
- IPC_MESSAGE_HANDLER(ViewHostMsg_SpeechInput_StopRecording,
+ IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording,
OnStopRecording)
IPC_END_MESSAGE_MAP()
return true;
@@ -147,17 +147,14 @@ bool SpeechInputDispatcherHost::OnMessageReceived(
}
void SpeechInputDispatcherHost::OnStartRecognition(
- int render_view_id,
- int request_id,
- const gfx::Rect& element_rect,
- const std::string& language,
- const std::string& grammar) {
+ const SpeechInputHostMsg_StartRecognition_Params &params) {
int caller_id = g_speech_input_callers.Get().CreateId(
- render_process_id_, render_view_id, request_id);
+ render_process_id_, params.render_view_id, params.request_id);
manager()->StartRecognition(this, caller_id,
render_process_id_,
- render_view_id, element_rect,
- language, grammar);
+ params.render_view_id, params.element_rect,
+ params.language, params.grammar,
+ params.origin_url);
}
void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id,
@@ -186,9 +183,9 @@ void SpeechInputDispatcherHost::SetRecognitionResult(
int caller_render_view_id =
g_speech_input_callers.Get().render_view_id(caller_id);
int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
- Send(new ViewMsg_SpeechInput_SetRecognitionResult(caller_render_view_id,
- caller_request_id,
- result));
+ Send(new SpeechInputMsg_SetRecognitionResult(caller_render_view_id,
+ caller_request_id,
+ result));
VLOG(1) << "SpeechInputDispatcherHost::SetRecognitionResult exit";
}
@@ -198,8 +195,8 @@ void SpeechInputDispatcherHost::DidCompleteRecording(int caller_id) {
int caller_render_view_id =
g_speech_input_callers.Get().render_view_id(caller_id);
int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
- Send(new ViewMsg_SpeechInput_RecordingComplete(caller_render_view_id,
- caller_request_id));
+ Send(new SpeechInputMsg_RecordingComplete(caller_render_view_id,
+ caller_request_id));
VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecording exit";
}
@@ -209,8 +206,8 @@ void SpeechInputDispatcherHost::DidCompleteRecognition(int caller_id) {
int caller_render_view_id =
g_speech_input_callers.Get().render_view_id(caller_id);
int caller_request_id = g_speech_input_callers.Get().request_id(caller_id);
- Send(new ViewMsg_SpeechInput_RecognitionComplete(caller_render_view_id,
- caller_request_id));
+ Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id,
+ caller_request_id));
// Request sequence ended, so remove mapping.
g_speech_input_callers.Get().RemoveId(caller_id);
VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit";
diff --git a/chrome/browser/speech/speech_input_dispatcher_host.h b/chrome/browser/speech/speech_input_dispatcher_host.h
index 51ae04c..d8befd3 100644
--- a/chrome/browser/speech/speech_input_dispatcher_host.h
+++ b/chrome/browser/speech/speech_input_dispatcher_host.h
@@ -9,6 +9,8 @@
#include "chrome/browser/browser_message_filter.h"
#include "chrome/browser/speech/speech_input_manager.h"
+struct SpeechInputHostMsg_StartRecognition_Params;
+
namespace speech_input {
// SpeechInputDispatcherHost is a delegate for Speech API messages used by
@@ -39,10 +41,8 @@ class SpeechInputDispatcherHost : public BrowserMessageFilter,
private:
virtual ~SpeechInputDispatcherHost();
- void OnStartRecognition(int render_view_id, int request_id,
- const gfx::Rect& element_rect,
- const std::string& language,
- const std::string& grammar);
+ void OnStartRecognition(
+ const SpeechInputHostMsg_StartRecognition_Params &params);
void OnCancelRecognition(int render_view_id, int request_id);
void OnStopRecording(int render_view_id, int request_id);
diff --git a/chrome/browser/speech/speech_input_manager.cc b/chrome/browser/speech/speech_input_manager.cc
index 25f0550..f59a3b7 100644
--- a/chrome/browser/speech/speech_input_manager.cc
+++ b/chrome/browser/speech/speech_input_manager.cc
@@ -14,6 +14,7 @@
#include "base/ref_counted.h"
#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -27,26 +28,26 @@
#include "media/audio/audio_manager.h"
#if defined(OS_WIN)
-#include "chrome/browser/browser_process.h"
#include "chrome/installer/util/wmi.h"
#endif
namespace {
-// Asynchronously fetches the PC and audio hardware/driver info on windows if
+// Asynchronously fetches the PC and audio hardware/driver info if
// the user has opted into UMA. This information is sent with speech input
// requests to the server for identifying and improving quality issues with
// specific device configurations.
-class HardwareInfo : public base::RefCountedThreadSafe<HardwareInfo> {
+class OptionalRequestInfo
+ : public base::RefCountedThreadSafe<OptionalRequestInfo> {
public:
- HardwareInfo() {}
+ OptionalRequestInfo() : can_report_metrics_(false) {}
-#if defined(OS_WIN)
void Refresh() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// UMA opt-in can be checked only from the UI thread, so switch to that.
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &HardwareInfo::CheckUMAAndGetHardwareInfo));
+ NewRunnableMethod(this,
+ &OptionalRequestInfo::CheckUMAAndGetHardwareInfo));
}
void CheckUMAAndGetHardwareInfo() {
@@ -55,16 +56,22 @@ class HardwareInfo : public base::RefCountedThreadSafe<HardwareInfo> {
prefs::kMetricsReportingEnabled)) {
// Access potentially slow OS calls from the FILE thread.
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(this, &HardwareInfo::GetHardwareInfo));
+ NewRunnableMethod(this, &OptionalRequestInfo::GetHardwareInfo));
}
}
void GetHardwareInfo() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
AutoLock lock(lock_);
+ can_report_metrics_ = true;
+#if defined(OS_WIN)
value_ = UTF16ToUTF8(
installer::WMIComputerSystem::GetModel() + L"|" +
AudioManager::GetAudioManager()->GetAudioInputDeviceModel());
+#else // defined(OS_WIN)
+ value_ = UTF16ToUTF8(
+ AudioManager::GetAudioManager()->GetAudioInputDeviceModel());
+#endif // defined(OS_WIN)
}
std::string value() {
@@ -72,16 +79,17 @@ class HardwareInfo : public base::RefCountedThreadSafe<HardwareInfo> {
return value_;
}
+ bool can_report_metrics() {
+ AutoLock lock(lock_);
+ return can_report_metrics_;
+ }
+
private:
Lock lock_;
std::string value_;
+ bool can_report_metrics_;
-#else // defined(OS_WIN)
- void Refresh() {}
- std::string value() { return std::string(); }
-#endif // defined(OS_WIN)
-
- DISALLOW_COPY_AND_ASSIGN(HardwareInfo);
+ DISALLOW_COPY_AND_ASSIGN(OptionalRequestInfo);
};
} // namespace
@@ -99,7 +107,8 @@ class SpeechInputManagerImpl : public SpeechInputManager,
int render_view_id,
const gfx::Rect& element_rect,
const std::string& language,
- const std::string& grammar);
+ const std::string& grammar,
+ const std::string& origin_url);
virtual void CancelRecognition(int caller_id);
virtual void StopRecording(int caller_id);
@@ -143,7 +152,7 @@ class SpeechInputManagerImpl : public SpeechInputManager,
SpeechRecognizerMap requests_;
int recording_caller_id_;
scoped_refptr<SpeechInputBubbleController> bubble_controller_;
- scoped_refptr<HardwareInfo> hardware_info_;
+ scoped_refptr<OptionalRequestInfo> optional_request_info_;
};
static ::base::LazyInstance<SpeechInputManagerImpl> g_speech_input_manager_impl(
@@ -200,14 +209,15 @@ void SpeechInputManagerImpl::StartRecognition(
int render_view_id,
const gfx::Rect& element_rect,
const std::string& language,
- const std::string& grammar) {
+ const std::string& grammar,
+ const std::string& origin_url) {
DCHECK(!HasPendingRequest(caller_id));
bubble_controller_->CreateBubble(caller_id, render_process_id, render_view_id,
element_rect);
- if (!hardware_info_.get()) {
- hardware_info_ = new HardwareInfo();
+ if (!optional_request_info_.get()) {
+ optional_request_info_ = new OptionalRequestInfo();
// Since hardware info is optional with speech input requests, we start an
// asynchronous fetch here and move on with recording audio. This first
// speech input request would send an empty string for hardware info and
@@ -215,13 +225,14 @@ void SpeechInputManagerImpl::StartRecognition(
// completed before them. This way we don't end up stalling the user with
// a long wait and disk seeks when they click on a UI element and start
// speaking.
- hardware_info_->Refresh();
+ optional_request_info_->Refresh();
}
SpeechInputRequest* request = &requests_[caller_id];
request->delegate = delegate;
- request->recognizer = new SpeechRecognizer(this, caller_id, language,
- grammar, hardware_info_->value());
+ request->recognizer = new SpeechRecognizer(
+ this, caller_id, language, grammar, optional_request_info_->value(),
+ optional_request_info_->can_report_metrics() ? origin_url : "");
request->is_active = false;
StartRecognitionForRequest(caller_id);
diff --git a/chrome/browser/speech/speech_input_manager.h b/chrome/browser/speech/speech_input_manager.h
index ffeaba0..83bde90 100644
--- a/chrome/browser/speech/speech_input_manager.h
+++ b/chrome/browser/speech/speech_input_manager.h
@@ -37,7 +37,7 @@ class SpeechInputManager {
static bool IsFeatureEnabled();
// Factory method to access the singleton. We have this method here instead of
- // using Singleton<> directly in the calling code to aid tests in injection
+ // using Singleton directly in the calling code to aid tests in injection
// mocks.
static SpeechInputManager* Get();
// Factory method definition useful for tests.
@@ -59,7 +59,8 @@ class SpeechInputManager {
int render_view_id,
const gfx::Rect& element_rect,
const std::string& language,
- const std::string& grammar) = 0;
+ const std::string& grammar,
+ const std::string& origin_url) = 0;
virtual void CancelRecognition(int caller_id) = 0;
virtual void StopRecording(int caller_id) = 0;
};
diff --git a/chrome/browser/speech/speech_recognition_request.cc b/chrome/browser/speech/speech_recognition_request.cc
index 1281666..754534a 100644
--- a/chrome/browser/speech/speech_recognition_request.cc
+++ b/chrome/browser/speech/speech_recognition_request.cc
@@ -123,6 +123,7 @@ SpeechRecognitionRequest::~SpeechRecognitionRequest() {}
bool SpeechRecognitionRequest::Send(const std::string& language,
const std::string& grammar,
const std::string& hardware_info,
+ const std::string& origin_url,
const std::string& content_type,
const std::string& audio_data) {
DCHECK(!url_fetcher_.get());
@@ -161,6 +162,7 @@ bool SpeechRecognitionRequest::Send(const std::string& language,
this));
url_fetcher_->set_upload_data(content_type, audio_data);
url_fetcher_->set_request_context(url_context_);
+ url_fetcher_->set_referrer(origin_url);
// The speech recognition API does not require user identification as part
// of requests, so we don't send cookies or auth data for these requests to
diff --git a/chrome/browser/speech/speech_recognition_request.h b/chrome/browser/speech/speech_recognition_request.h
index c12fc4d..9b022cf 100644
--- a/chrome/browser/speech/speech_recognition_request.h
+++ b/chrome/browser/speech/speech_recognition_request.h
@@ -48,6 +48,7 @@ class SpeechRecognitionRequest : public URLFetcher::Delegate {
bool Send(const std::string& language,
const std::string& grammar,
const std::string& hardware_info,
+ const std::string& origin_url,
const std::string& content_type,
const std::string& audio_data);
diff --git a/chrome/browser/speech/speech_recognition_request_unittest.cc b/chrome/browser/speech/speech_recognition_request_unittest.cc
index cf3f60b..bd2a26e 100644
--- a/chrome/browser/speech/speech_recognition_request_unittest.cc
+++ b/chrome/browser/speech/speech_recognition_request_unittest.cc
@@ -47,7 +47,7 @@ void SpeechRecognitionRequestTest::CreateAndTestRequest(
bool success, const std::string& http_response) {
SpeechRecognitionRequest request(NULL, this);
request.Send(std::string(), std::string(), std::string(), std::string(),
- std::string());
+ std::string(), std::string());
TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
ASSERT_TRUE(fetcher);
net::URLRequestStatus status;
diff --git a/chrome/browser/speech/speech_recognizer.cc b/chrome/browser/speech/speech_recognizer.cc
index 6d46a72..38bbeca 100644
--- a/chrome/browser/speech/speech_recognizer.cc
+++ b/chrome/browser/speech/speech_recognizer.cc
@@ -39,12 +39,14 @@ SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
int caller_id,
const std::string& language,
const std::string& grammar,
- const std::string& hardware_info)
+ const std::string& hardware_info,
+ const std::string& origin_url)
: delegate_(delegate),
caller_id_(caller_id),
language_(language),
grammar_(grammar),
hardware_info_(hardware_info),
+ origin_url_(origin_url),
codec_(AudioEncoder::CODEC_SPEEX),
encoder_(NULL),
endpointer_(kAudioSampleRate),
@@ -136,8 +138,8 @@ void SpeechRecognizer::StopRecording() {
DCHECK(!request_.get());
request_.reset(new SpeechRecognitionRequest(
Profile::GetDefaultRequestContext(), this));
- request_->Send(language_, grammar_, hardware_info_, encoder_->mime_type(),
- data);
+ request_->Send(language_, grammar_, hardware_info_, origin_url_,
+ encoder_->mime_type(), data);
}
encoder_.reset();
}
diff --git a/chrome/browser/speech/speech_recognizer.h b/chrome/browser/speech/speech_recognizer.h
index 5e8511f..2570fba 100644
--- a/chrome/browser/speech/speech_recognizer.h
+++ b/chrome/browser/speech/speech_recognizer.h
@@ -76,7 +76,8 @@ class SpeechRecognizer
int caller_id,
const std::string& language,
const std::string& grammar,
- const std::string& hardware_info);
+ const std::string& hardware_info,
+ const std::string& origin_url);
~SpeechRecognizer();
// Starts audio recording and does recognition after recording ends. The same
@@ -126,6 +127,7 @@ class SpeechRecognizer
std::string language_;
std::string grammar_;
std::string hardware_info_;
+ std::string origin_url_;
scoped_ptr<SpeechRecognitionRequest> request_;
scoped_refptr<media::AudioInputController> audio_controller_;
diff --git a/chrome/browser/speech/speech_recognizer_unittest.cc b/chrome/browser/speech/speech_recognizer_unittest.cc
index 05830d5d..855f35a 100644
--- a/chrome/browser/speech/speech_recognizer_unittest.cc
+++ b/chrome/browser/speech/speech_recognizer_unittest.cc
@@ -24,7 +24,8 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
: io_thread_(BrowserThread::IO, &message_loop_),
ALLOW_THIS_IN_INITIALIZER_LIST(
recognizer_(new SpeechRecognizer(this, 1, std::string(),
- std::string(), std::string()))),
+ std::string(), std::string(),
+ std::string()))),
recording_complete_(false),
recognition_complete_(false),
result_received_(false),