0

Rename SODA to speech recognition

This CL renames the generic pieces of the live caption feature from
"SODA" to "Speech Recognition". The SODA-specific pieces will not be
renamed including the presandbox hook, logic to retrieve the paths of
SODA-specific files, SODA component, and SODA client.

Bug: 1069284
Change-Id: Ic379b68cae607e77959a24368d93677a805b2713
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142765
Commit-Queue: Evan Liu <evliu@google.com>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758073}
This commit is contained in:
evliu
2020-04-09 23:35:29 +00:00
committed by Commit Bot
parent 11121ec4b9
commit 2e5dbee4d9
57 changed files with 466 additions and 432 deletions

@ -10467,9 +10467,9 @@ Please help our engineers fix this problem. Tell us what happened right before y
Learn more
</message>
<!-- Speech On-Device API -->
<message name="IDS_UTILITY_PROCESS_SODA_SERVICE_NAME" desc="The name of the service process used to interface with the Speech On-Demand API.">
SODA Service
<!-- Speech Recognition -->
<message name="IDS_UTILITY_PROCESS_SPEECH_RECOGNITION_SERVICE_NAME" desc="The name of the service process used to interface with the Speech On-Demand API.">
Speech recognition service
</message>
<!-- App pause prompt -->

@ -3618,14 +3618,14 @@ jumbo_static_library("browser") {
"signin/signin_promo.h",
"signin/signin_ui_util.cc",
"signin/signin_ui_util.h",
"soda/soda_service.cc",
"soda/soda_service.h",
"soda/soda_service_factory.cc",
"soda/soda_service_factory.h",
"speech/extension_api/tts_extension_api_constants.cc", # Should be moved
# to extensions
# section?
"speech/extension_api/tts_extension_api_constants.h",
"speech/speech_recognition_service.cc",
"speech/speech_recognition_service.h",
"speech/speech_recognition_service_factory.cc",
"speech/speech_recognition_service_factory.h",
"ssl/ssl_client_auth_observer.cc",
"ssl/ssl_client_auth_observer.h",
"status_icons/desktop_notification_balloon.cc",

@ -100,13 +100,13 @@
#else
#include "chrome/browser/badging/badge_manager.h"
#include "chrome/browser/payments/payment_request_factory.h"
#include "chrome/browser/soda/soda_service.h"
#include "chrome/browser/soda/soda_service_factory.h"
#include "chrome/browser/speech/speech_recognition_service.h"
#include "chrome/browser/speech/speech_recognition_service_factory.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "chrome/browser/ui/webui/downloads/downloads_ui.h"
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h"
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#endif
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
@ -346,14 +346,16 @@ void BindNetworkHintsHandler(
}
#if !defined(OS_ANDROID)
void BindSodaContextHandler(
void BindSpeechRecognitionContextHandler(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<media::mojom::SodaContext> receiver) {
mojo::PendingReceiver<media::mojom::SpeechRecognitionContext> receiver) {
Profile* profile = Profile::FromBrowserContext(
frame_host->GetProcess()->GetBrowserContext());
PrefService* profile_prefs = profile->GetPrefs();
if (profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled))
SodaServiceFactory::GetForProfile(profile)->Create(std::move(receiver));
if (profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled)) {
SpeechRecognitionServiceFactory::GetForProfile(profile)->Create(
std::move(receiver));
}
}
#endif
@ -436,8 +438,8 @@ void PopulateChromeFrameBinders(
base::BindRepeating(&BindNetworkHintsHandler));
#if !defined(OS_ANDROID)
map->Add<media::mojom::SodaContext>(
base::BindRepeating(&BindSodaContextHandler));
map->Add<media::mojom::SpeechRecognitionContext>(
base::BindRepeating(&BindSpeechRecognitionContextHandler));
#endif
}

@ -3607,7 +3607,7 @@ base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
case service_manager::SandboxType::kCdm:
case service_manager::SandboxType::kPrintCompositor:
case service_manager::SandboxType::kAudio:
case service_manager::SandboxType::kSoda:
case service_manager::SandboxType::kSpeechRecognition:
case service_manager::SandboxType::kProxyResolver:
case service_manager::SandboxType::kPdfConversion:
case service_manager::SandboxType::kSharingService:

@ -65,7 +65,7 @@ void SODAComponentInstallerPolicy::UpdateSODAComponentOnDemand() {
bool SODAComponentInstallerPolicy::VerifyInstallation(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) const {
return base::PathExists(install_dir.Append(soda::kSodaBinaryRelativePath));
return base::PathExists(install_dir.Append(speech::kSodaBinaryRelativePath));
}
bool SODAComponentInstallerPolicy::SupportsGroupPolicyEnabledComponentUpdates()
@ -97,7 +97,7 @@ void SODAComponentInstallerPolicy::ComponentReady(
}
base::FilePath SODAComponentInstallerPolicy::GetRelativeInstallDir() const {
return base::FilePath(soda::kSodaInstallationRelativePath);
return base::FilePath(speech::kSodaInstallationRelativePath);
}
void SODAComponentInstallerPolicy::GetHash(std::vector<uint8_t>* hash) const {
@ -122,7 +122,7 @@ void UpdateSODAInstallDirPref(PrefService* prefs,
const base::FilePath& install_dir) {
#if !defined(OS_ANDROID)
prefs->SetFilePath(prefs::kSODAPath,
install_dir.Append(soda::kSodaBinaryRelativePath));
install_dir.Append(speech::kSodaBinaryRelativePath));
#endif
}

@ -1,43 +0,0 @@
// Copyright 2020 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/soda/soda_service.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/service_process_host.h"
namespace soda {
constexpr base::TimeDelta kIdleProcessTimeout = base::TimeDelta::FromSeconds(5);
SodaService::SodaService() = default;
SodaService::~SodaService() = default;
void SodaService::Create(
mojo::PendingReceiver<media::mojom::SodaContext> receiver) {
LaunchIfNotRunning();
soda_service_->BindContext(std::move(receiver));
}
void SodaService::LaunchIfNotRunning() {
if (soda_service_.is_bound())
return;
content::ServiceProcessHost::Launch(
soda_service_.BindNewPipeAndPassReceiver(),
content::ServiceProcessHost::Options()
.WithDisplayName(IDS_UTILITY_PROCESS_SODA_SERVICE_NAME)
.WithSandboxType(service_manager::SandboxType::kSoda)
.Pass());
// Ensure that if the interface is ever disconnected (e.g. the service
// process crashes) or goes idle for a short period of time -- meaning there
// are no in-flight messages and no other interfaces bound through this
// one -- then we will reset |remote|, causing the service process to be
// terminated if it isn't already.
soda_service_.reset_on_disconnect();
soda_service_.reset_on_idle_timeout(kIdleProcessTimeout);
}
} // namespace soda

@ -1,39 +0,0 @@
// Copyright 2020 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_SODA_SODA_SERVICE_H_
#define CHROME_BROWSER_SODA_SODA_SERVICE_H_
#include "components/keyed_service/core/keyed_service.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
class Profile;
namespace soda {
// Provides a mojo endpoint in the browser that allows the renderer process to
// launch and initialize the sandboxed Speech On-Device API (SODA) service
// process.
class SodaService : public KeyedService {
public:
explicit SodaService();
SodaService(const SodaService&) = delete;
SodaService& operator=(const SodaService&) = delete;
~SodaService() override;
void Create(mojo::PendingReceiver<media::mojom::SodaContext> receiver);
private:
// Launches the SODA service in a sandboxed utility process.
void LaunchIfNotRunning();
// The remote to the SODA service. The browser will not launch a new SODA
// service process if this remote is already bound.
mojo::Remote<media::mojom::SodaService> soda_service_;
};
} // namespace soda
#endif // CHROME_BROWSER_SODA_SODA_SERVICE_H_

@ -1,34 +0,0 @@
// Copyright 2020 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/soda/soda_service_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/soda/soda_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
// static
soda::SodaService* SodaServiceFactory::GetForProfile(Profile* profile) {
return static_cast<soda::SodaService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
SodaServiceFactory* SodaServiceFactory::GetInstance() {
static base::NoDestructor<SodaServiceFactory> instance;
return instance.get();
}
SodaServiceFactory::SodaServiceFactory()
: BrowserContextKeyedServiceFactory(
"SodaService",
BrowserContextDependencyManager::GetInstance()) {}
SodaServiceFactory::~SodaServiceFactory() = default;
KeyedService* SodaServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return new soda::SodaService();
}

@ -1,39 +0,0 @@
// Copyright 2020 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_SODA_SODA_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SODA_SODA_SERVICE_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <class T>
class NoDestructor;
} // namespace base
namespace soda {
class SodaService;
} // namespace soda
// Factory to get or create an instance of SodaServiceFactory from
// a Profile.
class SodaServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static soda::SodaService* GetForProfile(Profile* profile);
private:
friend class base::NoDestructor<SodaServiceFactory>;
static SodaServiceFactory* GetInstance();
SodaServiceFactory();
~SodaServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
};
#endif // CHROME_BROWSER_SODA_SODA_SERVICE_FACTORY_H_

