summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
authorallanwoj@chromium.org <allanwoj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-29 15:13:01 +0000
committerallanwoj@chromium.org <allanwoj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-29 15:13:01 +0000
commit8238dd6190819daade7ee98f669e23a5a56ee4fa (patch)
tree09debefb10323f762ccdf5b94c5722ea77b60d5d /content/browser
parent8cc6e41efa5af14f403cbb14b15e3af8ea686c93 (diff)
downloadchromium_src-8238dd6190819daade7ee98f669e23a5a56ee4fa.zip
chromium_src-8238dd6190819daade7ee98f669e23a5a56ee4fa.tar.gz
chromium_src-8238dd6190819daade7ee98f669e23a5a56ee4fa.tar.bz2
Remove use of default request context and fix use of speech censor flag
Now gets the request context and censor preference in BrowserRenderProcessHost and passes them through to the SpeechInputDispatcherHost. Each time a speech request is made, the SpeechInputDispatcherHost passes through these values to the SpeechInputManager. Also each time the censor preference changes, RenderViewContextMenu updates the current profile's SpeechInputPreferences. BUG=92366 TEST=Speech recognition works. Review URL: http://codereview.chromium.org/7989001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/browser_context.h5
-rw-r--r--content/browser/renderer_host/browser_render_process_host.cc4
-rw-r--r--content/browser/speech/speech_input_browsertest.cc4
-rw-r--r--content/browser/speech/speech_input_dispatcher_host.cc16
-rw-r--r--content/browser/speech/speech_input_dispatcher_host.h9
-rw-r--r--content/browser/speech/speech_input_manager.cc9
-rw-r--r--content/browser/speech/speech_input_manager.h11
-rw-r--r--content/browser/speech/speech_input_preferences.cc11
-rw-r--r--content/browser/speech/speech_input_preferences.h31
-rw-r--r--content/browser/speech/speech_recognizer.cc14
-rw-r--r--content/browser/speech/speech_recognizer.h6
-rw-r--r--content/browser/speech/speech_recognizer_unittest.cc2
12 files changed, 96 insertions, 26 deletions
diff --git a/content/browser/browser_context.h b/content/browser/browser_context.h
index feda556..8a3e39a 100644
--- a/content/browser/browser_context.h
+++ b/content/browser/browser_context.h
@@ -29,6 +29,7 @@ class ChromeBlobStorageContext;
class DownloadManager;
class FilePath;
class GeolocationPermissionContext;
+class SpeechInputPreferences;
class HostZoomMap;
class SSLHostState;
class WebKitContext;
@@ -86,6 +87,10 @@ class BrowserContext {
// Returns the geolocation permission context for this context.
virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0;
+ // Returns the speech input preferences. SpeechInputPreferences is a
+ // ref counted class, so callers should take a reference if needed.
+ virtual SpeechInputPreferences* GetSpeechInputPreferences() = 0;
+
// Returns true if the last time this context was open it was exited cleanly.
// This doesn't belong here; http://crbug.com/90737
virtual bool DidLastSessionExitCleanly() = 0;
diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc
index 10bee62..4d21e2e 100644
--- a/content/browser/renderer_host/browser_render_process_host.cc
+++ b/content/browser/renderer_host/browser_render_process_host.cc
@@ -381,7 +381,9 @@ void BrowserRenderProcessHost::CreateMessageFilters() {
channel_->AddFilter(new PepperFileMessageFilter(id(), browser_context()));
channel_->AddFilter(
new PepperMessageFilter(&browser_context()->GetResourceContext()));
- channel_->AddFilter(new speech_input::SpeechInputDispatcherHost(id()));
+ channel_->AddFilter(new speech_input::SpeechInputDispatcherHost(
+ id(), browser_context()->GetRequestContext(),
+ browser_context()->GetSpeechInputPreferences()));
channel_->AddFilter(
new FileSystemDispatcherHost(browser_context()->GetRequestContext(),
browser_context()->GetFileSystemContext()));
diff --git a/content/browser/speech/speech_input_browsertest.cc b/content/browser/speech/speech_input_browsertest.cc
index 4909a31..eae9b23 100644
--- a/content/browser/speech/speech_input_browsertest.cc
+++ b/content/browser/speech/speech_input_browsertest.cc
@@ -59,7 +59,9 @@ class FakeSpeechInputManager : public SpeechInputManager {
const gfx::Rect& element_rect,
const std::string& language,
const std::string& grammar,
- const std::string& origin_url) {
+ const std::string& origin_url,
+ net::URLRequestContextGetter* context_getter,
+ SpeechInputPreferences* speech_input_prefs) {
VLOG(1) << "StartRecognition invoked.";
EXPECT_EQ(0, caller_id_);
EXPECT_EQ(NULL, delegate_);
diff --git a/content/browser/speech/speech_input_dispatcher_host.cc b/content/browser/speech/speech_input_dispatcher_host.cc
index d8ec2d1..54fd4ee 100644
--- a/content/browser/speech/speech_input_dispatcher_host.cc
+++ b/content/browser/speech/speech_input_dispatcher_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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/lazy_instance.h"
#include "content/browser/content_browser_client.h"
+#include "content/browser/speech/speech_input_preferences.h"
#include "content/common/speech_input_messages.h"
namespace speech_input {
@@ -104,9 +105,14 @@ int SpeechInputDispatcherHost::SpeechInputCallers::request_id(int id) {
SpeechInputManager* SpeechInputDispatcherHost::manager_;
-SpeechInputDispatcherHost::SpeechInputDispatcherHost(int render_process_id)
+SpeechInputDispatcherHost::SpeechInputDispatcherHost(
+ int render_process_id,
+ net::URLRequestContextGetter* context_getter,
+ SpeechInputPreferences* speech_input_preferences)
: render_process_id_(render_process_id),
- may_have_pending_requests_(false) {
+ may_have_pending_requests_(false),
+ context_getter_(context_getter),
+ speech_input_preferences_(speech_input_preferences) {
// This is initialized by Browser. Do not add any non-trivial
// initialization here, instead do it lazily when required (e.g. see the
// method |manager()|) or add an Init() method.
@@ -155,7 +161,9 @@ void SpeechInputDispatcherHost::OnStartRecognition(
render_process_id_,
params.render_view_id, params.element_rect,
params.language, params.grammar,
- params.origin_url);
+ params.origin_url,
+ context_getter_.get(),
+ speech_input_preferences_.get());
}
void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id,
diff --git a/content/browser/speech/speech_input_dispatcher_host.h b/content/browser/speech/speech_input_dispatcher_host.h
index a56660f..4642bcb 100644
--- a/content/browser/speech/speech_input_dispatcher_host.h
+++ b/content/browser/speech/speech_input_dispatcher_host.h
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "content/browser/browser_message_filter.h"
#include "content/browser/speech/speech_input_manager.h"
+#include "net/url_request/url_request_context_getter.h"
struct SpeechInputHostMsg_StartRecognition_Params;
@@ -21,7 +22,10 @@ class SpeechInputDispatcherHost : public BrowserMessageFilter,
public:
class SpeechInputCallers;
- explicit SpeechInputDispatcherHost(int render_process_id);
+ SpeechInputDispatcherHost(
+ int render_process_id,
+ net::URLRequestContextGetter* context_getter,
+ SpeechInputPreferences* speech_input_preferences);
// SpeechInputManager::Delegate methods.
virtual void SetRecognitionResult(int caller_id,
@@ -53,6 +57,9 @@ class SpeechInputDispatcherHost : public BrowserMessageFilter,
int render_process_id_;
bool may_have_pending_requests_; // Set if we received any speech IPC request
+ scoped_refptr<net::URLRequestContextGetter> context_getter_;
+ scoped_refptr<SpeechInputPreferences> speech_input_preferences_;
+
static SpeechInputManager* manager_;
DISALLOW_COPY_AND_ASSIGN(SpeechInputDispatcherHost);
diff --git a/content/browser/speech/speech_input_manager.cc b/content/browser/speech/speech_input_manager.cc
index c247bb6..5a37ec7 100644
--- a/content/browser/speech/speech_input_manager.cc
+++ b/content/browser/speech/speech_input_manager.cc
@@ -5,13 +5,13 @@
#include "content/browser/speech/speech_input_manager.h"
#include "content/browser/browser_thread.h"
+#include "content/browser/speech/speech_input_preferences.h"
#include "media/audio/audio_manager.h"
namespace speech_input {
SpeechInputManager::SpeechInputManager()
: can_report_metrics_(false),
- censor_results_(true),
recording_caller_id_(0) {
}
@@ -52,7 +52,9 @@ void SpeechInputManager::StartRecognition(
const gfx::Rect& element_rect,
const std::string& language,
const std::string& grammar,
- const std::string& origin_url) {
+ const std::string& origin_url,
+ net::URLRequestContextGetter* context_getter,
+ SpeechInputPreferences* speech_input_prefs) {
DCHECK(!HasPendingRequest(caller_id));
ShowRecognitionRequested(
@@ -62,7 +64,8 @@ void SpeechInputManager::StartRecognition(
SpeechInputRequest* request = &requests_[caller_id];
request->delegate = delegate;
request->recognizer = new SpeechRecognizer(
- this, caller_id, language, grammar, censor_results(),
+ this, caller_id, language, grammar, context_getter,
+ speech_input_prefs->censor_results(),
request_info_, can_report_metrics_ ? origin_url : "");
request->is_active = false;
diff --git a/content/browser/speech/speech_input_manager.h b/content/browser/speech/speech_input_manager.h
index af14b0d..c690780 100644
--- a/content/browser/speech/speech_input_manager.h
+++ b/content/browser/speech/speech_input_manager.h
@@ -14,6 +14,8 @@
#include "content/common/speech_input_result.h"
#include "ui/gfx/rect.h"
+class SpeechInputPreferences;
+
namespace speech_input {
// This is the gatekeeper for speech recognition in the browser process. It
@@ -58,7 +60,9 @@ class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate {
const gfx::Rect& element_rect,
const std::string& language,
const std::string& grammar,
- const std::string& origin_url);
+ const std::string& origin_url,
+ net::URLRequestContextGetter* context_getter,
+ SpeechInputPreferences* speech_input_prefs);
virtual void CancelRecognition(int caller_id);
virtual void CancelAllRequestsWithDelegate(Delegate* delegate);
virtual void StopRecording(int caller_id);
@@ -75,10 +79,6 @@ class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate {
virtual void DidCompleteEnvironmentEstimation(int caller_id);
virtual void SetInputVolume(int caller_id, float volume, float noise_volume);
- void set_censor_results(bool censor) { censor_results_ = censor; }
-
- bool censor_results() { return censor_results_; }
-
protected:
// The pure virtual methods are used for displaying the current state of
// recognition and for fetching optional request information.
@@ -144,7 +144,6 @@ class CONTENT_EXPORT SpeechInputManager : public SpeechRecognizerDelegate {
SpeechRecognizerMap requests_;
std::string request_info_;
bool can_report_metrics_;
- bool censor_results_;
int recording_caller_id_;
};
diff --git a/content/browser/speech/speech_input_preferences.cc b/content/browser/speech/speech_input_preferences.cc
new file mode 100644
index 0000000..ae6e79e
--- /dev/null
+++ b/content/browser/speech/speech_input_preferences.cc
@@ -0,0 +1,11 @@
+// Copyright (c) 2011 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.
+
+#include "content/browser/speech/speech_input_preferences.h"
+
+SpeechInputPreferences::SpeechInputPreferences() {
+}
+
+SpeechInputPreferences::~SpeechInputPreferences() {
+}
diff --git a/content/browser/speech/speech_input_preferences.h b/content/browser/speech/speech_input_preferences.h
new file mode 100644
index 0000000..c4536ed
--- /dev/null
+++ b/content/browser/speech/speech_input_preferences.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 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_BROWSER_SPEECH_SPEECH_INPUT_PREFERENCES_H_
+#define CONTENT_BROWSER_SPEECH_SPEECH_INPUT_PREFERENCES_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "content/common/content_export.h"
+
+class CONTENT_EXPORT SpeechInputPreferences
+ : public base::RefCountedThreadSafe<SpeechInputPreferences> {
+ public:
+ SpeechInputPreferences();
+
+ // Only to be called on the IO thread.
+ virtual bool censor_results() const = 0;
+
+ virtual void set_censor_results(bool censor_results) = 0;
+
+ protected:
+ virtual ~SpeechInputPreferences();
+
+ private:
+ friend class base::RefCountedThreadSafe<SpeechInputPreferences>;
+
+ DISALLOW_COPY_AND_ASSIGN(SpeechInputPreferences);
+};
+
+#endif // CONTENT_BROWSER_SPEECH_SPEECH_INPUT_PREFERENCES_H_
diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc
index f6019f6..295f156 100644
--- a/content/browser/speech/speech_recognizer.cc
+++ b/content/browser/speech/speech_recognizer.cc
@@ -6,8 +6,6 @@
#include "base/time.h"
#include "content/browser/browser_thread.h"
-#include "content/browser/content_browser_client.h"
-#include "content/common/content_client.h"
#include "net/url_request/url_request_context_getter.h"
using media::AudioInputController;
@@ -59,6 +57,7 @@ SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
int caller_id,
const std::string& language,
const std::string& grammar,
+ net::URLRequestContextGetter* context_getter,
bool censor_results,
const std::string& hardware_info,
const std::string& origin_url)
@@ -69,6 +68,7 @@ SpeechRecognizer::SpeechRecognizer(Delegate* delegate,
censor_results_(censor_results),
hardware_info_(hardware_info),
origin_url_(origin_url),
+ context_getter_(context_getter),
codec_(AudioEncoder::CODEC_FLAC),
encoder_(NULL),
endpointer_(kAudioSampleRate),
@@ -224,13 +224,9 @@ void SpeechRecognizer::HandleOnData(string* data) {
// This was the first audio packet recorded, so start a request to the
// server to send the data and inform the delegate.
delegate_->DidStartReceivingAudio(caller_id_);
- // Deprecated; see http://crbug.com/92366
- net::URLRequestContextGetter* context_getter =
- content::GetContentClient()->browser()->
- GetDefaultRequestContextDeprecatedCrBug64339();
- request_.reset(new SpeechRecognitionRequest(context_getter, this));
- request_->Start(language_, grammar_, censor_results_, hardware_info_,
- origin_url_, encoder_->mime_type());
+ request_.reset(new SpeechRecognitionRequest(context_getter_.get(), this));
+ request_->Start(language_, grammar_, censor_results_,
+ hardware_info_, origin_url_, encoder_->mime_type());
}
string encoded_data;
diff --git a/content/browser/speech/speech_recognizer.h b/content/browser/speech/speech_recognizer.h
index e350e65..bd1c8e4 100644
--- a/content/browser/speech/speech_recognizer.h
+++ b/content/browser/speech/speech_recognizer.h
@@ -17,6 +17,10 @@
#include "content/common/content_export.h"
#include "media/audio/audio_input_controller.h"
+namespace net {
+class URLRequestContextGetter;
+}
+
namespace speech_input {
// Records audio, sends recorded audio to server and translates server response
@@ -83,6 +87,7 @@ class CONTENT_EXPORT SpeechRecognizer
int caller_id,
const std::string& language,
const std::string& grammar,
+ net::URLRequestContextGetter* context_getter,
bool censor_results,
const std::string& hardware_info,
const std::string& origin_url);
@@ -139,6 +144,7 @@ class CONTENT_EXPORT SpeechRecognizer
scoped_ptr<SpeechRecognitionRequest> request_;
scoped_refptr<media::AudioInputController> audio_controller_;
+ scoped_refptr<net::URLRequestContextGetter> context_getter_;
AudioEncoder::Codec codec_;
scoped_ptr<AudioEncoder> encoder_;
Endpointer endpointer_;
diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc
index 03b222b..17e3e56 100644
--- a/content/browser/speech/speech_recognizer_unittest.cc
+++ b/content/browser/speech/speech_recognizer_unittest.cc
@@ -25,7 +25,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
: io_thread_(BrowserThread::IO, &message_loop_),
ALLOW_THIS_IN_INITIALIZER_LIST(
recognizer_(new SpeechRecognizer(this, 1, std::string(),
- std::string(), false,
+ std::string(), NULL, false,
std::string(), std::string()))),
recording_complete_(false),
recognition_complete_(false),