Skip to content

Commit

Permalink
Purge Service Manager bits from within Content
Browse files Browse the repository at this point in the history
This disentangles most of the remaining Service Manager bits brought up
and/or exposed by the Content layer. After this CL, it is trivial to
move Service Manager ownership completely into //chromecast where its
only remaining consumers reside.

Bug: 977637
Change-Id: I8306c5dde888fc14c20b1f6fcdd5d439f0e12831
Tbr: danakj@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2545068
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Yuchen Liu <yucliu@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Sean Topping <seantopping@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#828728}
  • Loading branch information
krockot authored and Commit Bot committed Nov 18, 2020
1 parent 6a7f821 commit e2e6ea0
Show file tree
Hide file tree
Showing 34 changed files with 130 additions and 363 deletions.
5 changes: 4 additions & 1 deletion chromecast/utility/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ cast_source_set("utility") {
"cast_content_utility_client.h",
]

deps = [
public_deps = [
"//base",
"//content/public/utility",
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//services/service_manager/public/mojom",
]

if (chromecast_branding == "public") {
Expand Down
2 changes: 2 additions & 0 deletions chromecast/utility/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ include_rules = [
"+components/services/heap_profiling",
"+components/services/heap_profiling/public/mojom",
"+content/public/utility",
"+mojo/public",
"+services/service_manager/public",
]
14 changes: 14 additions & 0 deletions chromecast/utility/cast_content_utility_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@ namespace shell {

CastContentUtilityClient::CastContentUtilityClient() = default;

bool CastContentUtilityClient::HandleServiceRequestDeprecated(
const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe) {
return HandleServiceRequest(
service_name, mojo::PendingReceiver<service_manager::mojom::Service>(
std::move(service_pipe)));
}

bool CastContentUtilityClient::HandleServiceRequest(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) {
return false;
}

} // namespace shell
} // namespace chromecast
13 changes: 13 additions & 0 deletions chromecast/utility/cast_content_utility_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
#define CHROMECAST_UTILITY_CAST_CONTENT_UTILITY_CLIENT_H_

#include <memory>
#include <string>

#include "base/macros.h"
#include "content/public/utility/content_utility_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/service_manager/public/mojom/service.mojom.h"

namespace chromecast {
namespace shell {
Expand All @@ -19,6 +23,15 @@ class CastContentUtilityClient : public content::ContentUtilityClient {

CastContentUtilityClient();

// cast::ContentUtilityClient:
bool HandleServiceRequestDeprecated(
const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe) override;

virtual bool HandleServiceRequest(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver);

private:
DISALLOW_COPY_AND_ASSIGN(CastContentUtilityClient);
};
Expand Down
6 changes: 0 additions & 6 deletions components/viz/host/gpu_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ void GpuHostImpl::BindInterface(const std::string& interface_name,
delegate_->BindInterface(interface_name, std::move(interface_pipe));
}

void GpuHostImpl::RunService(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) {
delegate_->RunService(service_name, std::move(receiver));
}

mojom::GpuService* GpuHostImpl::gpu_service() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(gpu_service_remote_.is_bound());
Expand Down
6 changes: 0 additions & 6 deletions components/viz/host/gpu_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
virtual void BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) = 0;
virtual void RunService(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) = 0;
#if defined(USE_OZONE)
virtual void TerminateGpuProcess(const std::string& message) = 0;
#endif
Expand Down Expand Up @@ -179,9 +176,6 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {

void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe);
void RunService(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver);

mojom::GpuService* gpu_service();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ class MockChildProcess : public mojom::ChildProcess {
MOCK_METHOD0(CrashHungProcess, void());
MOCK_METHOD1(BootstrapLegacyIpc,
void(mojo::PendingReceiver<IPC::mojom::ChannelBootstrap>));
MOCK_METHOD2(RunService,
void(const std::string&,
mojo::PendingReceiver<service_manager::mojom::Service>));
MOCK_METHOD2(RunServiceDeprecated,
void(const std::string&, mojo::ScopedMessagePipeHandle));
MOCK_METHOD1(BindServiceInterface,
void(mojo::GenericPendingReceiver receiver));
MOCK_METHOD1(BindReceiver, void(mojo::GenericPendingReceiver receiver));
Expand Down
6 changes: 0 additions & 6 deletions content/browser/gpu/gpu_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,6 @@ void GpuProcessHost::BindInterface(
mojo::GenericPendingReceiver(interface_name, std::move(interface_pipe)));
}

void GpuProcessHost::RunService(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) {
process_->GetHost()->RunService(service_name, std::move(receiver));
}

#if defined(USE_OZONE)
void GpuProcessHost::TerminateGpuProcess(const std::string& message) {
// At the moment, this path is only used by Ozone/Wayland. Once others start
Expand Down
3 changes: 0 additions & 3 deletions content/browser/gpu/gpu_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
void BindHostReceiver(mojo::GenericPendingReceiver generic_receiver) override;
void RunService(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) override;
#if defined(USE_OZONE)
void TerminateGpuProcess(const std::string& message) override;
#endif
Expand Down
42 changes: 6 additions & 36 deletions content/browser/service_manager/service_manager_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/child_process_launcher.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/system_connector_impl.h"
#include "content/browser/utility_process_host.h"
#include "content/common/service_manager/service_manager_connection_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -68,9 +64,6 @@ namespace {
base::LazyInstance<std::unique_ptr<service_manager::Connector>>::Leaky
g_io_thread_connector = LAZY_INSTANCE_INITIALIZER;

base::LazyInstance<std::map<std::string, base::WeakPtr<UtilityProcessHost>>>::
Leaky g_active_process_groups;

const service_manager::Manifest& GetContentBrowserManifest() {
static base::NoDestructor<service_manager::Manifest> manifest{
service_manager::ManifestBuilder()
Expand Down Expand Up @@ -109,9 +102,7 @@ service_manager::Manifest GetContentSystemManifest() {
void DestroyConnectorOnIOThread() { g_io_thread_connector.Get().reset(); }

// A ServiceProcessHost implementation which delegates to Content-managed
// processes, either via a new UtilityProcessHost to launch new service
// processes, or the existing GpuProcessHost to run service instances in the GPU
// process.
// processes via a new UtilityProcessHost.
class ContentChildServiceProcessHost
: public service_manager::ServiceProcessHost {
public:
Expand All @@ -124,24 +115,12 @@ class ContentChildServiceProcessHost
sandbox::policy::SandboxType sandbox_type,
const base::string16& display_name,
LaunchCallback callback) override {
mojo::PendingRemote<service_manager::mojom::Service> remote;
auto receiver = remote.InitWithNewPipeAndPassReceiver();

// Start a new process for this service.
UtilityProcessHost* process_host = new UtilityProcessHost();
process_host->SetName(display_name);
process_host->SetMetricsName(identity.name());
process_host->SetServiceIdentity(identity);
process_host->SetSandboxType(sandbox_type);
process_host->Start();
process_host->RunService(
identity.name(), std::move(receiver),
base::BindOnce(
[](LaunchCallback callback,
const base::Optional<base::ProcessId> pid) {
std::move(callback).Run(pid.value_or(base::kNullProcessId));
},
std::move(callback)));
mojo::PendingRemote<service_manager::mojom::Service> remote;
LaunchUtilityProcessServiceDeprecated(
identity.name(), display_name, sandbox_type,
remote.InitWithNewPipeAndPassReceiver().PassPipe(),
std::move(callback));
return remote;
}

Expand Down Expand Up @@ -379,15 +358,6 @@ service_manager::Connector* ServiceManagerContext::GetConnectorForIOThread() {
return g_io_thread_connector.Get().get();
}

// static
bool ServiceManagerContext::HasValidProcessForProcessGroup(
const std::string& process_group_name) {
auto iter = g_active_process_groups.Get().find(process_group_name);
if (iter == g_active_process_groups.Get().end() || !iter->second)
return false;
return iter->second->GetData().GetProcess().IsValid();
}

void ServiceManagerContext::RunServiceInstance(
const service_manager::Identity& identity,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) {
Expand Down
22 changes: 22 additions & 0 deletions content/browser/service_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <utility>

#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
Expand Down Expand Up @@ -210,4 +211,25 @@ void ServiceProcessHost::Launch(mojo::GenericPendingReceiver receiver,
std::move(receiver), std::move(options)));
}

void LaunchUtilityProcessServiceDeprecated(
const std::string& service_name,
const base::string16& display_name,
sandbox::policy::SandboxType sandbox_type,
mojo::ScopedMessagePipeHandle service_pipe,
base::OnceCallback<void(base::ProcessId)> callback) {
UtilityProcessHost* host = new UtilityProcessHost();
host->SetName(display_name);
host->SetMetricsName(service_name);
host->SetSandboxType(sandbox_type);
host->Start();
host->RunServiceDeprecated(
service_name, std::move(service_pipe),
base::BindOnce(
[](base::OnceCallback<void(base::ProcessId)> callback,
const base::Optional<base::ProcessId> pid) {
std::move(callback).Run(pid.value_or(base::kNullProcessId));
},
std::move(callback)));
}

} // namespace content
18 changes: 6 additions & 12 deletions content/browser/utility_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,17 @@ bool UtilityProcessHost::Start() {
return StartProcess();
}

void UtilityProcessHost::RunService(
void UtilityProcessHost::RunServiceDeprecated(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
service_manager::Service::CreatePackagedServiceInstanceCallback callback) {
mojo::ScopedMessagePipeHandle service_pipe,
RunServiceDeprecatedCallback callback) {
if (launch_state_ == LaunchState::kLaunchFailed) {
std::move(callback).Run(base::nullopt);
return;
}

process_->GetHost()->RunService(service_name, std::move(receiver));
process_->GetHost()->RunServiceDeprecated(service_name,
std::move(service_pipe));
if (launch_state_ == LaunchState::kLaunchComplete) {
std::move(callback).Run(process_->GetProcess().Pid());
} else {
Expand All @@ -132,11 +133,6 @@ void UtilityProcessHost::SetName(const base::string16& name) {
name_ = name;
}

void UtilityProcessHost::SetServiceIdentity(
const service_manager::Identity& identity) {
service_identity_ = identity;
}

void UtilityProcessHost::SetExtraCommandLineSwitches(
std::vector<std::string> switches) {
extra_switches_ = std::move(switches);
Expand Down Expand Up @@ -362,9 +358,7 @@ void UtilityProcessHost::OnProcessCrashed(int exit_code) {
}

base::Optional<std::string> UtilityProcessHost::GetServiceName() {
if (!service_identity_)
return metrics_name_;
return service_identity_->name();
return metrics_name_;
}

} // namespace content
29 changes: 9 additions & 20 deletions content/browser/utility_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <vector>

#include "base/callback.h"
#include "base/environment.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
Expand All @@ -24,9 +25,6 @@
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "sandbox/policy/sandbox_type.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/service.mojom.h"

namespace base {
class Thread;
Expand Down Expand Up @@ -93,11 +91,12 @@ class CONTENT_EXPORT UtilityProcessHost
bool Start();

// Instructs the utility process to run an instance of the named service,
// bound to |receiver|.
void RunService(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
service_manager::Service::CreatePackagedServiceInstanceCallback callback);
// bound to |service_pipe|. This is DEPRECATED and should never be used.
using RunServiceDeprecatedCallback =
base::OnceCallback<void(base::Optional<base::ProcessId>)>;
void RunServiceDeprecated(const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe,
RunServiceDeprecatedCallback callback);

// Sets the name of the process to appear in the task manager.
void SetName(const base::string16& name);
Expand All @@ -109,10 +108,6 @@ class CONTENT_EXPORT UtilityProcessHost

void set_child_flags(int flags) { child_flags_ = flags; }

// Used when the utility process is going to host a service. |identity| is
// the identity of the service being launched.
void SetServiceIdentity(const service_manager::Identity& identity);

// Provides extra switches to append to the process's command line.
void SetExtraCommandLineSwitches(std::vector<std::string> switches);

Expand Down Expand Up @@ -158,10 +153,6 @@ class CONTENT_EXPORT UtilityProcessHost
// Used in single-process mode instead of |process_|.
std::unique_ptr<base::Thread> in_process_thread_;

// If this has a value it indicates the process is going to host a mojo
// service.
base::Optional<service_manager::Identity> service_identity_;

// Extra command line switches to append.
std::vector<std::string> extra_switches_;

Expand All @@ -175,10 +166,8 @@ class CONTENT_EXPORT UtilityProcessHost
LaunchState launch_state_ = LaunchState::kLaunchInProgress;

// Collection of callbacks to be run once the process is actually started (or
// fails to start). These are used to notify the Service Manager about which
// process the corresponding services have been started within.
std::vector<service_manager::Service::CreatePackagedServiceInstanceCallback>
pending_run_service_callbacks_;
// fails to start).
std::vector<RunServiceDeprecatedCallback> pending_run_service_callbacks_;

std::unique_ptr<Client> client_;

Expand Down
16 changes: 8 additions & 8 deletions content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,13 @@ class ChildThreadImpl::IOThreadState
mojo::FusePipes(std::move(receiver), std::move(legacy_ipc_bootstrap_));
}

void RunService(const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service>
receiver) override {
void RunServiceDeprecated(
const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe) override {
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&ChildThreadImpl::RunService, weak_main_thread_,
service_name, std::move(receiver)));
FROM_HERE, base::BindOnce(&ChildThreadImpl::RunServiceDeprecated,
weak_main_thread_, service_name,
std::move(service_pipe)));
}

void BindServiceInterface(mojo::GenericPendingReceiver receiver) override {
Expand Down Expand Up @@ -809,9 +809,9 @@ void ChildThreadImpl::GetBackgroundTracingAgentProvider(
background_tracing_agent_provider_->AddBinding(std::move(receiver));
}

void ChildThreadImpl::RunService(
void ChildThreadImpl::RunServiceDeprecated(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver) {
mojo::ScopedMessagePipeHandle service_pipe) {
DLOG(ERROR) << "Ignoring unhandled request to run service: " << service_name;
}

Expand Down
Loading

0 comments on commit e2e6ea0

Please sign in to comment.