summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-09 21:10:29 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-09 21:10:29 +0000
commit9232738f3f237d64e15fe17f9830b516652f5c86 (patch)
treee8e64d72bdab3ff5a33c57c674f72105fcddf771
parenta081aebba3483e4605cff0e81b917b69b0f49fe3 (diff)
downloadchromium_src-9232738f3f237d64e15fe17f9830b516652f5c86.zip
chromium_src-9232738f3f237d64e15fe17f9830b516652f5c86.tar.gz
chromium_src-9232738f3f237d64e15fe17f9830b516652f5c86.tar.bz2
Get rid of the SpeechRecognitionPreferences interface. It only had one method, and we can roll that into SpeechRecognitionDelegate instead to simplify things. This also allows us to get rid of ChromeSpeechRecognitionPreferences.
R=tommi@chromium.org Review URL: https://codereview.chromium.org/18487007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210616 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--android_webview/browser/aw_browser_context.cc6
-rw-r--r--android_webview/browser/aw_browser_context.h2
-rw-r--r--chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc4
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc5
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h2
-rw-r--r--chrome/browser/profiles/profile.cc4
-rw-r--r--chrome/browser/profiles/profile_impl.cc10
-rw-r--r--chrome/browser/profiles/profile_impl.h6
-rw-r--r--chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc15
-rw-r--r--chrome/browser/speech/chrome_speech_recognition_manager_delegate.h1
-rw-r--r--chrome/browser/speech/chrome_speech_recognition_preferences.cc219
-rw-r--r--chrome/browser/speech/chrome_speech_recognition_preferences.h124
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc11
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/test/base/testing_profile.cc10
-rw-r--r--chrome/test/base/testing_profile.h2
-rw-r--r--content/browser/download/download_manager_impl_unittest.cc2
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc6
-rw-r--r--content/browser/speech/input_tag_speech_dispatcher_host.cc107
-rw-r--r--content/browser/speech/input_tag_speech_dispatcher_host.h14
-rw-r--r--content/browser/speech/speech_recognition_browsertest.cc2
-rw-r--r--content/browser/speech/speech_recognition_dispatcher_host.cc98
-rw-r--r--content/browser/speech/speech_recognition_dispatcher_host.h19
-rw-r--r--content/browser/speech/speech_recognition_manager_impl.h2
-rw-r--r--content/content_browser.gypi1
-rw-r--r--content/public/browser/browser_context.h6
-rw-r--r--content/public/browser/speech_recognition_manager_delegate.h7
-rw-r--r--content/public/browser/speech_recognition_preferences.h26
-rw-r--r--content/public/test/fake_speech_recognition_manager.cc23
-rw-r--r--content/public/test/fake_speech_recognition_manager.h8
-rw-r--r--content/public/test/test_browser_context.cc5
-rw-r--r--content/public/test/test_browser_context.h2
-rw-r--r--content/shell/shell_browser_context.cc5
-rw-r--r--content/shell/shell_browser_context.h2
34 files changed, 170 insertions, 588 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc
index 06793fa..02fd0c3 100644
--- a/android_webview/browser/aw_browser_context.cc
+++ b/android_webview/browser/aw_browser_context.cc
@@ -216,12 +216,6 @@ AwBrowserContext::GetGeolocationPermissionContext() {
return geolocation_permission_context_.get();
}
-content::SpeechRecognitionPreferences*
-AwBrowserContext::GetSpeechRecognitionPreferences() {
- // By default allows profanities in speech recognition if return NULL.
- return NULL;
-}
-
quota::SpecialStoragePolicy* AwBrowserContext::GetSpecialStoragePolicy() {
// TODO(boliu): Implement this so we are not relying on default behavior.
NOTIMPLEMENTED();
diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h
index 4f281c1..4d672bc 100644
--- a/android_webview/browser/aw_browser_context.h
+++ b/android_webview/browser/aw_browser_context.h
@@ -91,8 +91,6 @@ class AwBrowserContext : public content::BrowserContext,
GetDownloadManagerDelegate() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
- virtual content::SpeechRecognitionPreferences*
- GetSpeechRecognitionPreferences() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
// visitedlink::VisitedLinkDelegate implementation.
diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
index e5ca157..06426c2 100644
--- a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
+++ b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
@@ -83,7 +83,6 @@
#include "chrome/browser/signin/about_signin_internals_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service_factory.h"
-#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
#include "chrome/browser/speech/extension_api/tts_extension_api.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -176,9 +175,6 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#if defined(OS_CHROMEOS)
chromeos::NetworkingPrivateEventRouterFactory::GetInstance();
#endif
-#if defined(ENABLE_INPUT_SPEECH)
- ChromeSpeechRecognitionPreferences::InitializeFactory();
-#endif
#if defined(ENABLE_PRINTING)
CloudPrintProxyServiceFactory::GetInstance();
#endif
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 592ed84..64064a7 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -321,11 +321,6 @@ content::GeolocationPermissionContext*
return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
}
-content::SpeechRecognitionPreferences*
- OffTheRecordProfileImpl::GetSpeechRecognitionPreferences() {
- return profile_->GetSpeechRecognitionPreferences();
-}
-
quota::SpecialStoragePolicy*
OffTheRecordProfileImpl::GetSpecialStoragePolicy() {
return GetExtensionSpecialStoragePolicy();
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index f6053e1..9f6ed29 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -101,8 +101,6 @@ class OffTheRecordProfileImpl : public Profile {
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
- virtual content::SpeechRecognitionPreferences*
- GetSpeechRecognitionPreferences() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
private:
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index d060484..0f86688 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -111,6 +111,10 @@ void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
prefs::kDefaultApps,
"install",
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+ registry->RegisterBooleanPref(
+ prefs::kSpeechRecognitionFilterProfanities,
+ true,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
#if defined(OS_CHROMEOS)
// TODO(dilmah): For OS_CHROMEOS we maintain kApplicationLocale in both
// local state and user's profile. For other platforms we maintain
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index aa86bf0..7123d16 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -67,7 +67,6 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/sessions/session_service_factory.h"
-#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/user_style_sheet_watcher.h"
@@ -903,15 +902,6 @@ content::GeolocationPermissionContext*
return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
}
-content::SpeechRecognitionPreferences*
-ProfileImpl::GetSpeechRecognitionPreferences() {
-#if defined(ENABLE_INPUT_SPEECH)
- return ChromeSpeechRecognitionPreferences::GetForProfile(this).get();
-#else
- return NULL;
-#endif
-}
-
DownloadManagerDelegate* ProfileImpl::GetDownloadManagerDelegate() {
return DownloadServiceFactory::GetForProfile(this)->
GetDownloadManagerDelegate();
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 59e125c..a8ece65 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -37,10 +37,6 @@ namespace base {
class SequencedTaskRunner;
}
-namespace content {
-class SpeechRecognitionPreferences;
-}
-
namespace extensions {
class ExtensionSystem;
}
@@ -81,8 +77,6 @@ class ProfileImpl : public Profile {
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
- virtual content::SpeechRecognitionPreferences*
- GetSpeechRecognitionPreferences() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
// Profile implementation:
diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc
index 24e74ef..0d4bb39 100644
--- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc
+++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
@@ -343,8 +342,7 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
// Make sure that initiators (extensions/web pages) properly set the
- // |render_process_id| field, which is needed later to retrieve the
- // ChromeSpeechRecognitionPreferences associated to their profile.
+ // |render_process_id| field, which is needed later to retrieve the profile.
DCHECK_NE(context.render_process_id, 0);
// Check that the render view type is appropriate, and whether or not we
@@ -362,6 +360,17 @@ ChromeSpeechRecognitionManagerDelegate::GetEventListener() {
return this;
}
+bool ChromeSpeechRecognitionManagerDelegate::FilterProfanities(
+ int render_process_id) {
+ content::RenderProcessHost* rph =
+ content::RenderProcessHost::FromID(render_process_id);
+ if (!rph) // Guard against race conditions on RPH lifetime.
+ return true;
+
+ return Profile::FromBrowserContext(rph->GetBrowserContext())->GetPrefs()->
+ GetBoolean(prefs::kSpeechRecognitionFilterProfanities);
+}
+
void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
base::Callback<void(bool ask_user, bool is_allowed)> callback,
int render_process_id,
diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h
index 7cd5a77..1d33a71 100644
--- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h
+++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.h
@@ -45,6 +45,7 @@ class ChromeSpeechRecognitionManagerDelegate
int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) OVERRIDE;
virtual content::SpeechRecognitionEventListener* GetEventListener() OVERRIDE;
+ virtual bool FilterProfanities(int render_process_id) OVERRIDE;
// Callback called by |tab_watcher_| on the IO thread to signal tab closure.
virtual void TabClosedCallback(int render_process_id, int render_view_id);
diff --git a/chrome/browser/speech/chrome_speech_recognition_preferences.cc b/chrome/browser/speech/chrome_speech_recognition_preferences.cc
deleted file mode 100644
index dea478a..0000000
--- a/chrome/browser/speech/chrome_speech_recognition_preferences.cc
+++ /dev/null
@@ -1,219 +0,0 @@
-// 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.
-
-#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
-
-#include "base/bind.h"
-#include "base/prefs/pref_service.h"
-#include "base/values.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/pref_names.h"
-#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
-#include "components/user_prefs/pref_registry_syncable.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_details.h"
-
-using base::ListValue;
-using content::BrowserThread;
-
-namespace {
-const bool kDefaultFilterProfanities = true;
-const bool kDefaultShownSecurityNotification = false;
-}
-
-ChromeSpeechRecognitionPreferences::Factory*
-ChromeSpeechRecognitionPreferences::Factory::GetInstance() {
- return Singleton<ChromeSpeechRecognitionPreferences::Factory>::get();
-}
-
-void ChromeSpeechRecognitionPreferences::InitializeFactory() {
- ChromeSpeechRecognitionPreferences::Factory::GetInstance();
-}
-
-scoped_refptr<ChromeSpeechRecognitionPreferences>
-ChromeSpeechRecognitionPreferences::Factory::GetForProfile(Profile* profile) {
- DCHECK(profile);
- // GetServiceForBrowserContext will let us instantiate a new (if not already
- // cached for the profile) Service through BuildServiceInstanceFor method.
- ChromeSpeechRecognitionPreferences::Service* service =
- static_cast<ChromeSpeechRecognitionPreferences::Service*>(
- GetServiceForBrowserContext(profile, true));
-
- if (!service) {
- // Incognito won't have this service.
- return NULL;
- }
-
- return service->GetPreferences();
-}
-
-ChromeSpeechRecognitionPreferences::Factory::Factory()
- : BrowserContextKeyedServiceFactory(
- "ChromeSpeechRecognitionPreferences",
- BrowserContextDependencyManager::GetInstance()) {
-}
-
-ChromeSpeechRecognitionPreferences::Factory::~Factory() {
-}
-
-BrowserContextKeyedService*
-ChromeSpeechRecognitionPreferences::Factory::BuildServiceInstanceFor(
- content::BrowserContext* profile) const {
- DCHECK(profile);
- return new ChromeSpeechRecognitionPreferences::Service(
- static_cast<Profile*>(profile));
-}
-
-void ChromeSpeechRecognitionPreferences::Factory::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* prefs) {
- prefs->RegisterBooleanPref(
- prefs::kSpeechRecognitionFilterProfanities,
- kDefaultFilterProfanities,
- user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-
- prefs->RegisterListPref(
- prefs::kSpeechRecognitionTrayNotificationShownContexts,
- user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-}
-
-bool ChromeSpeechRecognitionPreferences::Factory::
-ServiceIsNULLWhileTesting() const {
- return true;
-}
-
-bool ChromeSpeechRecognitionPreferences::Factory::
-ServiceIsCreatedWithBrowserContext() const {
- return false;
-}
-
-ChromeSpeechRecognitionPreferences::Service::Service(
- Profile* profile)
- : preferences_(new ChromeSpeechRecognitionPreferences(profile)) {
-}
-
-ChromeSpeechRecognitionPreferences::Service::~Service() {
-}
-
-void ChromeSpeechRecognitionPreferences::Service::Shutdown() {
- DCHECK(preferences_.get());
- preferences_->DetachFromProfile();
-}
-
-scoped_refptr<ChromeSpeechRecognitionPreferences>
-ChromeSpeechRecognitionPreferences::Service::GetPreferences() const {
- return preferences_;
-}
-
-scoped_refptr<ChromeSpeechRecognitionPreferences>
-ChromeSpeechRecognitionPreferences::GetForProfile(Profile* profile) {
- scoped_refptr<ChromeSpeechRecognitionPreferences> ret;
- if (profile) {
- // Note that when in incognito, GetForProfile will return NULL.
- // We catch that case below and return the default preferences.
- ret = Factory::GetInstance()->GetForProfile(profile);
- }
-
- if (!ret.get()) {
- // Create a detached preferences object if no profile is provided.
- ret = new ChromeSpeechRecognitionPreferences(NULL);
- }
-
- return ret;
-}
-
-ChromeSpeechRecognitionPreferences::ChromeSpeechRecognitionPreferences(
- Profile* profile)
- : profile_(profile),
- pref_change_registrar_(new PrefChangeRegistrar()),
- filter_profanities_(kDefaultFilterProfanities),
- notifications_shown_(new ListValue()) {
- if (!profile_)
- return;
-
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- pref_change_registrar_->Init(profile_->GetPrefs());
-
- ReloadFilterProfanities();
- pref_change_registrar_->Add(
- prefs::kSpeechRecognitionFilterProfanities,
- base::Bind(&ChromeSpeechRecognitionPreferences::ReloadFilterProfanities,
- base::Unretained(this)));
-
- ReloadNotificationsShown();
- pref_change_registrar_->Add(
- prefs::kSpeechRecognitionTrayNotificationShownContexts,
- base::Bind(&ChromeSpeechRecognitionPreferences::ReloadNotificationsShown,
- base::Unretained(this)));
-}
-
-ChromeSpeechRecognitionPreferences::~ChromeSpeechRecognitionPreferences() {
-}
-
-void ChromeSpeechRecognitionPreferences::DetachFromProfile() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(profile_);
- pref_change_registrar_.reset();
- profile_ = NULL;
-}
-
-bool ChromeSpeechRecognitionPreferences::FilterProfanities() const {
- base::AutoLock read_lock(preferences_lock_);
- return filter_profanities_;
-}
-
-void ChromeSpeechRecognitionPreferences::SetFilterProfanities(
- bool filter_profanities) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- {
- base::AutoLock write_lock(preferences_lock_);
- filter_profanities_ = filter_profanities;
- }
- if (profile_) {
- profile_->GetPrefs()->SetBoolean(prefs::kSpeechRecognitionFilterProfanities,
- filter_profanities);
- }
-}
-
-void ChromeSpeechRecognitionPreferences::ToggleFilterProfanities() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- SetFilterProfanities(!FilterProfanities());
-}
-
-bool ChromeSpeechRecognitionPreferences::ShouldShowSecurityNotification(
- const std::string& context_name) const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(notifications_shown_.get());
- scoped_ptr<base::StringValue> match_name(
- base::Value::CreateStringValue(context_name));
- return notifications_shown_->Find(*match_name) == notifications_shown_->end();
-}
-
-void ChromeSpeechRecognitionPreferences::SetHasShownSecurityNotification(
- const std::string& context_name) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(notifications_shown_.get());
- notifications_shown_->AppendIfNotPresent(
- base::Value::CreateStringValue(context_name));
- if (profile_) {
- profile_->GetPrefs()->Set(
- prefs::kSpeechRecognitionTrayNotificationShownContexts,
- *notifications_shown_);
- }
-}
-
-void ChromeSpeechRecognitionPreferences::ReloadFilterProfanities() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- base::AutoLock write_lock(preferences_lock_);
- filter_profanities_ = profile_->GetPrefs()->GetBoolean(
- prefs::kSpeechRecognitionFilterProfanities);
-}
-
-void ChromeSpeechRecognitionPreferences::ReloadNotificationsShown() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- base::AutoLock write_lock(preferences_lock_);
- const base::ListValue* pref_list = profile_->GetPrefs()->GetList(
- prefs::kSpeechRecognitionTrayNotificationShownContexts);
- notifications_shown_.reset(pref_list->DeepCopy());
-}
diff --git a/chrome/browser/speech/chrome_speech_recognition_preferences.h b/chrome/browser/speech/chrome_speech_recognition_preferences.h
deleted file mode 100644
index 17640be..0000000
--- a/chrome/browser/speech/chrome_speech_recognition_preferences.h
+++ /dev/null
@@ -1,124 +0,0 @@
-// 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 CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_
-#define CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/singleton.h"
-#include "base/prefs/pref_change_registrar.h"
-#include "base/synchronization/lock.h"
-#include "base/threading/non_thread_safe.h"
-#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
-#include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
-#include "content/public/browser/speech_recognition_preferences.h"
-
-class PrefService;
-class Profile;
-
-namespace base {
-class ListValue;
-}
-
-// Utility class that handles persistent storage of speech recognition
-// preferences. Instances of this class must be obtained exclusively through the
-// method ChromeSpeechRecognitionPreferences::GetForProfile(...), so that
-// preferences are handled within the Profile (if not NULL). The internal
-// factory class also handles ownership and lifetime of the
-// ChromeSpeechRecognitionPreferences instances (through the inner Service
-// class), allowing them to be used in a detached mode (no persistent storage)
-// even when a Profile is not available (or has been shutdown).
-
-class ChromeSpeechRecognitionPreferences
- : public content::SpeechRecognitionPreferences {
- public:
- static void InitializeFactory();
- static scoped_refptr<ChromeSpeechRecognitionPreferences> GetForProfile(
- Profile* profile);
-
- // content::SpeechRecognitionPreferences implementation.
- // Called by both Content (on IO thread) and Chrome (on UI thread).
- virtual bool FilterProfanities() const OVERRIDE;
-
- // Called only by Chrome (on UI thread).
- void SetFilterProfanities(bool filter_profanities);
- void ToggleFilterProfanities();
- bool ShouldShowSecurityNotification(const std::string& context_name) const;
- void SetHasShownSecurityNotification(const std::string& context_name);
-
- private:
- // The two classes below are needed to handle storage of speech recognition
- // preferences in profile preferences, according to the Chromium Profile
- // Architecture document entitled "The New Way:
- // BrowserContextKeyedServiceFactory".
-
- // Singleton that manages instantiation of ChromeSpeechRecognitionPreferences
- // handling its association with Profiles.
- class Factory : public BrowserContextKeyedServiceFactory {
- public:
- static Factory* GetInstance();
- scoped_refptr<ChromeSpeechRecognitionPreferences> GetForProfile(
- Profile* profile);
-
- private:
- friend struct DefaultSingletonTraits<Factory>;
-
- Factory();
- virtual ~Factory();
-
- // BrowserContextKeyedServiceFactory methods:
- virtual BrowserContextKeyedService* BuildServiceInstanceFor(
- content::BrowserContext* profile) const OVERRIDE;
- virtual void RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) OVERRIDE;
- virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
- virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;
-
- DISALLOW_COPY_AND_ASSIGN(Factory);
- };
-
- // This wrapper handles the binding between ChromeSpeechRecognitionPreferences
- // instances (which can have a longer lifetime, since they are refcounted) and
- // BrowserContextKeyedService (which lifetime depends on the Profile service).
- // Upon profile shutdown, the ChromeSpeechRecognitionPreferences instance is
- // detached from profile, meaning that after that point its clients can still
- // use it, but preferences will no longer be kept in sync with the profile.
- class Service : public BrowserContextKeyedService {
- public:
- explicit Service(Profile* profile);
- virtual ~Service();
-
- // BrowserContextKeyedService implementation.
- virtual void Shutdown() OVERRIDE;
-
- scoped_refptr<ChromeSpeechRecognitionPreferences> GetPreferences() const;
-
- private:
- scoped_refptr<ChromeSpeechRecognitionPreferences> preferences_;
-
- DISALLOW_COPY_AND_ASSIGN(Service);
- };
-
- explicit ChromeSpeechRecognitionPreferences(Profile* profile);
- virtual ~ChromeSpeechRecognitionPreferences();
-
- void DetachFromProfile();
- void ReloadFilterProfanities();
- void ReloadNotificationsShown();
-
- Profile* profile_; // NULL when detached.
- scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
- bool filter_profanities_;
- scoped_ptr<base::ListValue> notifications_shown_;
-
- // Lock used to ensure exclusive access to preference variables that are
- // accessed by both threads (note: mutable is required to keep getters const).
- mutable base::Lock preferences_lock_;
-
- DISALLOW_COPY_AND_ASSIGN(ChromeSpeechRecognitionPreferences);
-};
-
-#endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_RECOGNITION_PREFERENCES_H_
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index a82feff..9ed8090 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -44,7 +44,6 @@
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/tab_contents/retargeting_details.h"
@@ -1450,8 +1449,8 @@ bool RenderViewContextMenu::IsCommandIdChecked(int id) const {
#if defined(ENABLE_INPUT_SPEECH)
// Check box for menu item 'Block offensive words'.
if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES) {
- return ChromeSpeechRecognitionPreferences::GetForProfile(profile_)->
- FilterProfanities();
+ return profile_->GetPrefs()->GetBoolean(
+ prefs::kSpeechRecognitionFilterProfanities);
}
#endif
@@ -1889,8 +1888,10 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
#if defined(ENABLE_INPUT_SPEECH)
case IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES: {
- ChromeSpeechRecognitionPreferences::GetForProfile(profile_)->
- ToggleFilterProfanities();
+ profile_->GetPrefs()->SetBoolean(
+ prefs::kSpeechRecognitionFilterProfanities,
+ !profile_->GetPrefs()->GetBoolean(
+ prefs::kSpeechRecognitionFilterProfanities));
break;
}
#endif
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index adeed80..cf0f80e 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1875,8 +1875,6 @@
'browser/speech/chrome_speech_recognition_manager_delegate.h',
'browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.cc',
'browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h',
- 'browser/speech/chrome_speech_recognition_preferences.cc',
- 'browser/speech/chrome_speech_recognition_preferences.h',
'browser/speech/extension_api/tts_extension_api_constants.cc',
'browser/speech/extension_api/tts_extension_api_constants.h',
'browser/speech/speech_recognition_bubble.cc',
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 145804e..d521860 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -47,7 +47,6 @@
#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
#include "chrome/browser/profiles/storage_partition_descriptor.h"
#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
-#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_constants.h"
@@ -691,15 +690,6 @@ TestingProfile::GetGeolocationPermissionContext() {
return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
}
-content::SpeechRecognitionPreferences*
- TestingProfile::GetSpeechRecognitionPreferences() {
-#if defined(ENABLE_INPUT_SPEECH)
- return ChromeSpeechRecognitionPreferences::GetForProfile(this).get();
-#else
- return NULL;
-#endif
-}
-
std::wstring TestingProfile::GetName() {
return std::wstring();
}
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index 9088fbe..c8c7faa 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -190,8 +190,6 @@ class TestingProfile : public Profile {
virtual content::ResourceContext* GetResourceContext() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
- virtual content::SpeechRecognitionPreferences*
- GetSpeechRecognitionPreferences() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
virtual TestingProfile* AsTestingProfile() OVERRIDE;
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc
index 7817d3e..fba20f8 100644
--- a/content/browser/download/download_manager_impl_unittest.cc
+++ b/content/browser/download/download_manager_impl_unittest.cc
@@ -404,8 +404,6 @@ class MockBrowserContext : public BrowserContext {
MOCK_METHOD0(GetDownloadManagerDelegate, DownloadManagerDelegate*());
MOCK_METHOD0(GetGeolocationPermissionContext,
GeolocationPermissionContext* ());
- MOCK_METHOD0(GetSpeechRecognitionPreferences,
- SpeechRecognitionPreferences* ());
MOCK_METHOD0(GetSpecialStoragePolicy, quota::SpecialStoragePolicy*());
};
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 7bd9337..3162e8e 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -651,12 +651,10 @@ void RenderProcessHostImpl::CreateMessageFilters() {
#endif
#if defined(ENABLE_INPUT_SPEECH)
channel_->AddFilter(new InputTagSpeechDispatcherHost(
- IsGuest(), GetID(), storage_partition_impl_->GetURLRequestContext(),
- browser_context->GetSpeechRecognitionPreferences()));
+ IsGuest(), GetID(), storage_partition_impl_->GetURLRequestContext()));
#endif
channel_->AddFilter(new SpeechRecognitionDispatcherHost(
- GetID(), storage_partition_impl_->GetURLRequestContext(),
- browser_context->GetSpeechRecognitionPreferences()));
+ GetID(), storage_partition_impl_->GetURLRequestContext()));
channel_->AddFilter(new FileAPIMessageFilter(
GetID(),
storage_partition_impl_->GetURLRequestContext(),
diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.cc b/content/browser/speech/input_tag_speech_dispatcher_host.cc
index 8c4acdb..4a3af54 100644
--- a/content/browser/speech/input_tag_speech_dispatcher_host.cc
+++ b/content/browser/speech/input_tag_speech_dispatcher_host.cc
@@ -8,10 +8,10 @@
#include "base/lazy_instance.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/browser/speech/speech_recognition_manager_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/speech_recognition_messages.h"
-#include "content/public/browser/speech_recognition_manager.h"
-#include "content/public/browser/speech_recognition_preferences.h"
+#include "content/public/browser/speech_recognition_manager_delegate.h"
#include "content/public/browser/speech_recognition_session_config.h"
#include "content/public/browser/speech_recognition_session_context.h"
@@ -24,23 +24,17 @@ namespace content {
InputTagSpeechDispatcherHost::InputTagSpeechDispatcherHost(
bool guest,
int render_process_id,
- net::URLRequestContextGetter* url_request_context_getter,
- SpeechRecognitionPreferences* recognition_preferences)
+ net::URLRequestContextGetter* url_request_context_getter)
: guest_(guest),
render_process_id_(render_process_id),
- url_request_context_getter_(url_request_context_getter),
- recognition_preferences_(recognition_preferences) {
+ url_request_context_getter_(url_request_context_getter) {
// 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.
+ // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or
+ // add an Init() method.
}
InputTagSpeechDispatcherHost::~InputTagSpeechDispatcherHost() {
- if (SpeechRecognitionManager* sr_manager = manager())
- sr_manager->AbortAllSessionsForListener(this);
-}
-
-SpeechRecognitionManager* InputTagSpeechDispatcherHost::manager() {
- return SpeechRecognitionManager::GetInstance();
+ SpeechRecognitionManager::GetInstance()->AbortAllSessionsForListener(this);
}
bool InputTagSpeechDispatcherHost::OnMessageReceived(
@@ -59,20 +53,15 @@ bool InputTagSpeechDispatcherHost::OnMessageReceived(
return handled;
}
-void InputTagSpeechDispatcherHost::OnStartRecognition(
- const InputTagSpeechHostMsg_StartRecognition_Params& params) {
- if (guest_ && !BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(
- &InputTagSpeechDispatcherHost::OnStartRecognition,
- this,
- params));
- return;
- }
-
- DCHECK(!guest_ || BrowserThread::CurrentlyOn(BrowserThread::UI));
+void InputTagSpeechDispatcherHost::OverrideThreadForMessage(
+ const IPC::Message& message,
+ BrowserThread::ID* thread) {
+ if (message.type() == InputTagSpeechHostMsg_StartRecognition::ID)
+ *thread = BrowserThread::UI;
+}
+void InputTagSpeechDispatcherHost::OnStartRecognition(
+ const InputTagSpeechHostMsg_StartRecognition_Params& params) {
InputTagSpeechHostMsg_StartRecognition_Params input_params(params);
int render_process_id = render_process_id_;
// The chrome layer is mostly oblivious to BrowserPlugin guests and so it
@@ -93,25 +82,28 @@ void InputTagSpeechDispatcherHost::OnStartRecognition(
input_params.render_view_id =
guest->embedder_web_contents()->GetRoutingID();
}
-
- if (guest_) {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(
- &InputTagSpeechDispatcherHost::StartRecognitionOnIO,
- this,
- render_process_id,
- guest_render_view_id,
- input_params));
- } else {
- StartRecognitionOnIO(render_process_id, guest_render_view_id, params);
- }
+ bool filter_profanities =
+ SpeechRecognitionManagerImpl::GetInstance() &&
+ SpeechRecognitionManagerImpl::GetInstance()->delegate() &&
+ SpeechRecognitionManagerImpl::GetInstance()->delegate()->
+ FilterProfanities(render_process_id_);
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &InputTagSpeechDispatcherHost::StartRecognitionOnIO,
+ this,
+ render_process_id,
+ guest_render_view_id,
+ input_params,
+ filter_profanities));
}
void InputTagSpeechDispatcherHost::StartRecognitionOnIO(
int render_process_id,
int guest_render_view_id,
- const InputTagSpeechHostMsg_StartRecognition_Params& params) {
+ const InputTagSpeechHostMsg_StartRecognition_Params& params,
+ bool filter_profanities) {
SpeechRecognitionSessionContext context;
context.render_process_id = render_process_id;
context.render_view_id = params.render_view_id;
@@ -128,40 +120,37 @@ void InputTagSpeechDispatcherHost::StartRecognitionOnIO(
config.origin_url = params.origin_url;
config.initial_context = context;
config.url_request_context_getter = url_request_context_getter_.get();
- if (recognition_preferences_.get()) {
- config.filter_profanities = recognition_preferences_->FilterProfanities();
- } else {
- config.filter_profanities = false;
- }
+ config.filter_profanities = filter_profanities;
config.event_listener = this;
- int session_id = manager()->CreateSession(config);
+ int session_id = SpeechRecognitionManager::GetInstance()->CreateSession(
+ config);
DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid);
- manager()->StartSession(session_id);
+ SpeechRecognitionManager::GetInstance()->StartSession(session_id);
}
void InputTagSpeechDispatcherHost::OnCancelRecognition(int render_view_id,
int request_id) {
- int session_id = manager()->GetSession(render_process_id_,
- render_view_id,
- request_id);
+ int session_id = SpeechRecognitionManager::GetInstance()->GetSession(
+ render_process_id_, render_view_id, request_id);
// The renderer might provide an invalid |request_id| if the session was not
// started as expected, e.g., due to unsatisfied security requirements.
if (session_id != SpeechRecognitionManager::kSessionIDInvalid)
- manager()->AbortSession(session_id);
+ SpeechRecognitionManager::GetInstance()->AbortSession(session_id);
}
void InputTagSpeechDispatcherHost::OnStopRecording(int render_view_id,
int request_id) {
- int session_id = manager()->GetSession(render_process_id_,
- render_view_id,
- request_id);
+ int session_id = SpeechRecognitionManager::GetInstance()->GetSession(
+ render_process_id_, render_view_id, request_id);
// The renderer might provide an invalid |request_id| if the session was not
// started as expected, e.g., due to unsatisfied security requirements.
- if (session_id != SpeechRecognitionManager::kSessionIDInvalid)
- manager()->StopAudioCaptureForSession(session_id);
+ if (session_id != SpeechRecognitionManager::kSessionIDInvalid) {
+ SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession(
+ session_id);
+ }
}
// -------- SpeechRecognitionEventListener interface implementation -----------
@@ -171,7 +160,7 @@ void InputTagSpeechDispatcherHost::OnRecognitionResults(
DVLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionResults enter";
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
int render_view_id = context.guest_render_view_id ?
context.guest_render_view_id : context.render_view_id;
@@ -186,7 +175,7 @@ void InputTagSpeechDispatcherHost::OnAudioEnd(int session_id) {
DVLOG(1) << "InputTagSpeechDispatcherHost::OnAudioEnd enter";
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
int render_view_id = context.guest_render_view_id ?
context.guest_render_view_id : context.render_view_id;
Send(new InputTagSpeechMsg_RecordingComplete(render_view_id,
@@ -197,7 +186,7 @@ void InputTagSpeechDispatcherHost::OnAudioEnd(int session_id) {
void InputTagSpeechDispatcherHost::OnRecognitionEnd(int session_id) {
DVLOG(1) << "InputTagSpeechDispatcherHost::OnRecognitionEnd enter";
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
int render_view_id = context.guest_render_view_id ?
context.guest_render_view_id : context.render_view_id;
Send(new InputTagSpeechMsg_RecognitionComplete(render_view_id,
diff --git a/content/browser/speech/input_tag_speech_dispatcher_host.h b/content/browser/speech/input_tag_speech_dispatcher_host.h
index 5593ac6..cb0bf3b 100644
--- a/content/browser/speech/input_tag_speech_dispatcher_host.h
+++ b/content/browser/speech/input_tag_speech_dispatcher_host.h
@@ -18,7 +18,6 @@ struct InputTagSpeechHostMsg_StartRecognition_Params;
namespace content {
class SpeechRecognitionManager;
-class SpeechRecognitionPreferences;
// InputTagSpeechDispatcherHost is a delegate for Speech API messages used by
// RenderMessageFilter. Basically it acts as a proxy, relaying the events coming
@@ -31,8 +30,7 @@ class CONTENT_EXPORT InputTagSpeechDispatcherHost
InputTagSpeechDispatcherHost(
bool guest,
int render_process_id,
- net::URLRequestContextGetter* url_request_context_getter,
- SpeechRecognitionPreferences* recognition_preferences);
+ net::URLRequestContextGetter* url_request_context_getter);
// SpeechRecognitionEventListener methods.
virtual void OnRecognitionStart(int session_id) OVERRIDE;
@@ -55,6 +53,9 @@ class CONTENT_EXPORT InputTagSpeechDispatcherHost
// BrowserMessageFilter implementation.
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) OVERRIDE;
+ virtual void OverrideThreadForMessage(
+ const IPC::Message& message,
+ BrowserThread::ID* thread) OVERRIDE;
private:
virtual ~InputTagSpeechDispatcherHost();
@@ -67,15 +68,12 @@ class CONTENT_EXPORT InputTagSpeechDispatcherHost
void StartRecognitionOnIO(
int render_process_id,
int guest_render_view_id,
- const InputTagSpeechHostMsg_StartRecognition_Params& params);
- // Returns the speech recognition manager to forward events to, creating one
- // if needed.
- SpeechRecognitionManager* manager();
+ const InputTagSpeechHostMsg_StartRecognition_Params& params,
+ bool filter_profanities);
bool guest_;
int render_process_id_;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
- scoped_refptr<SpeechRecognitionPreferences> recognition_preferences_;
DISALLOW_COPY_AND_ASSIGN(InputTagSpeechDispatcherHost);
};
diff --git a/content/browser/speech/speech_recognition_browsertest.cc b/content/browser/speech/speech_recognition_browsertest.cc
index 8c7eaae..9c9c823 100644
--- a/content/browser/speech/speech_recognition_browsertest.cc
+++ b/content/browser/speech/speech_recognition_browsertest.cc
@@ -54,7 +54,7 @@ class SpeechRecognitionBrowserTest : public ContentBrowserTest {
web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
mouse_event.type = WebKit::WebInputEvent::MouseUp;
web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
- fake_speech_recognition_manager_.recognition_started_event().Wait();
+ fake_speech_recognition_manager_.WaitForRecognitionStarted();
// We should wait for a navigation event, raised by the test page JS code
// upon the onwebkitspeechchange event, in all cases except when the
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.cc b/content/browser/speech/speech_recognition_dispatcher_host.cc
index 7f20ca4..e506675 100644
--- a/content/browser/speech/speech_recognition_dispatcher_host.cc
+++ b/content/browser/speech/speech_recognition_dispatcher_host.cc
@@ -7,42 +7,27 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
+#include "content/browser/speech/speech_recognition_manager_impl.h"
#include "content/common/speech_recognition_messages.h"
-#include "content/public/browser/speech_recognition_manager.h"
-#include "content/public/browser/speech_recognition_preferences.h"
+#include "content/public/browser/speech_recognition_manager_delegate.h"
#include "content/public/browser/speech_recognition_session_config.h"
#include "content/public/browser/speech_recognition_session_context.h"
#include "content/public/common/content_switches.h"
namespace content {
-SpeechRecognitionManager* SpeechRecognitionDispatcherHost::manager_for_tests_;
-
-void SpeechRecognitionDispatcherHost::SetManagerForTests(
- SpeechRecognitionManager* manager) {
- manager_for_tests_ = manager;
-}
SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost(
int render_process_id,
- net::URLRequestContextGetter* context_getter,
- SpeechRecognitionPreferences* recognition_preferences)
+ net::URLRequestContextGetter* context_getter)
: render_process_id_(render_process_id),
- context_getter_(context_getter),
- recognition_preferences_(recognition_preferences) {
+ context_getter_(context_getter) {
// 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.
+ // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or
+ // add an Init() method.
}
SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() {
- if (SpeechRecognitionManager* sr_manager = manager())
- sr_manager->AbortAllSessionsForListener(this);
-}
-
-SpeechRecognitionManager* SpeechRecognitionDispatcherHost::manager() {
- if (manager_for_tests_)
- return manager_for_tests_;
-
- return SpeechRecognitionManager::GetInstance();
+ SpeechRecognitionManager::GetInstance()->AbortAllSessionsForListener(this);
}
bool SpeechRecognitionDispatcherHost::OnMessageReceived(
@@ -61,9 +46,31 @@ bool SpeechRecognitionDispatcherHost::OnMessageReceived(
return handled;
}
+void SpeechRecognitionDispatcherHost::OverrideThreadForMessage(
+ const IPC::Message& message,
+ BrowserThread::ID* thread) {
+ if (message.type() == SpeechRecognitionHostMsg_StartRequest::ID)
+ *thread = BrowserThread::UI;
+}
+
void SpeechRecognitionDispatcherHost::OnStartRequest(
const SpeechRecognitionHostMsg_StartRequest_Params& params) {
-
+ bool filter_profanities =
+ SpeechRecognitionManagerImpl::GetInstance() &&
+ SpeechRecognitionManagerImpl::GetInstance()->delegate() &&
+ SpeechRecognitionManagerImpl::GetInstance()->delegate()->
+ FilterProfanities(render_process_id_);
+
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&SpeechRecognitionDispatcherHost::OnStartRequestOnIO,
+ this, params, filter_profanities));
+}
+
+void SpeechRecognitionDispatcherHost::OnStartRequestOnIO(
+ const SpeechRecognitionHostMsg_StartRequest_Params& params,
+ bool filter_profanities) {
SpeechRecognitionSessionContext context;
context.context_name = params.origin_url;
context.render_process_id = render_process_id_;
@@ -79,84 +86,81 @@ void SpeechRecognitionDispatcherHost::OnStartRequest(
config.origin_url = params.origin_url;
config.initial_context = context;
config.url_request_context_getter = context_getter_.get();
- if (recognition_preferences_.get()) {
- config.filter_profanities = recognition_preferences_->FilterProfanities();
- } else {
- config.filter_profanities = false;
- }
+ config.filter_profanities = filter_profanities;
config.continuous = params.continuous;
config.interim_results = params.interim_results;
config.event_listener = this;
- int session_id = manager()->CreateSession(config);
+ int session_id = SpeechRecognitionManager::GetInstance()->CreateSession(
+ config);
DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid);
- manager()->StartSession(session_id);
+ SpeechRecognitionManager::GetInstance()->StartSession(session_id);
}
void SpeechRecognitionDispatcherHost::OnAbortRequest(int render_view_id,
int request_id) {
- int session_id = manager()->GetSession(render_process_id_,
- render_view_id,
- request_id);
+ int session_id = SpeechRecognitionManager::GetInstance()->GetSession(
+ render_process_id_, render_view_id, request_id);
// The renderer might provide an invalid |request_id| if the session was not
// started as expected, e.g., due to unsatisfied security requirements.
if (session_id != SpeechRecognitionManager::kSessionIDInvalid)
- manager()->AbortSession(session_id);
+ SpeechRecognitionManager::GetInstance()->AbortSession(session_id);
}
void SpeechRecognitionDispatcherHost::OnStopCaptureRequest(
int render_view_id, int request_id) {
- int session_id = manager()->GetSession(render_process_id_,
- render_view_id,
- request_id);
+ int session_id = SpeechRecognitionManager::GetInstance()->GetSession(
+ render_process_id_, render_view_id, request_id);
// The renderer might provide an invalid |request_id| if the session was not
// started as expected, e.g., due to unsatisfied security requirements.
- if (session_id != SpeechRecognitionManager::kSessionIDInvalid)
- manager()->StopAudioCaptureForSession(session_id);
+ if (session_id != SpeechRecognitionManager::kSessionIDInvalid) {
+ SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession(
+ session_id);
+ }
}
// -------- SpeechRecognitionEventListener interface implementation -----------
void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_Started(context.render_view_id,
context.request_id));
}
void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_AudioStarted(context.render_view_id,
context.request_id));
}
void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_SoundStarted(context.render_view_id,
context.request_id));
}
void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_SoundEnded(context.render_view_id,
context.request_id));
}
void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_AudioEnded(context.render_view_id,
context.request_id));
}
void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_Ended(context.render_view_id,
context.request_id));
}
@@ -165,7 +169,7 @@ void SpeechRecognitionDispatcherHost::OnRecognitionResults(
int session_id,
const SpeechRecognitionResults& results) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_ResultRetrieved(context.render_view_id,
context.request_id,
results));
@@ -175,7 +179,7 @@ void SpeechRecognitionDispatcherHost::OnRecognitionError(
int session_id,
const SpeechRecognitionError& error) {
const SpeechRecognitionSessionContext& context =
- manager()->GetSessionContext(session_id);
+ SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
Send(new SpeechRecognitionMsg_ErrorOccurred(context.render_view_id,
context.request_id,
error));
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.h b/content/browser/speech/speech_recognition_dispatcher_host.h
index dea822d..1bc12a1 100644
--- a/content/browser/speech/speech_recognition_dispatcher_host.h
+++ b/content/browser/speech/speech_recognition_dispatcher_host.h
@@ -16,7 +16,6 @@ struct SpeechRecognitionHostMsg_StartRequest_Params;
namespace content {
class SpeechRecognitionManager;
-class SpeechRecognitionPreferences;
struct SpeechRecognitionResult;
// SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by
@@ -29,8 +28,7 @@ class CONTENT_EXPORT SpeechRecognitionDispatcherHost
public:
SpeechRecognitionDispatcherHost(
int render_process_id,
- net::URLRequestContextGetter* context_getter,
- SpeechRecognitionPreferences* recognition_preferences);
+ net::URLRequestContextGetter* context_getter);
// SpeechRecognitionEventListener methods.
virtual void OnRecognitionStart(int session_id) OVERRIDE;
@@ -53,26 +51,23 @@ class CONTENT_EXPORT SpeechRecognitionDispatcherHost
// BrowserMessageFilter implementation.
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) OVERRIDE;
-
- // Singleton manager setter useful for tests.
- static void SetManagerForTests(SpeechRecognitionManager* manager);
+ virtual void OverrideThreadForMessage(
+ const IPC::Message& message,
+ BrowserThread::ID* thread) OVERRIDE;
private:
virtual ~SpeechRecognitionDispatcherHost();
void OnStartRequest(
const SpeechRecognitionHostMsg_StartRequest_Params& params);
+ void OnStartRequestOnIO(
+ const SpeechRecognitionHostMsg_StartRequest_Params& params,
+ bool filter_profanities);
void OnAbortRequest(int render_view_id, int request_id);
void OnStopCaptureRequest(int render_view_id, int request_id);
- // Returns the speech recognition manager to forward requests to.
- SpeechRecognitionManager* manager();
-
int render_process_id_;
scoped_refptr<net::URLRequestContextGetter> context_getter_;
- scoped_refptr<SpeechRecognitionPreferences> recognition_preferences_;
-
- static SpeechRecognitionManager* manager_for_tests_;
DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost);
};
diff --git a/content/browser/speech/speech_recognition_manager_impl.h b/content/browser/speech/speech_recognition_manager_impl.h
index bf86ac1..0432570 100644
--- a/content/browser/speech/speech_recognition_manager_impl.h
+++ b/content/browser/speech/speech_recognition_manager_impl.h
@@ -93,6 +93,8 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl :
virtual void OnAudioLevelsChange(int session_id, float volume,
float noise_volume) OVERRIDE;
+ SpeechRecognitionManagerDelegate* delegate() const { return delegate_.get(); }
+
protected:
// BrowserMainLoop is the only one allowed to istantiate and free us.
friend class BrowserMainLoop;
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 0d088fa..a6dfa87 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -163,7 +163,6 @@
'public/browser/speech_recognition_event_listener.h',
'public/browser/speech_recognition_manager.h',
'public/browser/speech_recognition_manager_delegate.h',
- 'public/browser/speech_recognition_preferences.h',
'public/browser/speech_recognition_session_config.cc',
'public/browser/speech_recognition_session_config.h',
'public/browser/speech_recognition_session_context.cc',
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h
index 67ede4a..1fb1052 100644
--- a/content/public/browser/browser_context.h
+++ b/content/public/browser/browser_context.h
@@ -37,7 +37,6 @@ class GeolocationPermissionContext;
class IndexedDBContext;
class ResourceContext;
class SiteInstance;
-class SpeechRecognitionPreferences;
class StoragePartition;
// This class holds the context needed for a browsing session.
@@ -141,11 +140,6 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
// return NULL, in which case geolocation requests will always be allowed.
virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0;
- // Returns the speech input preferences. SpeechRecognitionPreferences is a
- // ref counted class, so callers should take a reference if needed. It's valid
- // to return NULL.
- virtual SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() = 0;
-
// Returns a special storage policy implementation, or NULL.
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
};
diff --git a/content/public/browser/speech_recognition_manager_delegate.h b/content/public/browser/speech_recognition_manager_delegate.h
index 7b729d1..bbfeaed 100644
--- a/content/public/browser/speech_recognition_manager_delegate.h
+++ b/content/public/browser/speech_recognition_manager_delegate.h
@@ -22,17 +22,24 @@ class SpeechRecognitionManagerDelegate {
virtual ~SpeechRecognitionManagerDelegate() {}
// Get the optional diagnostic hardware information if available.
+ // This is called on the IO thread.
virtual void GetDiagnosticInformation(bool* can_report_metrics,
std::string* hardware_info) = 0;
// Checks (asynchronously) if current setup allows speech recognition.
+ // This is called on the IO thread.
virtual void CheckRecognitionIsAllowed(
int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) = 0;
// Checks whether the delegate is interested (returning a non NULL ptr) or not
// (returning NULL) in receiving a copy of all sessions events.
+ // This is called on the IO thread.
virtual SpeechRecognitionEventListener* GetEventListener() = 0;
+
+ // Checks whether the speech recognition for the given renderer should filter
+ // profanities or not.
+ virtual bool FilterProfanities(int render_process_id) = 0;
};
} // namespace content
diff --git a/content/public/browser/speech_recognition_preferences.h b/content/public/browser/speech_recognition_preferences.h
deleted file mode 100644
index d003b64..0000000
--- a/content/public/browser/speech_recognition_preferences.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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_RECOGNITION_PREFERENCES_H_
-#define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_PREFERENCES_H_
-
-#include "base/memory/ref_counted.h"
-
-namespace content {
-
-class SpeechRecognitionPreferences
- : public base::RefCountedThreadSafe<SpeechRecognitionPreferences> {
- public:
- virtual bool FilterProfanities() const = 0;
-
- protected:
- virtual ~SpeechRecognitionPreferences() {}
-
- private:
- friend class base::RefCountedThreadSafe<SpeechRecognitionPreferences>;
-};
-
-} // namespace content
-
-#endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_PREFERENCES_H_
diff --git a/content/public/test/fake_speech_recognition_manager.cc b/content/public/test/fake_speech_recognition_manager.cc
index 464789e..bc08b94 100644
--- a/content/public/test/fake_speech_recognition_manager.cc
+++ b/content/public/test/fake_speech_recognition_manager.cc
@@ -9,10 +9,15 @@
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/speech_recognition_event_listener.h"
#include "content/public/common/speech_recognition_result.h"
+#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kTestResult[] = "Pictures of the moon";
+
+void RunCallback(const base::Closure recognition_started_closure) {
+ recognition_started_closure.Run();
+}
} // namespace
namespace content {
@@ -22,13 +27,20 @@ FakeSpeechRecognitionManager::FakeSpeechRecognitionManager()
listener_(NULL),
fake_result_(kTestResult),
did_cancel_all_(false),
- should_send_fake_response_(true),
- recognition_started_event_(false, false) {
+ should_send_fake_response_(true) {
}
FakeSpeechRecognitionManager::~FakeSpeechRecognitionManager() {
}
+void FakeSpeechRecognitionManager::WaitForRecognitionStarted() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
+ recognition_started_closure_ = runner->QuitClosure();
+ runner->Run();
+ recognition_started_closure_.Reset();
+}
+
void FakeSpeechRecognitionManager::SetFakeResult(const std::string& value) {
fake_result_ = value;
}
@@ -65,7 +77,12 @@ void FakeSpeechRecognitionManager::StartSession(int session_id) {
// pointer below as required by the real code.
base::Unretained(this)));
}
- recognition_started_event_.Signal();
+ if (!recognition_started_closure_.is_null()) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&RunCallback, recognition_started_closure_));
+ }
}
void FakeSpeechRecognitionManager::AbortSession(int session_id) {
diff --git a/content/public/test/fake_speech_recognition_manager.h b/content/public/test/fake_speech_recognition_manager.h
index c805051..0973f6c 100644
--- a/content/public/test/fake_speech_recognition_manager.h
+++ b/content/public/test/fake_speech_recognition_manager.h
@@ -5,7 +5,7 @@
#ifndef CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNTION_MANAGER_H_
#define CONTENT_PUBLIC_TEST_FAKE_SPEECH_RECOGNTION_MANAGER_H_
-#include "base/synchronization/waitable_event.h"
+#include "base/callback_forward.h"
#include "content/public/browser/speech_recognition_manager.h"
#include "content/public/browser/speech_recognition_session_config.h"
#include "content/public/browser/speech_recognition_session_context.h"
@@ -37,9 +37,7 @@ class FakeSpeechRecognitionManager : public SpeechRecognitionManager {
return should_send_fake_response_;
}
- base::WaitableEvent& recognition_started_event() {
- return recognition_started_event_;
- }
+ void WaitForRecognitionStarted();
void SetFakeResult(const std::string& result);
@@ -75,7 +73,7 @@ class FakeSpeechRecognitionManager : public SpeechRecognitionManager {
std::string grammar_;
bool did_cancel_all_;
bool should_send_fake_response_;
- base::WaitableEvent recognition_started_event_;
+ base::Closure recognition_started_closure_;
DISALLOW_COPY_AND_ASSIGN(FakeSpeechRecognitionManager);
};
diff --git a/content/public/test/test_browser_context.cc b/content/public/test/test_browser_context.cc
index 0f6304d..05f40e8 100644
--- a/content/public/test/test_browser_context.cc
+++ b/content/public/test/test_browser_context.cc
@@ -110,11 +110,6 @@ GeolocationPermissionContext*
return NULL;
}
-SpeechRecognitionPreferences*
- TestBrowserContext::GetSpeechRecognitionPreferences() {
- return NULL;
-}
-
quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() {
return special_storage_policy_.get();
}
diff --git a/content/public/test/test_browser_context.h b/content/public/test/test_browser_context.h
index fbf4275..2106938 100644
--- a/content/public/test/test_browser_context.h
+++ b/content/public/test/test_browser_context.h
@@ -43,8 +43,6 @@ class TestBrowserContext : public BrowserContext {
virtual ResourceContext* GetResourceContext() OVERRIDE;
virtual GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
- virtual SpeechRecognitionPreferences*
- GetSpeechRecognitionPreferences() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
private:
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index 7cdaba1..721d7c8 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -187,11 +187,6 @@ GeolocationPermissionContext*
return NULL;
}
-SpeechRecognitionPreferences*
- ShellBrowserContext::GetSpeechRecognitionPreferences() {
- return NULL;
-}
-
quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
return NULL;
}
diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h
index 7248707..800a960 100644
--- a/content/shell/shell_browser_context.h
+++ b/content/shell/shell_browser_context.h
@@ -46,8 +46,6 @@ class ShellBrowserContext : public BrowserContext {
virtual ResourceContext* GetResourceContext() OVERRIDE;
virtual GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
- virtual SpeechRecognitionPreferences*
- GetSpeechRecognitionPreferences() OVERRIDE;
virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
net::URLRequestContextGetter* CreateRequestContext(