@ -0,0 +1,43 @@
// Copyright 2020 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/speech_recognition_service.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/service_process_host.h"
namespace speech {
constexpr base::TimeDelta kIdleProcessTimeout = base::TimeDelta::FromSeconds(5);
SpeechRecognitionService::SpeechRecognitionService() = default;
SpeechRecognitionService::~SpeechRecognitionService() = default;
void SpeechRecognitionService::Create(
mojo::PendingReceiver<media::mojom::SpeechRecognitionContext> receiver) {
LaunchIfNotRunning();
speech_recognition_service_->BindContext(std::move(receiver));
}
void SpeechRecognitionService::LaunchIfNotRunning() {
if (speech_recognition_service_.is_bound())
return;
content::ServiceProcessHost::Launch(
speech_recognition_service_.BindNewPipeAndPassReceiver(),
content::ServiceProcessHost::Options()
.WithDisplayName(IDS_UTILITY_PROCESS_SPEECH_RECOGNITION_SERVICE_NAME)
.WithSandboxType(service_manager::SandboxType::kSpeechRecognition)
.Pass());
// Ensure that if the interface is ever disconnected (e.g. the service
// process crashes) or goes idle for a short period of time -- meaning there
// are no in-flight messages and no other interfaces bound through this
// one -- then we will reset |remote|, causing the service process to be
// terminated if it isn't already.
speech_recognition_service_.reset_on_disconnect();
speech_recognition_service_.reset_on_idle_timeout(kIdleProcessTimeout);
}
} // namespace speech

@ -0,0 +1,39 @@
// Copyright 2020 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_SPEECH_RECOGNITION_SERVICE_H_
#define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_H_
#include "components/keyed_service/core/keyed_service.h"
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace speech {
// Provides a mojo endpoint in the browser that allows the renderer process to
// launch and initialize the sandboxed speech recognition service
// process.
class SpeechRecognitionService : public KeyedService {
public:
SpeechRecognitionService();
SpeechRecognitionService(const SpeechRecognitionService&) = delete;
SpeechRecognitionService& operator=(const SpeechRecognitionService&) = delete;
~SpeechRecognitionService() override;
void Create(
mojo::PendingReceiver<media::mojom::SpeechRecognitionContext> receiver);
private:
// Launches the speech recognition service in a sandboxed utility process.
void LaunchIfNotRunning();
// The remote to the speech recognition service. The browser will not launch a
// new speech recognition service process if this remote is already bound.
mojo::Remote<media::mojom::SpeechRecognitionService>
speech_recognition_service_;
};
} // namespace speech
#endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_H_

@ -0,0 +1,36 @@
// Copyright 2020 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/speech_recognition_service_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/speech_recognition_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
// static
speech::SpeechRecognitionService*
SpeechRecognitionServiceFactory::GetForProfile(Profile* profile) {
return static_cast<speech::SpeechRecognitionService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
SpeechRecognitionServiceFactory*
SpeechRecognitionServiceFactory::GetInstance() {
static base::NoDestructor<SpeechRecognitionServiceFactory> instance;
return instance.get();
}
SpeechRecognitionServiceFactory::SpeechRecognitionServiceFactory()
: BrowserContextKeyedServiceFactory(
"SpeechRecognitionService",
BrowserContextDependencyManager::GetInstance()) {}
SpeechRecognitionServiceFactory::~SpeechRecognitionServiceFactory() = default;
KeyedService* SpeechRecognitionServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return new speech::SpeechRecognitionService();
}

@ -0,0 +1,40 @@
// Copyright 2020 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_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <class T>
class NoDestructor;
} // namespace base
namespace speech {
class SpeechRecognitionService;
} // namespace speech
// Factory to get or create an instance of SpeechRecognitionServiceFactory from
// a Profile.
class SpeechRecognitionServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static speech::SpeechRecognitionService* GetForProfile(Profile* profile);
private:
friend class base::NoDestructor<SpeechRecognitionServiceFactory>;
static SpeechRecognitionServiceFactory* GetInstance();
SpeechRecognitionServiceFactory();
~SpeechRecognitionServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
};
#endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_SERVICE_FACTORY_H_

