diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 13:57:05 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 13:57:05 +0000 |
commit | ca97f30c1c6e282f62880c6b1d5e165b9ece716f (patch) | |
tree | 75f7f5abe47a49e5c603eacbe7abf993d232aad2 /chrome/browser/speech/speech_input_manager.cc | |
parent | c33ec4af81ba1d13ec18eb7b0e542c05a2c9d4b0 (diff) | |
download | chromium_src-ca97f30c1c6e282f62880c6b1d5e165b9ece716f.zip chromium_src-ca97f30c1c6e282f62880c6b1d5e165b9ece716f.tar.gz chromium_src-ca97f30c1c6e282f62880c6b1d5e165b9ece716f.tar.bz2 |
If user had consented for metrics reporting, send speech input request origin to the server.
This is the chromium side of the webkit patch https://bugs.webkit.org/show_bug.cgi?id=52718.
Suggested reviewer split:
wtc@ - the 2 url_fetcher.* files
hans@ - rest of the files
I needed to add a URLFetcher::set_referrer() method to send the origin url in the Referer header.
Also I had to create a new IPC params struct for startRecognition since the
number of parameters exceed what is provided by the macros. And in the process I also moved
the speech input IPC messages to their own source files.
BUG=none
TEST=No change in functionality except additional debug info sent to server.
Review URL: http://codereview.chromium.org/6308009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/speech/speech_input_manager.cc')
-rw-r--r-- | chrome/browser/speech/speech_input_manager.cc | 53 |
1 files changed, 32 insertions, 21 deletions
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); |