Commit 45474842 authored by Xiangjun Zhang's avatar Xiangjun Zhang Committed by Commit Bot

Setup mirroring service.

This CL setup a sandboxed utility service for mirroring. The service encodes the
captured audio/video streams and sends them to the remote Cast receiver. The
sandbox type is set to "renderer" since the service does media encoding and
cast control messages parsing, which has similar requirements as a renderer in
term of sandbox policy.

Bug: 734672
Change-Id: Ieeb1e373241266c15535f6d4d8fa54337ca59941
Reviewed-on: https://chromium-review.googlesource.com/1162932Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Xiangjun Zhang <xjz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584186}
parent 59fa81ea
......@@ -446,7 +446,10 @@ service_manifest("chrome_content_packaged_services_manifest_overlay") {
if (is_android) {
packaged_services += [ ":chrome_download_manager_manifest" ]
} else {
packaged_services += [ "//chrome/utility:profile_import_manifest" ]
packaged_services += [
"//components/mirroring/service:manifest",
"//chrome/utility:profile_import_manifest",
]
}
if (is_chromeos) {
packaged_services += [
......
......@@ -1749,6 +1749,7 @@ jumbo_split_static_library("browser") {
"//components/metrics:ui",
"//components/metrics_services_manager",
"//components/mirroring/browser:browser",
"//components/mirroring/mojom:constants",
"//components/mirroring/mojom:host",
"//components/mirroring/mojom:service",
"//components/mirroring/service:mirroring_service",
......
......@@ -179,6 +179,8 @@
#include "components/google/core/common/google_util.h"
#include "components/metrics/call_stack_profile_collector.h"
#include "components/metrics/client_info.h"
#include "components/mirroring/mojom/constants.mojom.h"
#include "components/mirroring/service/features.h"
#include "components/nacl/common/buildflags.h"
#include "components/nacl/common/nacl_constants.h"
#include "components/net_log/chrome_net_log.h"
......@@ -3753,6 +3755,15 @@ void ChromeContentBrowserClient::RegisterOutOfProcessServices(
});
}
#endif
#if !defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(mirroring::features::kMirroringService) &&
base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams) &&
base::FeatureList::IsEnabled(network::features::kNetworkService)) {
(*services)[mirroring::mojom::kServiceName] =
base::BindRepeating(&base::ASCIIToUTF16, "Mirroring Service");
}
#endif
}
bool ChromeContentBrowserClient::ShouldTerminateOnServiceQuit(
......
......@@ -30,6 +30,8 @@ static_library("utility") {
"//chrome:strings",
"//chrome/common",
"//chrome/common:mojo_bindings",
"//components/mirroring/mojom:constants",
"//components/mirroring/service:mirroring_service",
"//components/search_engines",
"//components/services/heap_profiling",
"//components/services/heap_profiling/public/cpp",
......
......@@ -20,6 +20,8 @@ include_rules = [
"+chrome/services/wifi_util_win/wifi_util_win_service.h",
"+chrome/services/wifi_util_win/public/mojom",
"+components/crash/core/common/crash_keys.h",
"+components/mirroring/mojom",
"+components/mirroring/service",
"+components/payments/content/utility",
"+components/services/heap_profiling/heap_profiling_service.h",
"+components/services/heap_profiling/public",
......
......@@ -14,16 +14,21 @@
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "chrome/common/buildflags.h"
#include "components/mirroring/mojom/constants.mojom.h"
#include "components/mirroring/service/features.h"
#include "components/mirroring/service/mirroring_service.h"
#include "components/services/heap_profiling/heap_profiling_service.h"
#include "components/services/heap_profiling/public/mojom/constants.mojom.h"
#include "components/services/unzip/public/interfaces/constants.mojom.h"
#include "components/services/unzip/unzip_service.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/simple_connection_filter.h"
#include "content/public/utility/utility_thread.h"
#include "device/vr/buildflags/buildflags.h"
#include "extensions/buildflags/buildflags.h"
#include "services/network/public/cpp/features.h"
#include "services/service_manager/embedder/embedded_service_info.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/sandbox/switches.h"
......@@ -291,6 +296,19 @@ void ChromeContentUtilityClient::RegisterServices(
}
#endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_ANDROID)
#if !defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(mirroring::features::kMirroringService) &&
base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams) &&
base::FeatureList::IsEnabled(network::features::kNetworkService)) {
service_manager::EmbeddedServiceInfo mirroring_info;
mirroring_info.factory =
base::BindRepeating([]() -> std::unique_ptr<service_manager::Service> {
return std::make_unique<mirroring::MirroringService>();
});
services->emplace(mirroring::mojom::kServiceName, mirroring_info);
}
#endif
#if defined(OS_CHROMEOS)
// TODO(jamescook): Figure out why we have to do this when not using mash.
mash_service_factory_->RegisterOutOfProcessServices(services);
......
......@@ -4,6 +4,12 @@
import("//mojo/public/tools/bindings/mojom.gni")
mojom("constants") {
sources = [
"constants.mojom",
]
}
mojom("common") {
sources = [
"cast_message_channel.mojom",
......
// Copyright 2018 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 mirroring.mojom;
const string kServiceName = "mirroring";
......@@ -2,8 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//services/catalog/public/tools/catalog.gni")
import("//services/service_manager/public/cpp/service.gni")
import("//services/service_manager/public/service_manifest.gni")
import("//services/service_manager/public/tools/test/service_test.gni")
import("//testing/test.gni")
service_manifest("manifest") {
name = "mirroring"
source = "manifest.json"
}
component("mirroring_service") {
sources = [
"captured_audio_input.cc",
......@@ -16,6 +25,8 @@ component("mirroring_service") {
"message_dispatcher.h",
"mirror_settings.cc",
"mirror_settings.h",
"mirroring_service.cc",
"mirroring_service.h",
"receiver_response.cc",
"receiver_response.h",
"remoting_sender.cc",
......@@ -58,6 +69,7 @@ component("mirroring_service") {
"//net",
"//services/network/public/cpp",
"//services/network/public/mojom",
"//services/service_manager/public/cpp:cpp",
"//ui/gfx",
]
......@@ -95,13 +107,11 @@ source_set("unittests") {
"//media/cast:net",
"//media/cast:sender",
"//media/cast:test_support",
"//media/cast:test_support",
"//media/mojo/interfaces",
"//media/mojo/interfaces:remoting",
"//mojo/public/cpp/bindings",
"//net",
"//services/network:test_support",
"//services/network/public/cpp",
"//services/network/public/mojom",
"//testing/gmock",
"//testing/gtest",
......
......@@ -7,4 +7,5 @@ include_rules = [
"+net",
"+services/network/public",
"+services/network/test",
"+services/service_manager",
]
per-file manifest.json=set noparent
per-file manifest.json=file://ipc/SECURITY_OWNERS
......@@ -6,7 +6,7 @@
#define COMPONENTS_MIRRORING_SERVICE_FAKE_NETWORK_SERVICE_H_
#include "base/callback.h"
#include "media/cast/net/cast_transport_config.h"
#include "media/cast/net/cast_transport_defines.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/network/public/mojom/udp_socket.mojom.h"
#include "services/network/test/test_network_context.h"
......
{
"name": "mirroring",
"sandbox_type": "utility",
"display_name": "Mirroring Service",
"interface_provider_specs": {
"service_manager:connector": {
"provides": {
"mirroring": [
"mirroring.mojom.MirroringService"
]
}
}
}
}
// Copyright 2018 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 "components/mirroring/service/mirroring_service.h"
#include "base/callback.h"
#include "components/mirroring/service/session.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
namespace mirroring {
MirroringService::MirroringService() {
registry_.AddInterface<mojom::MirroringService>(
base::BindRepeating(&MirroringService::Create, base::Unretained(this)));
}
MirroringService::~MirroringService() {
session_.reset();
registry_.RemoveInterface<mojom::MirroringService>();
}
void MirroringService::OnStart() {
ref_factory_.reset(new service_manager::ServiceContextRefFactory(
context()->CreateQuitClosure()));
}
void MirroringService::OnBindInterface(
const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
registry_.BindInterface(interface_name, std::move(interface_pipe));
}
bool MirroringService::OnServiceManagerConnectionLost() {
bindings_.CloseAllBindings();
return true;
}
void MirroringService::Create(mojom::MirroringServiceRequest request) {
bindings_.AddBinding(this, std::move(request));
bindings_.set_connection_error_handler(base::BindRepeating(
[](MirroringService* service) {
service->session_.reset();
service->bindings_.CloseAllBindings();
},
this));
}
void MirroringService::Start(mojom::SessionParametersPtr params,
const gfx::Size& max_resolution,
mojom::SessionObserverPtr observer,
mojom::ResourceProviderPtr resource_provider,
mojom::CastMessageChannelPtr outbound_channel,
mojom::CastMessageChannelRequest inbound_channel) {
session_.reset(); // Stops the current session if active.
session_ = std::make_unique<Session>(
std::move(params), max_resolution, std::move(observer),
std::move(resource_provider), std::move(outbound_channel),
std::move(inbound_channel));
}
} // namespace mirroring
// Copyright 2018 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 COMPONENTS_MIRRORING_SERVICE_MIRRORING_SERVICE_H_
#define COMPONENTS_MIRRORING_SERVICE_MIRRORING_SERVICE_H_
#include "base/component_export.h"
#include "base/macros.h"
#include "components/mirroring/mojom/mirroring_service.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
namespace service_manager {
class ServiceContextRefFactory;
} // namespace service_manager
namespace mirroring {
class Session;
class COMPONENT_EXPORT(MIRRORING_SERVICE) MirroringService final
: public service_manager::Service,
public mojom::MirroringService {
public:
MirroringService();
~MirroringService() override;
private:
// service_manager::Service implementation.
void OnStart() override;
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
bool OnServiceManagerConnectionLost() override;
// Handles the request to connect to this service.
void Create(mojom::MirroringServiceRequest request);
// mojom::MirroringService implementation.
void Start(mojom::SessionParametersPtr params,
const gfx::Size& max_resolution,
mojom::SessionObserverPtr observer,
mojom::ResourceProviderPtr resource_provider,
mojom::CastMessageChannelPtr outbound_channel,
mojom::CastMessageChannelRequest inbound_channel) override;
std::unique_ptr<service_manager::ServiceContextRefFactory> ref_factory_;
service_manager::BinderRegistry registry_;
mojo::BindingSet<mojom::MirroringService> bindings_;
std::unique_ptr<Session> session_; // Current mirroring session.
DISALLOW_COPY_AND_ASSIGN(MirroringService);
};
} // namespace mirroring
#endif // COMPONENTS_MIRRORING_SERVICE_MIRRORING_SERVICE_H_
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