@ -54,8 +54,8 @@ std::string GetSandboxTypeInEnglish(content::SandboxType sandbox_type) {
return "Print Compositor";
case content::SandboxType::kAudio:
return "Audio";
case content::SandboxType::kSoda:
return "SODA";
case content::SandboxType::kSpeechRecognition:
return "Speech Recognition";
case content::SandboxType::kProxyResolver:
return "Proxy Resolver";
case content::SandboxType::kPdfConversion:

@ -10,13 +10,14 @@
ChromeSpeechRecognitionClient::ChromeSpeechRecognitionClient(
content::RenderFrame* render_frame) {
mojo::PendingReceiver<media::mojom::SodaContext> soda_context_receiver =
soda_context_.BindNewPipeAndPassReceiver();
soda_context_->BindRecognizer(
soda_recognizer_.BindNewPipeAndPassReceiver(),
soda_recognition_client_receiver_.BindNewPipeAndPassRemote());
mojo::PendingReceiver<media::mojom::SpeechRecognitionContext>
speech_recognition_context_receiver =
speech_recognition_context_.BindNewPipeAndPassReceiver();
speech_recognition_context_->BindRecognizer(
speech_recognition_recognizer_.BindNewPipeAndPassReceiver(),
speech_recognition_client_receiver_.BindNewPipeAndPassRemote());
render_frame->GetBrowserInterfaceBroker()->GetInterface(
std::move(soda_context_receiver));
std::move(speech_recognition_context_receiver));
}
ChromeSpeechRecognitionClient::~ChromeSpeechRecognitionClient() = default;
@ -25,15 +26,17 @@ void ChromeSpeechRecognitionClient::AddAudio(
scoped_refptr<media::AudioBuffer> buffer) {
DCHECK(buffer);
if (IsSpeechRecognitionAvailable()) {
soda_recognizer_->SendAudioToSoda(ConvertToAudioDataS16(std::move(buffer)));
speech_recognition_recognizer_->SendAudioToSpeechRecognitionService(
ConvertToAudioDataS16(std::move(buffer)));
}
}
bool ChromeSpeechRecognitionClient::IsSpeechRecognitionAvailable() {
return soda_recognizer_.is_bound() && soda_recognizer_.is_connected();
return speech_recognition_recognizer_.is_bound() &&
speech_recognition_recognizer_.is_connected();
}
void ChromeSpeechRecognitionClient::OnSodaRecognitionEvent(
void ChromeSpeechRecognitionClient::OnSpeechRecognitionRecognitionEvent(
const std::string& transcription) {
// TODO(evliu): Pass the captions to the caption controller.
NOTIMPLEMENTED();

@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_CHROME_SPEECH_RECOGNITION_CLIENT_H_
#define CHROME_RENDERER_CHROME_SPEECH_RECOGNITION_CLIENT_H_
#ifndef CHROME_RENDERER_MEDIA_CHROME_SPEECH_RECOGNITION_CLIENT_H_
#define CHROME_RENDERER_MEDIA_CHROME_SPEECH_RECOGNITION_CLIENT_H_
#include <memory>
#include "media/base/audio_buffer.h"
#include "media/base/speech_recognition_client.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
@ -19,7 +19,7 @@ class RenderFrame;
class ChromeSpeechRecognitionClient
: public media::SpeechRecognitionClient,
public media::mojom::SodaRecognizerClient {
public media::mojom::SpeechRecognitionRecognizerClient {
public:
explicit ChromeSpeechRecognitionClient(content::RenderFrame* render_frame);
ChromeSpeechRecognitionClient(const ChromeSpeechRecognitionClient&) = delete;
@ -31,21 +31,24 @@ class ChromeSpeechRecognitionClient
void AddAudio(scoped_refptr<media::AudioBuffer> buffer) override;
bool IsSpeechRecognitionAvailable() override;
// media::mojom::SodaRecognizerClient
void OnSodaRecognitionEvent(const std::string& transcription) override;
// media::mojom::SpeechRecognitionRecognizerClient
void OnSpeechRecognitionRecognitionEvent(
const std::string& transcription) override;
private:
media::mojom::AudioDataS16Ptr ConvertToAudioDataS16(
scoped_refptr<media::AudioBuffer> buffer);
mojo::Remote<media::mojom::SodaContext> soda_context_;
mojo::Remote<media::mojom::SodaRecognizer> soda_recognizer_;
mojo::Receiver<media::mojom::SodaRecognizerClient>
soda_recognition_client_receiver_{this};
mojo::Remote<media::mojom::SpeechRecognitionContext>
speech_recognition_context_;
mojo::Remote<media::mojom::SpeechRecognitionRecognizer>
speech_recognition_recognizer_;
mojo::Receiver<media::mojom::SpeechRecognitionRecognizerClient>
speech_recognition_client_receiver_{this};
// The temporary audio bus used to convert the raw audio to the appropriate
// format.
std::unique_ptr<media::AudioBus> temp_audio_bus_;
};
#endif // CHROME_RENDERER_CHROME_SPEECH_RECOGNITION_CLIENT_H_
#endif // CHROME_RENDERER_MEDIA_CHROME_SPEECH_RECOGNITION_CLIENT_H_

@ -1,4 +0,0 @@
# COMPONENT: Internals>Media
evliu@google.com
beccahughes@chromium.org

@ -1,28 +0,0 @@
// Copyright 2020 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/services/soda/soda_service_impl.h"
#include "chrome/services/soda/soda_recognizer_impl.h"
namespace soda {
SodaServiceImpl::SodaServiceImpl(
mojo::PendingReceiver<media::mojom::SodaService> receiver)
: receiver_(this, std::move(receiver)) {}
SodaServiceImpl::~SodaServiceImpl() = default;
void SodaServiceImpl::BindContext(
mojo::PendingReceiver<media::mojom::SodaContext> context) {
soda_contexts_.Add(this, std::move(context));
}
void SodaServiceImpl::BindRecognizer(
mojo::PendingReceiver<media::mojom::SodaRecognizer> receiver,
mojo::PendingRemote<media::mojom::SodaRecognizerClient> client) {
SodaRecognizerImpl::Create(std::move(receiver), std::move(client));
}
} // namespace soda

@ -1,42 +0,0 @@
// Copyright 2020 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_SERVICES_SODA_SODA_SERVICE_IMPL_H_
#define CHROME_SERVICES_SODA_SODA_SERVICE_IMPL_H_
#include "media/mojo/mojom/soda_service.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace soda {
class SodaServiceImpl : public media::mojom::SodaService,
public media::mojom::SodaContext {
public:
explicit SodaServiceImpl(
mojo::PendingReceiver<media::mojom::SodaService> receiver);
~SodaServiceImpl() override;
// media::mojom::SodaService
void BindContext(
mojo::PendingReceiver<media::mojom::SodaContext> context) override;
// media::mojom::SodaContext
void BindRecognizer(
mojo::PendingReceiver<media::mojom::SodaRecognizer> receiver,
mojo::PendingRemote<media::mojom::SodaRecognizerClient> client) override;
private:
mojo::Receiver<media::mojom::SodaService> receiver_;
// The set of receivers used to receive messages from the renderer clients.
mojo::ReceiverSet<media::mojom::SodaContext> soda_contexts_;
DISALLOW_COPY_AND_ASSIGN(SodaServiceImpl);
};
} // namespace soda
#endif // CHROME_SERVICES_SODA_SODA_SERVICE_IMPL_H_

@ -3,7 +3,7 @@
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//chrome/services/soda/buildflags.gni")
import("//chrome/services/speech/buildflags.gni")
buildflag_header("buildflags") {
header = "buildflags.h"
@ -12,10 +12,10 @@ buildflag_header("buildflags") {
source_set("lib") {
sources = [
"soda_recognizer_impl.cc",
"soda_recognizer_impl.h",
"soda_service_impl.cc",
"soda_service_impl.h",
"speech_recognition_recognizer_impl.cc",
"speech_recognition_recognizer_impl.h",
"speech_recognition_service_impl.cc",
"speech_recognition_service_impl.h",
]
public_deps = [

@ -1,4 +1,5 @@
include_rules = [
"+chrome/services/soda/internal",
"+components/soda/constants.h",
"+media",
]

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/services/soda/soda_recognizer_impl.h"
#include "chrome/services/speech/speech_recognition_recognizer_impl.h"
#include "base/bind.h"
#include "components/soda/constants.h"
@ -17,20 +17,20 @@
#include "chrome/services/soda/internal/soda_client.h"
#endif // BUILDFLAG(ENABLE_SODA)
namespace soda {
namespace speech {
namespace {
#if BUILDFLAG(ENABLE_SODA)
// Callback executed by the SODA library on a speech recognition event. The
// callback handle is a void pointer to the SodaRecognizerImpl that owns the
// SODA instance. SodaRecognizerImpl owns the SodaClient which owns the instance
// of SODA and their sequential destruction order ensures that this callback
// will never be called with an invalid callback handle to the
// SodaRecognizerImpl.
// callback handle is a void pointer to the SpeechRecognitionRecognizerImpl that
// owns the SODA instance. SpeechRecognitionRecognizerImpl owns the SodaClient
// which owns the instance of SODA and their sequential destruction order
// ensures that this callback will never be called with an invalid callback
// handle to the SpeechRecognitionRecognizerImpl.
void RecognitionCallback(const char* result, void* callback_handle) {
DCHECK(callback_handle);
static_cast<SodaRecognizerImpl*>(callback_handle)
static_cast<SpeechRecognitionRecognizerImpl*>(callback_handle)
->recognition_event_callback()
.Run(std::string(result));
}
@ -38,31 +38,35 @@ void RecognitionCallback(const char* result, void* callback_handle) {
} // namespace
SodaRecognizerImpl::~SodaRecognizerImpl() = default;
SpeechRecognitionRecognizerImpl::~SpeechRecognitionRecognizerImpl() = default;
void SodaRecognizerImpl::Create(
mojo::PendingReceiver<media::mojom::SodaRecognizer> receiver,
mojo::PendingRemote<media::mojom::SodaRecognizerClient> remote) {
void SpeechRecognitionRecognizerImpl::Create(
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizer> receiver,
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient>
remote) {
mojo::MakeSelfOwnedReceiver(
base::WrapUnique(new SodaRecognizerImpl(std::move(remote))),
base::WrapUnique(new SpeechRecognitionRecognizerImpl(std::move(remote))),
std::move(receiver));
}
void SodaRecognizerImpl::OnRecognitionEvent(const std::string& result) {
client_remote_->OnSodaRecognitionEvent(result);
void SpeechRecognitionRecognizerImpl::OnRecognitionEvent(
const std::string& result) {
client_remote_->OnSpeechRecognitionRecognitionEvent(result);
}
SodaRecognizerImpl::SodaRecognizerImpl(
mojo::PendingRemote<media::mojom::SodaRecognizerClient> remote)
SpeechRecognitionRecognizerImpl::SpeechRecognitionRecognizerImpl(
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient> remote)
: client_remote_(std::move(remote)) {
recognition_event_callback_ = media::BindToCurrentLoop(base::Bind(
&SodaRecognizerImpl::OnRecognitionEvent, weak_factory_.GetWeakPtr()));
recognition_event_callback_ = media::BindToCurrentLoop(
base::Bind(&SpeechRecognitionRecognizerImpl::OnRecognitionEvent,
weak_factory_.GetWeakPtr()));
#if BUILDFLAG(ENABLE_SODA)
soda_client_ = std::make_unique<SodaClient>(GetSodaBinaryPath());
soda_client_ = std::make_unique<soda::SodaClient>(GetSodaBinaryPath());
#endif // BUILDFLAG(ENABLE_SODA)
}
void SodaRecognizerImpl::SendAudioToSoda(media::mojom::AudioDataS16Ptr buffer) {
void SpeechRecognitionRecognizerImpl::SendAudioToSpeechRecognitionService(
media::mojom::AudioDataS16Ptr buffer) {
int channel_count = buffer->channel_count;
int frame_count = buffer->frame_count;
int sample_rate = buffer->sample_rate;
@ -96,4 +100,4 @@ void SodaRecognizerImpl::SendAudioToSoda(media::mojom::AudioDataS16Ptr buffer) {
#endif // BUILDFLAG(ENABLE_SODA)
}
} // namespace soda
} // namespace speech

@ -2,65 +2,71 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_SERVICES_SODA_SODA_RECOGNIZER_IMPL_H_
#define CHROME_SERVICES_SODA_SODA_RECOGNIZER_IMPL_H_
#ifndef CHROME_SERVICES_SPEECH_SPEECH_RECOGNITION_RECOGNIZER_IMPL_H_
#define CHROME_SERVICES_SPEECH_SPEECH_RECOGNITION_RECOGNIZER_IMPL_H_
#include "base/memory/weak_ptr.h"
#include "build/branding_buildflags.h"
#include "chrome/services/soda/buildflags.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "chrome/services/speech/buildflags.h"
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace soda {
class SodaClient;
} // namespace soda
class SodaRecognizerImpl : public media::mojom::SodaRecognizer {
namespace speech {
class SpeechRecognitionRecognizerImpl
: public media::mojom::SpeechRecognitionRecognizer {
public:
using OnRecognitionEventCallback =
base::RepeatingCallback<void(const std::string& result)>;
~SodaRecognizerImpl() override;
~SpeechRecognitionRecognizerImpl() override;
static void Create(
mojo::PendingReceiver<media::mojom::SodaRecognizer> receiver,
mojo::PendingRemote<media::mojom::SodaRecognizerClient> remote);
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizer> receiver,
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient>
remote);
OnRecognitionEventCallback recognition_event_callback() const {
return recognition_event_callback_;
}
private:
explicit SodaRecognizerImpl(
mojo::PendingRemote<media::mojom::SodaRecognizerClient> remote);
explicit SpeechRecognitionRecognizerImpl(
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient>
remote);
// Convert the audio buffer into the appropriate format and feed the raw audio
// into the SODA instance.
void SendAudioToSoda(media::mojom::AudioDataS16Ptr buffer) final;
// into the speech recognition instance.
void SendAudioToSpeechRecognitionService(
media::mojom::AudioDataS16Ptr buffer) final;
// Return the transcribed audio from the recognition event back to the caller
// via the recognition event client.
void OnRecognitionEvent(const std::string& result);
// The remote endpoint for the mojo pipe used to return transcribed audio from
// the SODA service back to the renderer.
mojo::Remote<media::mojom::SodaRecognizerClient> client_remote_;
// the speech recognition service back to the renderer.
mojo::Remote<media::mojom::SpeechRecognitionRecognizerClient> client_remote_;
#if BUILDFLAG(ENABLE_SODA)
std::unique_ptr<SodaClient> soda_client_;
std::unique_ptr<soda::SodaClient> soda_client_;
#endif // BUILDFLAG(ENABLE_SODA)
// The callback that is eventually executed on a speech recognition event
// which passes the transcribed audio back to the caller via the SODA
// which passes the transcribed audio back to the caller via the speech
// recognition event client remote.
OnRecognitionEventCallback recognition_event_callback_;
base::WeakPtrFactory<SodaRecognizerImpl> weak_factory_{this};
base::WeakPtrFactory<SpeechRecognitionRecognizerImpl> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SodaRecognizerImpl);
DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionRecognizerImpl);
};
} // namespace soda
} // namespace speech
#endif // CHROME_SERVICES_SODA_SODA_RECOGNIZER_IMPL_H_
#endif // CHROME_SERVICES_SPEECH_SPEECH_RECOGNITION_RECOGNIZER_IMPL_H_

@ -0,0 +1,30 @@
// Copyright 2020 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/services/speech/speech_recognition_service_impl.h"
#include "chrome/services/speech/speech_recognition_recognizer_impl.h"
namespace speech {
SpeechRecognitionServiceImpl::SpeechRecognitionServiceImpl(
mojo::PendingReceiver<media::mojom::SpeechRecognitionService> receiver)
: receiver_(this, std::move(receiver)) {}
SpeechRecognitionServiceImpl::~SpeechRecognitionServiceImpl() = default;
void SpeechRecognitionServiceImpl::BindContext(
mojo::PendingReceiver<media::mojom::SpeechRecognitionContext> context) {
speech_recognition_contexts_.Add(this, std::move(context));
}
void SpeechRecognitionServiceImpl::BindRecognizer(
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizer> receiver,
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient>
client) {
SpeechRecognitionRecognizerImpl::Create(std::move(receiver),
std::move(client));
}
} // namespace speech

@ -0,0 +1,45 @@
// Copyright 2020 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_SERVICES_SPEECH_SPEECH_RECOGNITION_SERVICE_IMPL_H_
#define CHROME_SERVICES_SPEECH_SPEECH_RECOGNITION_SERVICE_IMPL_H_
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace speech {
class SpeechRecognitionServiceImpl
: public media::mojom::SpeechRecognitionService,
public media::mojom::SpeechRecognitionContext {
public:
explicit SpeechRecognitionServiceImpl(
mojo::PendingReceiver<media::mojom::SpeechRecognitionService> receiver);
~SpeechRecognitionServiceImpl() override;
// media::mojom::SpeechRecognitionService
void BindContext(mojo::PendingReceiver<media::mojom::SpeechRecognitionContext>
context) override;
// media::mojom::SpeechRecognitionContext
void BindRecognizer(
mojo::PendingReceiver<media::mojom::SpeechRecognitionRecognizer> receiver,
mojo::PendingRemote<media::mojom::SpeechRecognitionRecognizerClient>
client) override;
private:
mojo::Receiver<media::mojom::SpeechRecognitionService> receiver_;
// The set of receivers used to receive messages from the renderer clients.
mojo::ReceiverSet<media::mojom::SpeechRecognitionContext>
speech_recognition_contexts_;
DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionServiceImpl);
};
} // namespace speech
#endif // CHROME_SERVICES_SPEECH_SPEECH_RECOGNITION_SERVICE_IMPL_H_

@ -105,7 +105,7 @@ static_library("utility") {
"//chrome/common/importer:interfaces",
"//chrome/services/sharing",
"//chrome/services/sharing/public/mojom",
"//chrome/services/soda:lib",
"//chrome/services/speech:lib",
"//components/autofill/core/common",
"//services/proxy_resolver:lib",
]

@ -14,7 +14,7 @@ include_rules = [
"+chrome/services/qrcode_generator",
"+chrome/services/removable_storage_writer",
"+chrome/services/sharing",
"+chrome/services/soda/soda_service_impl.h",
"+chrome/services/speech/speech_recognition_service_impl.h",
"+chrome/services/util_win/util_win_impl.h",
"+chrome/services/util_win/public/mojom",
"+chromeos/assistant/buildflags.h",

@ -36,10 +36,10 @@
#include "chrome/services/qrcode_generator/qrcode_generator_service_impl.h" // nogncheck
#include "chrome/services/sharing/public/mojom/sharing.mojom.h"
#include "chrome/services/sharing/sharing_impl.h"
#include "chrome/services/soda/soda_service_impl.h"
#include "chrome/services/speech/speech_recognition_service_impl.h"
#include "chrome/utility/importer/profile_import_impl.h"
#include "components/mirroring/service/mirroring_service.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#include "services/proxy_resolver/proxy_resolver_factory_impl.h" // nogncheck
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
#endif // !defined(OS_ANDROID)
@ -139,8 +139,10 @@ auto RunSharing(mojo::PendingReceiver<sharing::mojom::Sharing> receiver) {
return std::make_unique<sharing::SharingImpl>(std::move(receiver));
}
auto RunSodaService(mojo::PendingReceiver<media::mojom::SodaService> receiver) {
return std::make_unique<soda::SodaServiceImpl>(std::move(receiver));
auto RunSpeechRecognitionService(
mojo::PendingReceiver<media::mojom::SpeechRecognitionService> receiver) {
return std::make_unique<speech::SpeechRecognitionServiceImpl>(
std::move(receiver));
}
#endif // !defined(OS_ANDROID)
@ -242,7 +244,7 @@ mojo::ServiceFactory* GetMainThreadServiceFactory() {
RunQRCodeGeneratorService,
RunMirroringService,
RunSharing,
RunSodaService,
RunSpeechRecognitionService,
#endif
#if defined(OS_WIN)

@ -9,7 +9,7 @@
#include "base/path_service.h"
#include "components/component_updater/component_updater_paths.h"
namespace soda {
namespace speech {
constexpr base::FilePath::CharType kSodaInstallationRelativePath[] =
FILE_PATH_LITERAL("SODA");
@ -55,4 +55,4 @@ const base::FilePath GetSodaConfigPath() {
: soda_dir.Append(kSodaConfigFileRelativePath);
}
} // namespace soda
} // namespace speech

@ -7,7 +7,7 @@
#include "base/files/file_path.h"
namespace soda {
namespace speech {
// Location of the SODA component relative to components directory.
extern const base::FilePath::CharType kSodaInstallationRelativePath[];
@ -37,6 +37,6 @@ const base::FilePath GetSodaBinaryPath();
// an empty path if SODA is not installed.
const base::FilePath GetSodaConfigPath();
} // namespace soda
} // namespace speech
#endif // COMPONENTS_SODA_CONSTANTS_H_

@ -117,7 +117,7 @@
#if !defined(OS_ANDROID)
#include "content/browser/installedapp/installed_app_provider_impl.h"
#include "content/public/common/content_switches.h"
#include "media/mojo/mojom/soda_service.mojom.h"
#include "media/mojo/mojom/speech_recognition_service.mojom.h"
#include "third_party/blink/public/mojom/hid/hid.mojom.h"
#include "third_party/blink/public/mojom/serial/serial.mojom.h"
#endif
@ -669,8 +669,8 @@ void PopulateBinderMapWithContext(
map->Add<blink::mojom::AnchorElementMetricsHost>(base::BindRepeating(
&EmptyBinderForFrame<blink::mojom::AnchorElementMetricsHost>));
#if !defined(OS_ANDROID)
map->Add<media::mojom::SodaContext>(
base::BindRepeating(&EmptyBinderForFrame<media::mojom::SodaContext>));
map->Add<media::mojom::SpeechRecognitionContext>(base::BindRepeating(
&EmptyBinderForFrame<media::mojom::SpeechRecognitionContext>));
#endif
#if BUILDFLAG(ENABLE_UNHANDLED_TAP)
map->Add<blink::mojom::UnhandledTapNotifier>(base::BindRepeating(

@ -219,7 +219,7 @@ void SetupSandboxParameters(service_manager::SandboxType sandbox_type,
sandbox::SeatbeltExecClient* client) {
switch (sandbox_type) {
case service_manager::SandboxType::kAudio:
case service_manager::SandboxType::kSoda:
case service_manager::SandboxType::kSpeechRecognition:
case service_manager::SandboxType::kNaClLoader:
case service_manager::SandboxType::kPrintCompositor:
case service_manager::SandboxType::kRenderer:

@ -95,7 +95,7 @@ class UtilitySandboxedProcessLauncherDelegate
#if !defined(OS_MACOSX)
sandbox_type_ == service_manager::SandboxType::kSharingService ||
#endif
sandbox_type_ == service_manager::SandboxType::kSoda;
sandbox_type_ == service_manager::SandboxType::kSpeechRecognition;
DCHECK(supported_sandbox_type);
#endif // DCHECK_IS_ON()
}
@ -210,7 +210,7 @@ class UtilitySandboxedProcessLauncherDelegate
sandbox_type_ == service_manager::SandboxType::kIme ||
#endif // OS_CHROMEOS
sandbox_type_ == service_manager::SandboxType::kAudio ||
sandbox_type_ == service_manager::SandboxType::kSoda) {
sandbox_type_ == service_manager::SandboxType::kSpeechRecognition) {
return service_manager::GetUnsandboxedZygote();
}

@ -116,7 +116,7 @@ class UtilityProcessSandboxBrowserTest
case SandboxType::kIme:
#endif
case SandboxType::kNetwork:
case SandboxType::kSoda: {
case SandboxType::kSpeechRecognition: {
constexpr int kExpectedPartialSandboxFlags =
SandboxLinux::kSeccompBPF | SandboxLinux::kYama |
SandboxLinux::kSeccompTSYNC;

@ -83,7 +83,7 @@ jumbo_source_set("utility") {
}
if (is_linux) {
deps += [ "//content/utility/soda:soda_sandbox_hook" ]
deps += [ "//content/utility/speech:speech_recognition_sandbox_hook" ]
}
if (enable_vr && !is_android) {

@ -1,3 +0,0 @@
per-file soda_sandbox_hook_linux.*=file://sandbox/linux/OWNERS
# COMPONENT: Internals>Sandbox

@ -2,10 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("soda_sandbox_hook") {
source_set("speech_recognition_sandbox_hook") {
sources = [
"soda_sandbox_hook_linux.cc",
"soda_sandbox_hook_linux.h",
"speech_recognition_sandbox_hook_linux.cc",
"speech_recognition_sandbox_hook_linux.h",
]
deps = [

@ -0,0 +1,3 @@
per-file speech_recognition_sandbox_hook_linux.*=file://sandbox/linux/OWNERS
# COMPONENT: Internals>Sandbox

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/utility/soda/soda_sandbox_hook_linux.h"
#include "content/utility/speech/speech_recognition_sandbox_hook_linux.h"
#include <dlfcn.h>
@ -13,10 +13,11 @@
using sandbox::syscall_broker::BrokerFilePermission;
using sandbox::syscall_broker::MakeBrokerCommandSet;
namespace soda {
namespace speech {
namespace {
// Gets the file permissions required by the Speech On-Device API (SODA).
std::vector<BrokerFilePermission> GetSodaFilePermissions(
base::FilePath latest_version_dir) {
std::vector<BrokerFilePermission> permissions{
@ -35,7 +36,8 @@ std::vector<BrokerFilePermission> GetSodaFilePermissions(
} // namespace
bool SodaPreSandboxHook(service_manager::SandboxLinux::Options options) {
bool SpeechRecognitionPreSandboxHook(
service_manager::SandboxLinux::Options options) {
void* soda_library = dlopen(GetSodaBinaryPath().value().c_str(),
RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
DCHECK(soda_library);
@ -55,4 +57,4 @@ bool SodaPreSandboxHook(service_manager::SandboxLinux::Options options) {
return true;
}
} // namespace soda
} // namespace speech

@ -2,17 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_UTILITY_SODA_SODA_SANDBOX_HOOK_LINUX_H_
#define CONTENT_UTILITY_SODA_SODA_SANDBOX_HOOK_LINUX_H_
#ifndef CONTENT_UTILITY_SPEECH_SPEECH_RECOGNITION_SANDBOX_HOOK_LINUX_H_
#define CONTENT_UTILITY_SPEECH_SPEECH_RECOGNITION_SANDBOX_HOOK_LINUX_H_
#include "services/service_manager/sandbox/linux/sandbox_linux.h"
namespace soda {
namespace speech {
// Opens the libsoda.so binary and grants broker file permissions to the
// necessary files required by the binary.
bool SodaPreSandboxHook(service_manager::SandboxLinux::Options options);
bool SpeechRecognitionPreSandboxHook(
service_manager::SandboxLinux::Options options);
} // namespace soda
} // namespace speech
#endif // CONTENT_UTILITY_SODA_SODA_SANDBOX_HOOK_LINUX_H_
#endif // CONTENT_UTILITY_SPEECH_SPEECH_RECOGNITION_SANDBOX_HOOK_LINUX_H_

@ -23,7 +23,7 @@
#include "services/tracing/public/cpp/trace_startup.h"
#if defined(OS_LINUX)
#include "content/utility/soda/soda_sandbox_hook_linux.h"
#include "content/utility/speech/speech_recognition_sandbox_hook_linux.h"
#include "services/audio/audio_sandbox_hook_linux.h"
#include "services/network/network_sandbox_hook_linux.h"
#include "services/service_manager/sandbox/linux/sandbox_linux.h"
@ -85,14 +85,15 @@ int UtilityMain(const MainFunctionParams& parameters) {
sandbox_type == service_manager::SandboxType::kIme ||
#endif // OS_CHROMEOS
sandbox_type == service_manager::SandboxType::kAudio ||
sandbox_type == service_manager::SandboxType::kSoda) {
sandbox_type == service_manager::SandboxType::kSpeechRecognition) {
service_manager::SandboxLinux::PreSandboxHook pre_sandbox_hook;
if (sandbox_type == service_manager::SandboxType::kNetwork)
pre_sandbox_hook = base::BindOnce(&network::NetworkPreSandboxHook);
else if (sandbox_type == service_manager::SandboxType::kAudio)
pre_sandbox_hook = base::BindOnce(&audio::AudioPreSandboxHook);
else if (sandbox_type == service_manager::SandboxType::kSoda)
pre_sandbox_hook = base::BindOnce(&soda::SodaPreSandboxHook);
else if (sandbox_type == service_manager::SandboxType::kSpeechRecognition)
pre_sandbox_hook =
base::BindOnce(&speech::SpeechRecognitionPreSandboxHook);
#if defined(OS_CHROMEOS)
else if (sandbox_type == service_manager::SandboxType::kIme)
pre_sandbox_hook = base::BindOnce(&chromeos::ime::ImePreSandboxHook);

@ -50,7 +50,7 @@ mojom("mojom") {
if (is_android) {
sources += [ "android_overlay.mojom" ]
} else {
sources += [ "soda_service.mojom" ]
sources += [ "speech_recognition_service.mojom" ]
}
if (is_chromecast) {

@ -1,42 +0,0 @@
// Copyright 2020 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.
module media.mojom;
import "media/mojo/mojom/media_types.mojom";
// The main interface a client uses to interact with a SODA service
// process. Every renderer can own one or more Remote<SodaContext>,
// with the receiver bound through the BrowserInterfaceBroker.
interface SodaContext {
// Bind the recognizers to the SODA service.
BindRecognizer(pending_receiver<SodaRecognizer> receiver,
pending_remote<SodaRecognizerClient> client);
};
// The main interface to a Speech On-Device API (SODA) service process.
// Used by the browser to issue top-level control requests to the service,
// acquired during process launch.
interface SodaService {
// Bind the SODA context to a new instance of SODA.
BindContext(pending_receiver<SodaContext> context);
};
// The interface used to pass raw audio from the renderer to the SODA
// service. The remote lives in the renderer process and the receiver
// lives in the SODA process.
interface SodaRecognizer {
// Initialize the SODA instance. SODA will use the SODA recognition client
// to return the recognition events containing the transcribed audio back
// to the originating media.
SendAudioToSoda(AudioDataS16 buffer);
};
// The interface used to return speech recognition events from the SODA
// service back to the originating media. The remote lives in the SODA
// process and the receiver lives in the renderer process.
interface SodaRecognizerClient {
// Triggered by SODA on a speech recognition event.
OnSodaRecognitionEvent(string transcription);
};

@ -0,0 +1,43 @@
// Copyright 2020 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.
module media.mojom;
import "media/mojo/mojom/media_types.mojom";
// The main interface a client uses to interact with a speech recognition
// service process. Every renderer can own one or more
// Remote<SpeechRecognitionContext>, with the receiver bound through the
// BrowserInterfaceBroker.
interface SpeechRecognitionContext {
// Bind the recognizers to the speech recognition service.
BindRecognizer(pending_receiver<SpeechRecognitionRecognizer> receiver,
pending_remote<SpeechRecognitionRecognizerClient> client);
};
// The main interface to a speech secognition service process.
// Used by the browser to issue top-level control requests to the service,
// acquired during process launch.
interface SpeechRecognitionService {
// Bind the context to a new instance of the speech recognition.
BindContext(pending_receiver<SpeechRecognitionContext> context);
};
// The interface used to pass raw audio from the renderer to the speech
// recognition service. The remote lives in the renderer process and the
// receiver lives in the speech recognition process.
interface SpeechRecognitionRecognizer {
// Initialize the speech recognition instance. The speech recognition client
// will return the recognition events containing the transcribed audio back
// to the originating media.
SendAudioToSpeechRecognitionService(AudioDataS16 buffer);
};
// The interface used to return speech recognition events from the speech
// recognition service back to the originating media. The remote lives in the
// speech recognition process and the receiver lives in the renderer process.
interface SpeechRecognitionRecognizerClient {
// Triggered by speech recognition process on a speech recognition event.
OnSpeechRecognitionRecognitionEvent(string transcription);
};

@ -52,8 +52,8 @@ component("sandbox") {
"linux/bpf_renderer_policy_linux.h",
"linux/bpf_sharing_service_policy_linux.cc",
"linux/bpf_sharing_service_policy_linux.h",
"linux/bpf_soda_policy_linux.cc",
"linux/bpf_soda_policy_linux.h",
"linux/bpf_speech_recognition_policy_linux.cc",
"linux/bpf_speech_recognition_policy_linux.h",
"linux/bpf_utility_policy_linux.cc",
"linux/bpf_utility_policy_linux.h",
"linux/sandbox_debug_handling_linux.cc",

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/service_manager/sandbox/linux/bpf_soda_policy_linux.h"
#include "services/service_manager/sandbox/linux/bpf_speech_recognition_policy_linux.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "sandbox/linux/syscall_broker/broker_process.h"
@ -16,10 +16,11 @@ using sandbox::syscall_broker::BrokerProcess;
namespace service_manager {
SodaProcessPolicy::SodaProcessPolicy() = default;
SodaProcessPolicy::~SodaProcessPolicy() = default;
SpeechRecognitionProcessPolicy::SpeechRecognitionProcessPolicy() = default;
SpeechRecognitionProcessPolicy::~SpeechRecognitionProcessPolicy() = default;
ResultExpr SodaProcessPolicy::EvaluateSyscall(int system_call_number) const {
ResultExpr SpeechRecognitionProcessPolicy::EvaluateSyscall(
int system_call_number) const {
switch (system_call_number) {
#if defined(__NR_eventfd2)
case __NR_eventfd2:

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_SERVICE_MANAGER_SANDBOX_LINUX_BPF_SODA_POLICY_LINUX_H_
#define SERVICES_SERVICE_MANAGER_SANDBOX_LINUX_BPF_SODA_POLICY_LINUX_H_
#ifndef SERVICES_SERVICE_MANAGER_SANDBOX_LINUX_BPF_SPEECH_RECOGNITION_POLICY_LINUX_H_
#define SERVICES_SERVICE_MANAGER_SANDBOX_LINUX_BPF_SPEECH_RECOGNITION_POLICY_LINUX_H_
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "services/service_manager/sandbox/linux/bpf_base_policy_linux.h"
@ -13,18 +13,19 @@ namespace service_manager {
// The process policy for the sandboxed utility process that loads the Speech
// On-Device API (SODA). This policy allows the syscalls used by the libsoda.so
// binary to transcribe audio into text.
class SERVICE_MANAGER_SANDBOX_EXPORT SodaProcessPolicy : public BPFBasePolicy {
class SERVICE_MANAGER_SANDBOX_EXPORT SpeechRecognitionProcessPolicy
: public BPFBasePolicy {
public:
SodaProcessPolicy();
~SodaProcessPolicy() override;
SpeechRecognitionProcessPolicy();
~SpeechRecognitionProcessPolicy() override;
sandbox::bpf_dsl::ResultExpr EvaluateSyscall(
int system_call_number) const override;
private:
DISALLOW_COPY_AND_ASSIGN(SodaProcessPolicy);
DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionProcessPolicy);
};
} // namespace service_manager
#endif // SERVICES_SERVICE_MANAGER_SANDBOX_LINUX_BPF_SODA_POLICY_LINUX_H_
#endif // SERVICES_SERVICE_MANAGER_SANDBOX_LINUX_BPF_SPEECH_RECOGNITION_POLICY_LINUX_H_

@ -44,7 +44,7 @@
#include "services/service_manager/sandbox/linux/bpf_print_compositor_policy_linux.h"
#include "services/service_manager/sandbox/linux/bpf_renderer_policy_linux.h"
#include "services/service_manager/sandbox/linux/bpf_sharing_service_policy_linux.h"
#include "services/service_manager/sandbox/linux/bpf_soda_policy_linux.h"
#include "services/service_manager/sandbox/linux/bpf_speech_recognition_policy_linux.h"
#include "services/service_manager/sandbox/linux/bpf_utility_policy_linux.h"
#if !defined(OS_NACL_NONSFI)
@ -179,8 +179,8 @@ std::unique_ptr<BPFBasePolicy> SandboxSeccompBPF::PolicyForSandboxType(
return std::make_unique<AudioProcessPolicy>();
case SandboxType::kSharingService:
return std::make_unique<SharingServiceProcessPolicy>();
case SandboxType::kSoda:
return std::make_unique<SodaProcessPolicy>();
case SandboxType::kSpeechRecognition:
return std::make_unique<SpeechRecognitionProcessPolicy>();
#if defined(OS_CHROMEOS)
case SandboxType::kIme:
return std::make_unique<ImeProcessPolicy>();
@ -229,7 +229,7 @@ void SandboxSeccompBPF::RunSandboxSanityChecks(
#endif // defined(OS_CHROMEOS)
case SandboxType::kAudio:
case SandboxType::kSharingService:
case SandboxType::kSoda:
case SandboxType::kSpeechRecognition:
case SandboxType::kNetwork:
case SandboxType::kUtility:
case SandboxType::kNoSandbox:

@ -262,7 +262,7 @@ std::string SandboxMac::GetSandboxProfile(SandboxType sandbox_type) {
break;
case service_manager::SandboxType::kNoSandbox:
case service_manager::SandboxType::kInvalid:
case service_manager::SandboxType::kSoda:
case service_manager::SandboxType::kSpeechRecognition:
CHECK(false);
break;
}

@ -54,7 +54,7 @@ bool IsUnsandboxedSandboxType(SandboxType sandbox_type) {
#if !defined(OS_MACOSX)
case SandboxType::kSharingService:
#endif
case SandboxType::kSoda:
case SandboxType::kSpeechRecognition:
return false;
}
}
@ -112,7 +112,7 @@ void SetCommandLineFlagsForSandboxType(base::CommandLine* command_line,
#if !defined(OS_MACOSX)
case SandboxType::kSharingService:
#endif
case SandboxType::kSoda:
case SandboxType::kSpeechRecognition:
DCHECK(command_line->GetSwitchValueASCII(switches::kProcessType) ==
switches::kUtilityProcess);
DCHECK(!command_line->HasSwitch(switches::kServiceSandboxType));
@ -192,8 +192,8 @@ std::string StringFromUtilitySandboxType(SandboxType sandbox_type) {
case SandboxType::kSharingService:
return switches::kSharingServiceSandbox;
#endif
case SandboxType::kSoda:
return switches::kSodaSandbox;
case SandboxType::kSpeechRecognition:
return switches::kSpeechRecognitionSandbox;
#if defined(OS_WIN)
case SandboxType::kXrCompositing:
return switches::kXrCompositingSandbox;
@ -252,8 +252,8 @@ SandboxType UtilitySandboxTypeFromString(const std::string& sandbox_string) {
#endif
if (sandbox_string == switches::kAudioSandbox)
return SandboxType::kAudio;
if (sandbox_string == switches::kSodaSandbox)
return SandboxType::kSoda;
if (sandbox_string == switches::kSpeechRecognitionSandbox)
return SandboxType::kSpeechRecognition;
#if defined(OS_CHROMEOS)
if (sandbox_string == switches::kImeSandbox)
return SandboxType::kIme;

@ -79,10 +79,10 @@ enum class SandboxType {
kSharingService,
#endif
// The Speech On-Device API service process.
kSoda,
// The speech recognition service process.
kSpeechRecognition,
kMaxValue = kSoda
kMaxValue = kSpeechRecognition
};
SERVICE_MANAGER_SANDBOX_EXPORT bool IsUnsandboxedSandboxType(

@ -29,7 +29,7 @@ const char kCdmSandbox[] = "cdm";
const char kPrintCompositorSandbox[] = "print_compositor";
const char kAudioSandbox[] = "audio";
const char kSharingServiceSandbox[] = "sharing_service";
const char kSodaSandbox[] = "soda";
const char kSpeechRecognitionSandbox[] = "speech_recognition";
#if defined(OS_WIN)
const char kPdfConversionSandbox[] = "pdf_conversion";

@ -28,7 +28,7 @@ SERVICE_MANAGER_SANDBOX_EXPORT extern const char kCdmSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kPrintCompositorSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kAudioSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kSharingServiceSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kSodaSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kSpeechRecognitionSandbox[];
#if defined(OS_WIN)
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kPdfConversionSandbox[];

@ -85,8 +85,10 @@ TEST(SandboxTypeTest, Utility) {
EXPECT_EQ(SandboxType::kAudio, SandboxTypeFromCommandLine(command_line8));
base::CommandLine command_line9(command_line);
SetCommandLineFlagsForSandboxType(&command_line9, SandboxType::kSoda);
EXPECT_EQ(SandboxType::kSoda, SandboxTypeFromCommandLine(command_line9));
SetCommandLineFlagsForSandboxType(&command_line9,
SandboxType::kSpeechRecognition);
EXPECT_EQ(SandboxType::kSpeechRecognition,
SandboxTypeFromCommandLine(command_line9));
#if defined(OS_WIN)
base::CommandLine command_line10(command_line);