Commit 6e0ef1f4 authored by Mark Pilgrim's avatar Mark Pilgrim Committed by Commit Bot

Speech recognition: Use BindOnce / OnceCallback / OnceClosure where applicable

Within browser/speech code, use BindOnce when posting tasks to
check whether speech recognition is allowed.

Bug: 714018
Change-Id: Ifa4eb2797601be2736dda1bf1a17ac57e5a34301
Reviewed-on: https://chromium-review.googlesource.com/565762
Commit-Queue: Mark Pilgrim <pilgrim@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarTommi <tommi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485944}
parent a81aa896
...@@ -271,7 +271,7 @@ void ChromeSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) { ...@@ -271,7 +271,7 @@ void ChromeSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) {
void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
int session_id, int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) { base::OnceCallback<void(bool ask_user, bool is_allowed)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
const content::SpeechRecognitionSessionContext& context = const content::SpeechRecognitionSessionContext& context =
...@@ -292,11 +292,10 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( ...@@ -292,11 +292,10 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
// Check that the render view type is appropriate, and whether or not we // Check that the render view type is appropriate, and whether or not we
// need to request permission from the user. // need to request permission from the user.
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(
base::Bind(&CheckRenderViewType, BrowserThread::UI, FROM_HERE,
callback, base::BindOnce(&CheckRenderViewType, std::move(callback),
render_process_id, render_process_id, render_view_id));
render_view_id));
} }
content::SpeechRecognitionEventListener* content::SpeechRecognitionEventListener*
...@@ -317,7 +316,7 @@ bool ChromeSpeechRecognitionManagerDelegate::FilterProfanities( ...@@ -317,7 +316,7 @@ bool ChromeSpeechRecognitionManagerDelegate::FilterProfanities(
// static. // static.
void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
base::Callback<void(bool ask_user, bool is_allowed)> callback, base::OnceCallback<void(bool ask_user, bool is_allowed)> callback,
int render_process_id, int render_process_id,
int render_view_id) { int render_view_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -331,8 +330,9 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( ...@@ -331,8 +330,9 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
// This happens for extensions. Manifest should be checked for permission. // This happens for extensions. Manifest should be checked for permission.
allowed = true; allowed = true;
check_permission = false; check_permission = false;
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(
base::Bind(callback, check_permission, allowed)); BrowserThread::IO, FROM_HERE,
base::BindOnce(std::move(callback), check_permission, allowed));
return; return;
} }
...@@ -357,8 +357,9 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( ...@@ -357,8 +357,9 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType(
check_permission = true; check_permission = true;
#endif #endif
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(
base::Bind(callback, check_permission, allowed)); BrowserThread::IO, FROM_HERE,
base::BindOnce(std::move(callback), check_permission, allowed));
} }
} // namespace speech } // namespace speech
...@@ -45,7 +45,8 @@ class ChromeSpeechRecognitionManagerDelegate ...@@ -45,7 +45,8 @@ class ChromeSpeechRecognitionManagerDelegate
// SpeechRecognitionManagerDelegate methods. // SpeechRecognitionManagerDelegate methods.
void CheckRecognitionIsAllowed( void CheckRecognitionIsAllowed(
int session_id, int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) override; base::OnceCallback<void(bool ask_user, bool is_allowed)> callback)
override;
content::SpeechRecognitionEventListener* GetEventListener() override; content::SpeechRecognitionEventListener* GetEventListener() override;
bool FilterProfanities(int render_process_id) override; bool FilterProfanities(int render_process_id) override;
...@@ -58,7 +59,7 @@ class ChromeSpeechRecognitionManagerDelegate ...@@ -58,7 +59,7 @@ class ChromeSpeechRecognitionManagerDelegate
// Checks for VIEW_TYPE_TAB_CONTENTS host in the UI thread and notifies back // Checks for VIEW_TYPE_TAB_CONTENTS host in the UI thread and notifies back
// the result in the IO thread through |callback|. // the result in the IO thread through |callback|.
static void CheckRenderViewType( static void CheckRenderViewType(
base::Callback<void(bool ask_user, bool is_allowed)> callback, base::OnceCallback<void(bool ask_user, bool is_allowed)> callback,
int render_process_id, int render_process_id,
int render_view_id); int render_view_id);
......
...@@ -156,9 +156,9 @@ void SpeechRecognitionManagerImpl::StartSession(int session_id) { ...@@ -156,9 +156,9 @@ void SpeechRecognitionManagerImpl::StartSession(int session_id) {
if (delegate_) { if (delegate_) {
delegate_->CheckRecognitionIsAllowed( delegate_->CheckRecognitionIsAllowed(
session_id, session_id,
base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback, base::BindOnce(
weak_factory_.GetWeakPtr(), &SpeechRecognitionManagerImpl::RecognitionAllowedCallback,
session_id)); weak_factory_.GetWeakPtr(), session_id));
} }
} }
...@@ -274,7 +274,7 @@ void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { ...@@ -274,7 +274,7 @@ void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) {
SessionsTable::iterator iter = sessions_.find(session_id); SessionsTable::iterator iter = sessions_.find(session_id);
if (iter->second->ui) { if (iter->second->ui) {
// Notify the UI that the devices are being used. // Notify the UI that the devices are being used.
iter->second->ui->OnStarted(base::Closure(), iter->second->ui->OnStarted(base::OnceClosure(),
MediaStreamUIProxy::WindowIdCallback()); MediaStreamUIProxy::WindowIdCallback());
} }
......
...@@ -24,7 +24,7 @@ class SpeechRecognitionManagerDelegate { ...@@ -24,7 +24,7 @@ class SpeechRecognitionManagerDelegate {
// This is called on the IO thread. // This is called on the IO thread.
virtual void CheckRecognitionIsAllowed( virtual void CheckRecognitionIsAllowed(
int session_id, int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) = 0; base::OnceCallback<void(bool ask_user, bool is_allowed)> callback) = 0;
// Checks whether the delegate is interested (returning a non nullptr ptr) or // Checks whether the delegate is interested (returning a non nullptr ptr) or
// not (returning nullptr) in receiving a copy of all sessions events. // not (returning nullptr) in receiving a copy of all sessions events.
......
...@@ -6,18 +6,19 @@ ...@@ -6,18 +6,19 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
using base::Callback; using base::OnceCallback;
namespace content { namespace content {
void ShellSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( void ShellSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
int session_id, Callback<void(bool ask_user, bool is_allowed)> callback) { int session_id,
OnceCallback<void(bool ask_user, bool is_allowed)> callback) {
// In content_shell, we expect speech recognition to happen when requested. // In content_shell, we expect speech recognition to happen when requested.
// Therefore we simply authorize it by calling back with is_allowed=true. The // Therefore we simply authorize it by calling back with is_allowed=true. The
// first parameter, ask_user, is set to false because we don't want to prompt // first parameter, ask_user, is set to false because we don't want to prompt
// the user for permission with an infobar. // the user for permission with an infobar.
BrowserThread::PostTask( BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
BrowserThread::IO, FROM_HERE, base::Bind(callback, false, true)); base::BindOnce(std::move(callback), false, true));
} }
SpeechRecognitionEventListener* SpeechRecognitionEventListener*
......
...@@ -25,7 +25,8 @@ class ShellSpeechRecognitionManagerDelegate ...@@ -25,7 +25,8 @@ class ShellSpeechRecognitionManagerDelegate
// SpeechRecognitionManagerDelegate methods. // SpeechRecognitionManagerDelegate methods.
void CheckRecognitionIsAllowed( void CheckRecognitionIsAllowed(
int session_id, int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) override; base::OnceCallback<void(bool ask_user, bool is_allowed)> callback)
override;
SpeechRecognitionEventListener* GetEventListener() override; SpeechRecognitionEventListener* GetEventListener() override;
bool FilterProfanities(int render_process_id) override; bool FilterProfanities(int render_process_id) override;
......
...@@ -66,7 +66,7 @@ void ShellSpeechRecognitionManagerDelegate::OnAudioLevelsChange( ...@@ -66,7 +66,7 @@ void ShellSpeechRecognitionManagerDelegate::OnAudioLevelsChange(
void ShellSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( void ShellSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
int session_id, int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) { base::OnceCallback<void(bool ask_user, bool is_allowed)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
const content::SpeechRecognitionSessionContext& context = const content::SpeechRecognitionSessionContext& context =
...@@ -76,11 +76,10 @@ void ShellSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( ...@@ -76,11 +76,10 @@ void ShellSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
// |render_process_id| field, which is needed later to retrieve the profile. // |render_process_id| field, which is needed later to retrieve the profile.
DCHECK_NE(context.render_process_id, 0); DCHECK_NE(context.render_process_id, 0);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(
base::Bind(&CheckRenderViewType, BrowserThread::UI, FROM_HERE,
callback, base::BindOnce(&CheckRenderViewType, std::move(callback),
context.render_process_id, context.render_process_id, context.render_view_id));
context.render_view_id));
} }
content::SpeechRecognitionEventListener* content::SpeechRecognitionEventListener*
...@@ -96,7 +95,7 @@ bool ShellSpeechRecognitionManagerDelegate::FilterProfanities( ...@@ -96,7 +95,7 @@ bool ShellSpeechRecognitionManagerDelegate::FilterProfanities(
// static // static
void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType( void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType(
base::Callback<void(bool ask_user, bool is_allowed)> callback, base::OnceCallback<void(bool ask_user, bool is_allowed)> callback,
int render_process_id, int render_process_id,
int render_view_id) { int render_view_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -119,8 +118,9 @@ void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType( ...@@ -119,8 +118,9 @@ void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType(
} }
} }
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(
base::Bind(callback, check_permission, allowed)); BrowserThread::IO, FROM_HERE,
base::BindOnce(std::move(callback), check_permission, allowed));
} }
} // namespace speech } // namespace speech
......
...@@ -41,12 +41,13 @@ class ShellSpeechRecognitionManagerDelegate ...@@ -41,12 +41,13 @@ class ShellSpeechRecognitionManagerDelegate
// SpeechRecognitionManagerDelegate methods. // SpeechRecognitionManagerDelegate methods.
void CheckRecognitionIsAllowed( void CheckRecognitionIsAllowed(
int session_id, int session_id,
base::Callback<void(bool ask_user, bool is_allowed)> callback) override; base::OnceCallback<void(bool ask_user, bool is_allowed)> callback)
override;
content::SpeechRecognitionEventListener* GetEventListener() override; content::SpeechRecognitionEventListener* GetEventListener() override;
bool FilterProfanities(int render_process_id) override; bool FilterProfanities(int render_process_id) override;
static void CheckRenderViewType( static void CheckRenderViewType(
base::Callback<void(bool ask_user, bool is_allowed)> callback, base::OnceCallback<void(bool ask_user, bool is_allowed)> callback,
int render_process_id, int render_process_id,
int render_view_id); int render_view_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment