diff options
author | allanwoj@chromium.org <allanwoj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 15:13:01 +0000 |
---|---|---|
committer | allanwoj@chromium.org <allanwoj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 15:13:01 +0000 |
commit | 8238dd6190819daade7ee98f669e23a5a56ee4fa (patch) | |
tree | 09debefb10323f762ccdf5b94c5722ea77b60d5d | |
parent | 8cc6e41efa5af14f403cbb14b15e3af8ea686c93 (diff) | |
download | chromium_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
28 files changed, 321 insertions, 114 deletions
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index 8812a27..177df04 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -421,6 +421,10 @@ GeolocationPermissionContext* return profile_->GetGeolocationPermissionContext(); } +SpeechInputPreferences* OffTheRecordProfileImpl::GetSpeechInputPreferences() { + return profile_->GetSpeechInputPreferences(); +} + UserStyleSheetWatcher* OffTheRecordProfileImpl::GetUserStyleSheetWatcher() { return profile_->GetUserStyleSheetWatcher(); } diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index ab54947..9f7dea4 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -83,6 +83,7 @@ class OffTheRecordProfileImpl : public Profile, virtual HostZoomMap* GetHostZoomMap() OVERRIDE; virtual GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; + virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; virtual FindBarState* GetFindBarState() OVERRIDE; virtual bool HasProfileSyncService() const OVERRIDE; diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 45f1447..337b8ab 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -84,6 +84,7 @@ class PromoResourceService; class ProtocolHandlerRegistry; class SQLitePersistentCookieStore; class SSLConfigServiceManager; +class SpeechInputPreferences; class SpellCheckHost; class TemplateURLFetcher; class TokenService; @@ -203,6 +204,7 @@ class Profile : public content::BrowserContext { virtual const content::ResourceContext& GetResourceContext() = 0; virtual HostZoomMap* GetHostZoomMap() = 0; virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0; + virtual SpeechInputPreferences* GetSpeechInputPreferences() = 0; virtual quota::QuotaManager* GetQuotaManager() = 0; virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0; virtual WebKitContext* GetWebKitContext() = 0; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 481b2ef..6c9deb5 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -64,6 +64,7 @@ #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/speech/chrome_speech_input_manager.h" +#include "chrome/browser/speech/chrome_speech_input_preferences.h" #include "chrome/browser/spellchecker/spellcheck_profile.h" #include "chrome/browser/sync/profile_sync_factory_impl.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -447,9 +448,6 @@ void ProfileImpl::DoFinalInit() { GetSpellCheckProfile()->StartRecordingMetrics( GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); - speech_input::ChromeSpeechInputManager::GetInstance()->set_censor_results( - prefs->GetBoolean(prefs::kSpeechInputCensorResults)); - FilePath cookie_path = GetPath(); cookie_path = cookie_path.Append(chrome::kCookieFilename); FilePath origin_bound_cert_path = GetPath(); @@ -1089,12 +1087,20 @@ HostZoomMap* ProfileImpl::GetHostZoomMap() { } GeolocationPermissionContext* ProfileImpl::GetGeolocationPermissionContext() { - if (!geolocation_permission_context_.get()) + if (!geolocation_permission_context_.get()) { geolocation_permission_context_ = new ChromeGeolocationPermissionContext(this); + } return geolocation_permission_context_.get(); } +SpeechInputPreferences* ProfileImpl::GetSpeechInputPreferences() { + if (!speech_input_preferences_.get()) { + speech_input_preferences_ = new ChromeSpeechInputPreferences(GetPrefs()); + } + return speech_input_preferences_.get(); +} + UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() { if (!user_style_sheet_watcher_.get()) { user_style_sheet_watcher_ = new UserStyleSheetWatcher(GetPath()); @@ -1492,9 +1498,8 @@ void ProfileImpl::Observe(int type, process->Send(new SpellCheckMsg_EnableAutoSpellCorrect(enabled)); } } else if (*pref_name_in == prefs::kSpeechInputCensorResults) { - speech_input::ChromeSpeechInputManager::GetInstance()-> - set_censor_results(prefs->GetBoolean( - prefs::kSpeechInputCensorResults)); + GetSpeechInputPreferences()->set_censor_results(prefs->GetBoolean( + prefs::kSpeechInputCensorResults)); } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 80a476d..c538eac 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -25,6 +25,7 @@ class ExtensionPrefValueMap; class ExtensionSettings; class NetPrefObserver; class PrefService; +class SpeechInputPreferences; class SpellCheckProfile; #if defined(OS_CHROMEOS) @@ -43,101 +44,109 @@ class ProfileImpl : public Profile, static void RegisterUserPrefs(PrefService* prefs); - // Profile implementation. - virtual std::string GetProfileName(); - virtual FilePath GetPath(); - virtual bool IsOffTheRecord(); - virtual Profile* GetOffTheRecordProfile(); - virtual void DestroyOffTheRecordProfile(); - virtual bool HasOffTheRecordProfile(); - virtual Profile* GetOriginalProfile(); - virtual ChromeAppCacheService* GetAppCacheService(); - virtual webkit_database::DatabaseTracker* GetDatabaseTracker(); - virtual history::TopSites* GetTopSites(); - virtual history::TopSites* GetTopSitesWithoutCreating(); - virtual VisitedLinkMaster* GetVisitedLinkMaster(); - virtual UserScriptMaster* GetUserScriptMaster(); - virtual SSLHostState* GetSSLHostState(); - virtual ExtensionService* GetExtensionService(); - virtual ExtensionDevToolsManager* GetExtensionDevToolsManager(); - virtual ExtensionProcessManager* GetExtensionProcessManager(); - virtual ExtensionMessageService* GetExtensionMessageService(); - virtual ExtensionEventRouter* GetExtensionEventRouter(); - virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy(); - virtual FaviconService* GetFaviconService(ServiceAccessType sat); - virtual HistoryService* GetHistoryService(ServiceAccessType sat); - virtual HistoryService* GetHistoryServiceWithoutCreating(); - virtual AutocompleteClassifier* GetAutocompleteClassifier(); - virtual history::ShortcutsBackend* GetShortcutsBackend(); - virtual WebDataService* GetWebDataService(ServiceAccessType sat); - virtual WebDataService* GetWebDataServiceWithoutCreating(); - virtual PasswordStore* GetPasswordStore(ServiceAccessType sat); - virtual PrefService* GetPrefs(); - virtual PrefService* GetOffTheRecordPrefs(); - virtual TemplateURLFetcher* GetTemplateURLFetcher(); - virtual DownloadManager* GetDownloadManager(); - virtual fileapi::FileSystemContext* GetFileSystemContext(); - virtual quota::QuotaManager* GetQuotaManager(); - virtual bool HasCreatedDownloadManager() const; - virtual net::URLRequestContextGetter* GetRequestContext(); + // content::BrowserContext implementation: + virtual FilePath GetPath() OVERRIDE; + virtual SSLHostState* GetSSLHostState() OVERRIDE; + virtual DownloadManager* GetDownloadManager() OVERRIDE; + virtual bool HasCreatedDownloadManager() const OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id); - virtual net::URLRequestContextGetter* GetRequestContextForMedia(); - virtual net::URLRequestContextGetter* GetRequestContextForExtensions(); + int renderer_child_id) OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContextForMedia() OVERRIDE; + virtual const content::ResourceContext& GetResourceContext() OVERRIDE; + virtual HostZoomMap* GetHostZoomMap() OVERRIDE; + virtual GeolocationPermissionContext* + GetGeolocationPermissionContext() OVERRIDE; + virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; + virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; + virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; + virtual WebKitContext* GetWebKitContext() OVERRIDE; + virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; + virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; + virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; + + // Profile implementation: + virtual std::string GetProfileName() OVERRIDE; + virtual bool IsOffTheRecord() OVERRIDE; + virtual Profile* GetOffTheRecordProfile() OVERRIDE; + virtual void DestroyOffTheRecordProfile() OVERRIDE; + virtual bool HasOffTheRecordProfile() OVERRIDE; + virtual Profile* GetOriginalProfile() OVERRIDE; + virtual history::TopSites* GetTopSites() OVERRIDE; + virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; + virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE; + virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE; + virtual ExtensionService* GetExtensionService() OVERRIDE; + virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() OVERRIDE; + virtual ExtensionProcessManager* GetExtensionProcessManager() OVERRIDE; + virtual ExtensionMessageService* GetExtensionMessageService() OVERRIDE; + virtual ExtensionEventRouter* GetExtensionEventRouter() OVERRIDE; + virtual ExtensionSpecialStoragePolicy* + GetExtensionSpecialStoragePolicy() OVERRIDE; + virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE; + virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE; + virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE; + virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE; + virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE; + virtual WebDataService* GetWebDataService(ServiceAccessType sat) OVERRIDE; + virtual WebDataService* GetWebDataServiceWithoutCreating() OVERRIDE; + virtual PasswordStore* GetPasswordStore(ServiceAccessType sat) OVERRIDE; + virtual PrefService* GetPrefs() OVERRIDE; + virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; + virtual TemplateURLFetcher* GetTemplateURLFetcher() OVERRIDE; + virtual net::URLRequestContextGetter* + GetRequestContextForExtensions() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp( - const std::string& app_id); - virtual const content::ResourceContext& GetResourceContext(); - virtual void RegisterExtensionWithRequestContexts(const Extension* extension); + const std::string& app_id) OVERRIDE; + virtual void RegisterExtensionWithRequestContexts( + const Extension* extension) OVERRIDE; virtual void UnregisterExtensionWithRequestContexts( const std::string& extension_id, - const extension_misc::UnloadedExtensionReason reason); - virtual net::SSLConfigService* GetSSLConfigService(); - virtual HostContentSettingsMap* GetHostContentSettingsMap(); - virtual HostZoomMap* GetHostZoomMap(); - virtual GeolocationPermissionContext* GetGeolocationPermissionContext(); - virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher(); - virtual FindBarState* GetFindBarState(); - virtual bool HasProfileSyncService() const; - virtual bool DidLastSessionExitCleanly(); - virtual BookmarkModel* GetBookmarkModel(); - virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry(); - virtual bool IsSameProfile(Profile* profile); - virtual base::Time GetStartTime() const; - virtual SpellCheckHost* GetSpellCheckHost(); - virtual void ReinitializeSpellCheckHost(bool force); - virtual WebKitContext* GetWebKitContext(); - virtual void MarkAsCleanShutdown(); - virtual void InitExtensions(bool extensions_enabled); - virtual void InitPromoResources(); - virtual void InitRegisteredProtocolHandlers(); - virtual FilePath last_selected_directory(); - virtual void set_last_selected_directory(const FilePath& path); - virtual ProfileSyncService* GetProfileSyncService(); + const extension_misc::UnloadedExtensionReason reason) OVERRIDE; + virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; + virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; + virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; + virtual FindBarState* GetFindBarState() OVERRIDE; + virtual bool HasProfileSyncService() const OVERRIDE; + virtual bool DidLastSessionExitCleanly() OVERRIDE; + virtual BookmarkModel* GetBookmarkModel() OVERRIDE; + virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; + virtual bool IsSameProfile(Profile* profile) OVERRIDE; + virtual base::Time GetStartTime() const OVERRIDE; + virtual SpellCheckHost* GetSpellCheckHost() OVERRIDE; + virtual void ReinitializeSpellCheckHost(bool force) OVERRIDE; + virtual void MarkAsCleanShutdown() OVERRIDE; + virtual void InitExtensions(bool extensions_enabled) OVERRIDE; + virtual void InitPromoResources() OVERRIDE; + virtual void InitRegisteredProtocolHandlers() OVERRIDE; + virtual FilePath last_selected_directory() OVERRIDE; + virtual void set_last_selected_directory(const FilePath& path) OVERRIDE; + virtual ProfileSyncService* GetProfileSyncService() OVERRIDE; virtual ProfileSyncService* GetProfileSyncService( - const std::string& cros_user); - virtual TokenService* GetTokenService(); + const std::string& cros_user) OVERRIDE; + virtual TokenService* GetTokenService() OVERRIDE; void InitSyncService(const std::string& cros_user); - virtual ChromeBlobStorageContext* GetBlobStorageContext(); - virtual ExtensionInfoMap* GetExtensionInfoMap(); - virtual PromoCounter* GetInstantPromoCounter(); - virtual ChromeURLDataManager* GetChromeURLDataManager(); - virtual chrome_browser_net::Predictor* GetNetworkPredictor(); - virtual void DeleteTransportSecurityStateSince(base::Time time); + virtual ExtensionInfoMap* GetExtensionInfoMap() OVERRIDE; + virtual PromoCounter* GetInstantPromoCounter() OVERRIDE; + virtual ChromeURLDataManager* GetChromeURLDataManager() OVERRIDE; + virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; + virtual void DeleteTransportSecurityStateSince(base::Time time) OVERRIDE; #if defined(OS_CHROMEOS) - virtual void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia); - virtual void OnLogin(); - virtual void SetupChromeOSEnterpriseExtensionObserver(); - virtual void InitChromeOSPreferences(); + virtual void ChangeAppLocale(const std::string& locale, + AppLocaleChangedVia) OVERRIDE; + virtual void OnLogin() OVERRIDE; + virtual void SetupChromeOSEnterpriseExtensionObserver() OVERRIDE; + virtual void InitChromeOSPreferences() OVERRIDE; #endif // defined(OS_CHROMEOS) - virtual PrefProxyConfigTracker* GetProxyConfigTracker(); - virtual prerender::PrerenderManager* GetPrerenderManager(); + virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE; + virtual prerender::PrerenderManager* GetPrerenderManager() OVERRIDE; // NotificationObserver implementation. virtual void Observe(int type, const NotificationSource& source, - const NotificationDetails& details); + const NotificationDetails& details) OVERRIDE; private: friend class Profile; @@ -224,6 +233,7 @@ class ProfileImpl : public Profile, scoped_refptr<HostZoomMap> host_zoom_map_; scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; + scoped_refptr<SpeechInputPreferences> speech_input_preferences_; scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher_; scoped_ptr<FindBarState> find_bar_state_; scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; diff --git a/chrome/browser/speech/chrome_speech_input_preferences.cc b/chrome/browser/speech/chrome_speech_input_preferences.cc new file mode 100644 index 0000000..e6a2982 --- /dev/null +++ b/chrome/browser/speech/chrome_speech_input_preferences.cc @@ -0,0 +1,35 @@ +// 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 "chrome/browser/speech/chrome_speech_input_preferences.h" + +#include "base/bind.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/common/pref_names.h" +#include "content/browser/browser_thread.h" + +ChromeSpeechInputPreferences::ChromeSpeechInputPreferences( + PrefService* pref_service) + : censor_results_( + pref_service->GetBoolean(prefs::kSpeechInputCensorResults)) { +} + +ChromeSpeechInputPreferences::~ChromeSpeechInputPreferences() { +} + +bool ChromeSpeechInputPreferences::censor_results() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return censor_results_; +} + +void ChromeSpeechInputPreferences::set_censor_results(bool censor_results) { + if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&ChromeSpeechInputPreferences::set_censor_results, + this, censor_results)); + return; + } + censor_results_ = censor_results; +} diff --git a/chrome/browser/speech/chrome_speech_input_preferences.h b/chrome/browser/speech/chrome_speech_input_preferences.h new file mode 100644 index 0000000..feca5a6 --- /dev/null +++ b/chrome/browser/speech/chrome_speech_input_preferences.h @@ -0,0 +1,32 @@ +// 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 CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_PREFERENCES_H_ +#define CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_PREFERENCES_H_ +#pragma once + +#include "base/basictypes.h" +#include "chrome/browser/prefs/pref_service.h" +#include "content/browser/speech/speech_input_preferences.h" + +class PrefService; + +class ChromeSpeechInputPreferences : public SpeechInputPreferences { + public: + explicit ChromeSpeechInputPreferences(PrefService* pref_service); + + // SpeechInputPreferences methods. + virtual bool censor_results() const OVERRIDE; + virtual void set_censor_results(bool censor_results) OVERRIDE; + + private: + virtual ~ChromeSpeechInputPreferences(); + + // Only to be accessed and modified on the IO thread. + bool censor_results_; + + DISALLOW_COPY_AND_ASSIGN(ChromeSpeechInputPreferences); +}; + +#endif // CHROME_BROWSER_SPEECH_CHROME_SPEECH_INPUT_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 65b1de9..299c660 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -57,6 +57,7 @@ #include "content/browser/download/save_package.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_widget_host_view.h" +#include "content/browser/speech/speech_input_preferences.h" #include "content/browser/tab_contents/navigation_details.h" #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" @@ -1829,6 +1830,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { PrefService* prefs = profile_->GetPrefs(); const bool censor = !prefs->GetBoolean(prefs::kSpeechInputCensorResults); prefs->SetBoolean(prefs::kSpeechInputCensorResults, censor); + profile_->GetSpeechInputPreferences()->set_censor_results(censor); break; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index df2041e..4b58b51 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2037,6 +2037,8 @@ 'browser/simple_message_box.h', 'browser/speech/chrome_speech_input_manager.cc', 'browser/speech/chrome_speech_input_manager.h', + 'browser/speech/chrome_speech_input_preferences.cc', + 'browser/speech/chrome_speech_input_preferences.h', 'browser/speech/speech_input_bubble.cc', 'browser/speech/speech_input_bubble.h', 'browser/speech/speech_input_bubble_controller.cc', diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 8c13345..d8aabd1 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -36,6 +36,7 @@ #include "chrome/browser/search_engines/template_url_fetcher.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_input_preferences.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/browser/ui/find_bar/find_bar_state.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" @@ -639,6 +640,12 @@ TestingProfile::GetGeolocationPermissionContext() { return geolocation_permission_context_.get(); } +SpeechInputPreferences* TestingProfile::GetSpeechInputPreferences() { + if (!speech_input_preferences_.get()) + speech_input_preferences_ = new ChromeSpeechInputPreferences(GetPrefs()); + return speech_input_preferences_.get(); +} + HostZoomMap* TestingProfile::GetHostZoomMap() { return NULL; } diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index edafda8..925cc44 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -46,6 +46,7 @@ class HostContentSettingsMap; class PrefService; class ProfileDependencyManager; class ProfileSyncService; +class SpeechInputPreferences; class TemplateURLService; class TestingPrefService; class ThemeService; @@ -220,6 +221,7 @@ class TestingProfile : public Profile { virtual FindBarState* GetFindBarState(); virtual HostContentSettingsMap* GetHostContentSettingsMap(); virtual GeolocationPermissionContext* GetGeolocationPermissionContext(); + virtual SpeechInputPreferences* GetSpeechInputPreferences(); virtual HostZoomMap* GetHostZoomMap(); virtual bool HasProfileSyncService() const; virtual std::wstring GetName(); @@ -365,6 +367,8 @@ class TestingProfile : public Profile { scoped_refptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; + scoped_refptr<SpeechInputPreferences> speech_input_preferences_; + // Find bar state. Created lazily by GetFindBarState(). scoped_ptr<FindBarState> find_bar_state_; 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), diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 86013aa..39ced25 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -461,6 +461,8 @@ 'browser/speech/speech_input_dispatcher_host.h', 'browser/speech/speech_input_manager.cc', 'browser/speech/speech_input_manager.h', + 'browser/speech/speech_input_preferences.cc', + 'browser/speech/speech_input_preferences.h', 'browser/speech/speech_recognition_request.cc', 'browser/speech/speech_recognition_request.h', 'browser/speech/speech_recognizer.cc', diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index 91c51c8..33d88f9 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -18,6 +18,7 @@ #include "content/browser/host_zoom_map.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/ssl/ssl_host_state.h" +#include "content/browser/speech/speech_input_preferences.h" #include "content/shell/shell_browser_main.h" #include "content/shell/shell_resource_context.h" #include "content/shell/shell_url_request_context_getter.h" @@ -56,6 +57,23 @@ class ShellGeolocationPermissionContext : public GeolocationPermissionContext { DISALLOW_COPY_AND_ASSIGN(ShellGeolocationPermissionContext); }; +class ShellSpeechInputPreferences : public SpeechInputPreferences { + public: + ShellSpeechInputPreferences() { + } + + // SpeechInputPreferences implementation. + virtual bool censor_results() const OVERRIDE { + return false; + } + + virtual void set_censor_results(bool censor_results) OVERRIDE { + } + + private: + DISALLOW_COPY_AND_ASSIGN(ShellSpeechInputPreferences); +}; + } // namespace namespace content { @@ -160,6 +178,12 @@ GeolocationPermissionContext* return geolocation_permission_context_; } +SpeechInputPreferences* ShellBrowserContext::GetSpeechInputPreferences() { + if (!speech_input_preferences_.get()) + speech_input_preferences_ = new ShellSpeechInputPreferences(); + return speech_input_preferences_.get(); +} + bool ShellBrowserContext::DidLastSessionExitCleanly() { return true; } diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index b5806c5..7de6528 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -43,6 +43,7 @@ class ShellBrowserContext : public BrowserContext { virtual HostZoomMap* GetHostZoomMap() OVERRIDE; virtual GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; + virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; virtual WebKitContext* GetWebKitContext() OVERRIDE; @@ -63,6 +64,7 @@ class ShellBrowserContext : public BrowserContext { scoped_refptr<net::URLRequestContextGetter> url_request_getter_; scoped_refptr<HostZoomMap> host_zoom_map_; scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; + scoped_refptr<SpeechInputPreferences> speech_input_preferences_; scoped_refptr<WebKitContext> webkit_context_; scoped_refptr<ChromeAppCacheService> appcache_service_; scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc index b17dc62..7ec34d5b 100644 --- a/content/test/test_browser_context.cc +++ b/content/test/test_browser_context.cc @@ -61,6 +61,10 @@ TestBrowserContext::GetGeolocationPermissionContext() { return NULL; } +SpeechInputPreferences* TestBrowserContext::GetSpeechInputPreferences() { + return NULL; +} + bool TestBrowserContext::DidLastSessionExitCleanly() { return true; } diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h index 65f49b1..dc65565 100644 --- a/content/test/test_browser_context.h +++ b/content/test/test_browser_context.h @@ -30,6 +30,7 @@ class TestBrowserContext : public content::BrowserContext { virtual HostZoomMap* GetHostZoomMap() OVERRIDE; virtual GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; + virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; virtual WebKitContext* GetWebKitContext() OVERRIDE; |