diff options
Diffstat (limited to 'chromium/content/browser/mojo')
12 files changed, 101 insertions, 433 deletions
diff --git a/chromium/content/browser/mojo/browser_shell_connection.cc b/chromium/content/browser/mojo/browser_shell_connection.cc deleted file mode 100644 index 71e3bf3f368..00000000000 --- a/chromium/content/browser/mojo/browser_shell_connection.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/mojo/browser_shell_connection.h" - -#include "base/bind.h" -#include "content/browser/mojo/constants.h" -#include "content/public/common/mojo_application_info.h" -#include "services/shell/public/interfaces/connector.mojom.h" - -namespace content { - -BrowserShellConnection::BrowserShellConnection() {} - -BrowserShellConnection::BrowserShellConnection( - shell::mojom::ShellClientRequest request) - : shell_connection_(new shell::ShellConnection(this, std::move(request))) {} - -BrowserShellConnection::~BrowserShellConnection() {} - -shell::Connector* BrowserShellConnection::GetConnector() { - DCHECK(shell_connection_); - return shell_connection_->connector(); -} - -void BrowserShellConnection::AddEmbeddedApplication( - const base::StringPiece& name, - const MojoApplicationInfo& info) { - std::unique_ptr<EmbeddedApplicationRunner> app( - new EmbeddedApplicationRunner(name, info)); - AddShellClientRequestHandler( - name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, - base::Unretained(app.get()))); - auto result = embedded_apps_.insert( - std::make_pair(name.as_string(), std::move(app))); - DCHECK(result.second); -} - -void BrowserShellConnection::AddShellClientRequestHandler( - const base::StringPiece& name, - const ShellClientRequestHandler& handler) { - auto result = request_handlers_.insert( - std::make_pair(name.as_string(), handler)); - DCHECK(result.second); -} - -bool BrowserShellConnection::AcceptConnection(shell::Connection* connection) { - std::string remote_app = connection->GetRemoteIdentity().name(); - if (remote_app == "mojo:shell") { - // Only expose the SCF interface to the shell. - connection->AddInterface<shell::mojom::ShellClientFactory>(this); - return true; - } - - // Allow connections from the root browser application. - if (remote_app == kBrowserMojoApplicationName && - connection->GetRemoteIdentity().user_id() == shell::mojom::kRootUserID) - return true; - - // Reject all other connections to this application. - return false; -} - -void BrowserShellConnection::Create( - shell::Connection* connection, - shell::mojom::ShellClientFactoryRequest request) { - factory_bindings_.AddBinding(this, std::move(request)); -} - -void BrowserShellConnection::CreateShellClient( - shell::mojom::ShellClientRequest request, - const mojo::String& name) { - auto it = request_handlers_.find(name); - if (it != request_handlers_.end()) - it->second.Run(std::move(request)); -} - -} // namespace content diff --git a/chromium/content/browser/mojo/browser_shell_connection.h b/chromium/content/browser/mojo/browser_shell_connection.h deleted file mode 100644 index 62968320a83..00000000000 --- a/chromium/content/browser/mojo/browser_shell_connection.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ -#define CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ - -#include <memory> -#include <string> -#include <unordered_map> - -#include "base/callback.h" -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "base/single_thread_task_runner.h" -#include "base/strings/string_piece.h" -#include "content/common/mojo/embedded_application_runner.h" -#include "content/public/common/mojo_application_info.h" -#include "mojo/public/cpp/bindings/binding_set.h" -#include "services/shell/public/cpp/connector.h" -#include "services/shell/public/cpp/interface_factory.h" -#include "services/shell/public/cpp/shell_client.h" -#include "services/shell/public/cpp/shell_connection.h" -#include "services/shell/public/interfaces/shell_client.mojom.h" -#include "services/shell/public/interfaces/shell_client_factory.mojom.h" - -namespace content { - -// A connection from the browser process to the Mojo shell. There may be -// multiple connections in a single browser process. Each connection may have -// its own identity, e.g., a connection with unique user ID per BrowserContext. -class BrowserShellConnection - : public shell::ShellClient, - public shell::InterfaceFactory<shell::mojom::ShellClientFactory>, - public shell::mojom::ShellClientFactory { - public: - using ShellClientRequestHandler = - base::Callback<void(shell::mojom::ShellClientRequest)>; - - // Constructs a connection which does not own a ShellClient pipe. This - // connection must be manually fed new incoming connections via its - // shell::ShellClient interface. - BrowserShellConnection(); - - // Constructs a connection associated with its own ShellClient pipe. - explicit BrowserShellConnection(shell::mojom::ShellClientRequest request); - - ~BrowserShellConnection() override; - - shell::Connector* GetConnector(); - - // Adds an embedded application to this connection's ShellClientFactory. - // |info| provides details on how to construct new instances of the - // application when an incoming connection is made to |name|. - void AddEmbeddedApplication(const base::StringPiece& name, - const MojoApplicationInfo& info); - - // Adds a generic ShellClientRequestHandler for a given application name. This - // will be used to satisfy any incoming calls to CreateShellClient() which - // reference the given name. - // - // For in-process applications, it is preferrable to use - // |AddEmbeddedApplication()| as defined above. - void AddShellClientRequestHandler(const base::StringPiece& name, - const ShellClientRequestHandler& handler); - - private: - // shell::ShellClient: - bool AcceptConnection(shell::Connection* connection) override; - - // shell::InterfaceFactory<shell::mojom::ShellClientFactory>: - void Create(shell::Connection* connection, - shell::mojom::ShellClientFactoryRequest request) override; - - // shell::mojom::ShellClientFactory: - void CreateShellClient(shell::mojom::ShellClientRequest request, - const mojo::String& name) override; - - std::unique_ptr<shell::ShellConnection> shell_connection_; - mojo::BindingSet<shell::mojom::ShellClientFactory> factory_bindings_; - std::unordered_map<std::string, std::unique_ptr<EmbeddedApplicationRunner>> - embedded_apps_; - std::unordered_map<std::string, ShellClientRequestHandler> request_handlers_; - - DISALLOW_COPY_AND_ASSIGN(BrowserShellConnection); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ diff --git a/chromium/content/browser/mojo/constants.cc b/chromium/content/browser/mojo/constants.cc index cbb79379eeb..4fe5f2ab705 100644 --- a/chromium/content/browser/mojo/constants.cc +++ b/chromium/content/browser/mojo/constants.cc @@ -11,9 +11,19 @@ namespace content { // src/content/public/app/mojo/content_browser_manifest.json. const char kBrowserMojoApplicationName[] = "exe:content_browser"; +// The default application name used to identify the gpu process when +// connecting it to the shell. This must match the name in +// src/content/public/app/mojo/content_gpu_manifest.json. +const char kGpuMojoApplicationName[] = "exe:content_gpu"; + // The default application name used to identify render processes when // connecting them to the shell. This must match the name in // src/content/public/app/mojo/content_renderer_manifest.json. const char kRendererMojoApplicationName[] = "exe:content_renderer"; +// The default application name used to identify utility processes when +// connecting them to the shell. This must match the name in +// src/content/public/app/mojo/content_utility_manifest.json. +const char kUtilityMojoApplicationName[] = "exe:content_utility"; + } // namespace content diff --git a/chromium/content/browser/mojo/constants.h b/chromium/content/browser/mojo/constants.h index ed6120a5c33..2fd761a17c7 100644 --- a/chromium/content/browser/mojo/constants.h +++ b/chromium/content/browser/mojo/constants.h @@ -8,7 +8,9 @@ namespace content { extern const char kBrowserMojoApplicationName[]; +extern const char kGpuMojoApplicationName[]; extern const char kRendererMojoApplicationName[]; +extern const char kUtilityMojoApplicationName[]; } // namespace content diff --git a/chromium/content/browser/mojo/mojo_app_connection_impl.cc b/chromium/content/browser/mojo/mojo_app_connection_impl.cc deleted file mode 100644 index 582da64dc5d..00000000000 --- a/chromium/content/browser/mojo/mojo_app_connection_impl.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/mojo/mojo_app_connection_impl.h" - -#include <stdint.h> -#include <utility> - -#include "base/bind.h" -#include "content/browser/mojo/mojo_shell_context.h" - -namespace content { - -const char kBrowserMojoAppUrl[] = "system:content_browser"; - -namespace { -void OnGotInstanceID(shell::mojom::ConnectResult result, - const std::string& user_id, - uint32_t remote_id) {} -} // namespace - -// static -std::unique_ptr<MojoAppConnection> MojoAppConnection::Create( - const std::string& user_id, - const std::string& name, - const std::string& requestor_name) { - return std::unique_ptr<MojoAppConnection>( - new MojoAppConnectionImpl(user_id, name, requestor_name)); -} - -MojoAppConnectionImpl::MojoAppConnectionImpl( - const std::string& user_id, - const std::string& name, - const std::string& requestor_name) { - MojoShellContext::ConnectToApplication( - user_id, name, requestor_name, mojo::GetProxy(&interfaces_), - shell::mojom::InterfaceProviderPtr(), base::Bind(&OnGotInstanceID)); -} - -MojoAppConnectionImpl::~MojoAppConnectionImpl() { -} - -void MojoAppConnectionImpl::GetInterface( - const std::string& interface_name, - mojo::ScopedMessagePipeHandle handle) { - interfaces_->GetInterface(interface_name, std::move(handle)); -} - -} // namespace content diff --git a/chromium/content/browser/mojo/mojo_app_connection_impl.h b/chromium/content/browser/mojo/mojo_app_connection_impl.h deleted file mode 100644 index e2ed0bd3dfb..00000000000 --- a/chromium/content/browser/mojo/mojo_app_connection_impl.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_MOJO_MOJO_APP_CONNECTION_IMPL_H_ -#define CONTENT_BROWSER_MOJO_MOJO_APP_CONNECTION_IMPL_H_ - -#include "base/macros.h" -#include "content/public/browser/mojo_app_connection.h" -#include "services/shell/public/interfaces/interface_provider.mojom.h" - -namespace content { - -// Implementation of the app connection mechanism provided to browser code. -class MojoAppConnectionImpl : public MojoAppConnection { - public: - // Takes a BrowserContext and derives a mojo userid from it for this - // connection. - MojoAppConnectionImpl(const std::string& user_id, - const std::string& name, - const std::string& requestor_name); - ~MojoAppConnectionImpl() override; - - private: - // MojoAppConnection: - void GetInterface(const std::string& interface_name, - mojo::ScopedMessagePipeHandle handle) override; - - shell::mojom::InterfaceProviderPtr interfaces_; - - DISALLOW_COPY_AND_ASSIGN(MojoAppConnectionImpl); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_MOJO_MOJO_APP_CONNECTION_IMPL_H_ diff --git a/chromium/content/browser/mojo/mojo_application_host.cc b/chromium/content/browser/mojo/mojo_application_host.cc deleted file mode 100644 index f2b110e71b1..00000000000 --- a/chromium/content/browser/mojo/mojo_application_host.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/mojo/mojo_application_host.h" - -#include <utility> - -#include "base/logging.h" -#include "build/build_config.h" -#include "mojo/edk/embedder/embedder.h" - -namespace content { -namespace { - -class ApplicationSetupImpl : public mojom::ApplicationSetup { - public: - ApplicationSetupImpl(ServiceRegistryImpl* service_registry, - mojo::InterfaceRequest<mojom::ApplicationSetup> request) - : binding_(this, std::move(request)), - service_registry_(service_registry) {} - - ~ApplicationSetupImpl() override { - } - - private: - // mojom::ApplicationSetup implementation. - void ExchangeInterfaceProviders( - shell::mojom::InterfaceProviderRequest services, - shell::mojom::InterfaceProviderPtr exposed_services) override { - service_registry_->Bind(std::move(services)); - service_registry_->BindRemoteServiceProvider(std::move(exposed_services)); - } - - mojo::Binding<mojom::ApplicationSetup> binding_; - ServiceRegistryImpl* service_registry_; -}; - -} // namespace - -MojoApplicationHost::MojoApplicationHost() - : token_(mojo::edk::GenerateRandomToken()) { -#if defined(OS_ANDROID) - service_registry_android_ = - ServiceRegistryAndroid::Create(&service_registry_); -#endif - - mojo::ScopedMessagePipeHandle pipe = - mojo::edk::CreateParentMessagePipe(token_); - DCHECK(pipe.is_valid()); - application_setup_.reset(new ApplicationSetupImpl( - &service_registry_, - mojo::MakeRequest<mojom::ApplicationSetup>(std::move(pipe)))); -} - -MojoApplicationHost::~MojoApplicationHost() { -} - -} // namespace content diff --git a/chromium/content/browser/mojo/mojo_application_host.h b/chromium/content/browser/mojo/mojo_application_host.h deleted file mode 100644 index b1bc026cfdc..00000000000 --- a/chromium/content/browser/mojo/mojo_application_host.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ -#define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ - -#include <memory> -#include <string> - -#include "base/macros.h" -#include "build/build_config.h" -#include "content/common/application_setup.mojom.h" -#include "content/common/mojo/service_registry_impl.h" - -#if defined(OS_ANDROID) -#include "content/public/browser/android/service_registry_android.h" -#endif - -namespace IPC { -class Sender; -} - -namespace content { - -// MojoApplicationHost represents the code needed on the browser side to setup -// a child process as a Mojo application. The child process should use the token -// from GetToken() to initialize its MojoApplication. MojoApplicationHost makes -// the ServiceRegistry interface available so that child-provided services can -// be invoked. -class CONTENT_EXPORT MojoApplicationHost { - public: - MojoApplicationHost(); - ~MojoApplicationHost(); - - // Returns a token to pass to the child process to initialize its - // MojoApplication. - const std::string& GetToken() { return token_; } - - ServiceRegistry* service_registry() { return &service_registry_; } - -#if defined(OS_ANDROID) - ServiceRegistryAndroid* service_registry_android() { - return service_registry_android_.get(); - } -#endif - - private: - const std::string token_; - - std::unique_ptr<mojom::ApplicationSetup> application_setup_; - ServiceRegistryImpl service_registry_; - -#if defined(OS_ANDROID) - std::unique_ptr<ServiceRegistryAndroid> service_registry_android_; -#endif - - DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ diff --git a/chromium/content/browser/mojo/mojo_child_connection.cc b/chromium/content/browser/mojo/mojo_child_connection.cc index 333271a651e..896d8f5aafc 100644 --- a/chromium/content/browser/mojo/mojo_child_connection.cc +++ b/chromium/content/browser/mojo/mojo_child_connection.cc @@ -17,16 +17,12 @@ namespace content { MojoChildConnection::MojoChildConnection(const std::string& application_name, - const std::string& instance_id) + const std::string& instance_id, + const std::string& child_token, + shell::Connector* connector) : shell_client_token_(mojo::edk::GenerateRandomToken()) { mojo::ScopedMessagePipeHandle shell_client_pipe = - mojo::edk::CreateParentMessagePipe(shell_client_token_); - - // Some process types get created before the main message loop. In this case - // the shell request pipe will simply be closed, and the child can detect - // this. - if (!MojoShellConnection::Get()) - return; + mojo::edk::CreateParentMessagePipe(shell_client_token_, child_token); shell::mojom::ShellClientPtr client; client.Bind(mojo::InterfacePtrInfo<shell::mojom::ShellClient>( @@ -39,7 +35,16 @@ MojoChildConnection::MojoChildConnection(const std::string& application_name, shell::Connector::ConnectParams params(target); params.set_client_process_connection(std::move(client), std::move(pid_receiver_request)); - connection_ = MojoShellConnection::Get()->GetConnector()->Connect(¶ms); + + // In some unit testing scenarios a null connector is passed. + if (!connector) + return; + + connection_ = connector->Connect(¶ms); +#if defined(OS_ANDROID) + service_registry_android_ = ServiceRegistryAndroid::Create( + connection_->GetInterfaceRegistry(), connection_->GetRemoteInterfaces()); +#endif } MojoChildConnection::~MojoChildConnection() {} diff --git a/chromium/content/browser/mojo/mojo_child_connection.h b/chromium/content/browser/mojo/mojo_child_connection.h index 369442725b0..7227284cc16 100644 --- a/chromium/content/browser/mojo/mojo_child_connection.h +++ b/chromium/content/browser/mojo/mojo_child_connection.h @@ -12,8 +12,13 @@ #include "base/process/process_handle.h" #include "services/shell/public/interfaces/connector.mojom.h" +#if defined(OS_ANDROID) +#include "content/public/browser/android/service_registry_android.h" +#endif + namespace shell { class Connection; +class Connector; } namespace content { @@ -26,8 +31,11 @@ class MojoChildConnection { // Prepares a new child connection for a child process which will be // identified to the shell as |application_name|. |instance_id| must be // unique among all child connections using the same |application_name|. + // |connector| is the connector to use to establish the connection. MojoChildConnection(const std::string& application_name, - const std::string& instance_id); + const std::string& instance_id, + const std::string& child_token, + shell::Connector* connector); ~MojoChildConnection(); shell::Connection* connection() const { @@ -44,10 +52,19 @@ class MojoChildConnection { // functional until this is called. void SetProcessHandle(base::ProcessHandle handle); +#if defined(OS_ANDROID) + ServiceRegistryAndroid* service_registry_android() { + return service_registry_android_.get(); + } +#endif + private: const std::string shell_client_token_; std::unique_ptr<shell::Connection> connection_; shell::mojom::PIDReceiverPtr pid_receiver_; +#if defined(OS_ANDROID) + std::unique_ptr<ServiceRegistryAndroid> service_registry_android_; +#endif DISALLOW_COPY_AND_ASSIGN(MojoChildConnection); }; diff --git a/chromium/content/browser/mojo/mojo_shell_context.cc b/chromium/content/browser/mojo/mojo_shell_context.cc index 9ed0b916dca..e454437fb83 100644 --- a/chromium/content/browser/mojo/mojo_shell_context.cc +++ b/chromium/content/browser/mojo/mojo_shell_context.cc @@ -16,7 +16,6 @@ #include "base/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "content/browser/gpu/gpu_process_host.h" -#include "content/browser/mojo/browser_shell_connection.h" #include "content/browser/mojo/constants.h" #include "content/common/gpu_process_launch_causes.h" #include "content/common/mojo/mojo_shell_connection_impl.h" @@ -28,7 +27,7 @@ #include "content/public/browser/utility_process_host_client.h" #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" -#include "content/public/common/service_registry.h" +#include "mojo/edk/embedder/embedder.h" #include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/string.h" #include "services/catalog/catalog.h" @@ -36,11 +35,13 @@ #include "services/catalog/store.h" #include "services/shell/connect_params.h" #include "services/shell/native_runner.h" +#include "services/shell/public/cpp/connector.h" #include "services/shell/public/cpp/identity.h" #include "services/shell/public/cpp/shell_client.h" #include "services/shell/public/interfaces/connector.mojom.h" #include "services/shell/public/interfaces/shell_client.mojom.h" #include "services/shell/public/interfaces/shell_client_factory.mojom.h" +#include "services/shell/runner/common/client_util.h" #include "services/shell/runner/host/in_process_native_runner.h" #include "services/user/public/cpp/constants.h" @@ -48,6 +49,21 @@ namespace content { namespace { +using ConnectorPtr = base::ThreadLocalPointer<shell::Connector>; + +base::LazyInstance<ConnectorPtr>::Leaky io_connector_tls_ptr = + LAZY_INSTANCE_INITIALIZER; + +void SetConnectorOnIOThread(std::unique_ptr<shell::Connector> connector) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + io_connector_tls_ptr.Pointer()->Set(connector.release()); +} + +void DestroyConnectorOnIOThread() { + delete MojoShellContext::GetConnectorForIOThread(); + io_connector_tls_ptr.Pointer()->Set(nullptr); +} + void StartUtilityProcessOnIOThread( mojo::InterfaceRequest<mojom::ProcessControl> request, const base::string16& process_name, @@ -59,8 +75,7 @@ void StartUtilityProcessOnIOThread( process_host->DisableSandbox(); process_host->Start(); - ServiceRegistry* services = process_host->GetServiceRegistry(); - services->ConnectToRemoteService(std::move(request)); + process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); } void OnApplicationLoaded(const std::string& name, bool success) { @@ -102,8 +117,7 @@ void RequestGpuProcessControl( // load requests through mojom::ProcessControl will also fail. Make sure we // handle // these cases correctly. - process_host->GetServiceRegistry()->ConnectToRemoteService( - std::move(request)); + process_host->GetRemoteInterfaces()->GetInterface(std::move(request)); } void LaunchAppInGpuProcess(const std::string& app_name, @@ -210,26 +224,6 @@ class MojoShellContext::Proxy { DISALLOW_COPY_AND_ASSIGN(Proxy); }; -// Used to attach an existing ShellClient instance as a listener on the global -// MojoShellConnection. -// TODO(rockot): Find a way to get rid of this. -class ShellConnectionListener : public MojoShellConnection::Listener { - public: - ShellConnectionListener(std::unique_ptr<shell::ShellClient> client) - : client_(std::move(client)) {} - ~ShellConnectionListener() override {} - - private: - // MojoShellConnection::Listener: - bool AcceptConnection(shell::Connection* connection) override { - return client_->AcceptConnection(connection); - } - - std::unique_ptr<shell::ShellClient> client_; - - DISALLOW_COPY_AND_ASSIGN(ShellConnectionListener); -}; - // static base::LazyInstance<std::unique_ptr<MojoShellContext::Proxy>> MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; @@ -254,8 +248,12 @@ MojoShellContext::MojoShellContext() { manifest_provider_->AddManifests(std::move(manifests)); manifest_provider_->AddManifestResource(kBrowserMojoApplicationName, IDR_MOJO_CONTENT_BROWSER_MANIFEST); + manifest_provider_->AddManifestResource(kGpuMojoApplicationName, + IDR_MOJO_CONTENT_GPU_MANIFEST); manifest_provider_->AddManifestResource(kRendererMojoApplicationName, IDR_MOJO_CONTENT_RENDERER_MANIFEST); + manifest_provider_->AddManifestResource(kUtilityMojoApplicationName, + IDR_MOJO_CONTENT_UTILITY_MANIFEST); manifest_provider_->AddManifestResource("mojo:catalog", IDR_MOJO_CATALOG_MANIFEST); manifest_provider_->AddManifestResource(user_service::kUserServiceName, @@ -264,29 +262,37 @@ MojoShellContext::MojoShellContext() { catalog_.reset(new catalog::Catalog(file_task_runner.get(), nullptr, manifest_provider_.get())); - if (!IsRunningInMojoShell()) { + shell::mojom::ShellClientRequest request; + if (shell::ShellIsRemote()) { + mojo::edk::SetParentPipeHandleFromCommandLine(); + request = shell::GetShellClientRequestFromCommandLine(); + } else { shell_.reset(new shell::Shell(std::move(native_runner_factory), catalog_->TakeShellClient())); - MojoShellConnection::Create( - shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), - false /* is_external */); + request = shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName); } - GetContentClient()->browser()->AddMojoShellConnectionListeners(); + MojoShellConnection::SetForProcess( + MojoShellConnection::Create(std::move(request))); - std::unique_ptr<BrowserShellConnection> browser_shell_connection( - new BrowserShellConnection); + std::unique_ptr<shell::Connector> io_connector = + MojoShellConnection::GetForProcess()->GetConnector()->Clone(); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&SetConnectorOnIOThread, base::Passed(&io_connector))); ContentBrowserClient::StaticMojoApplicationMap apps; GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); - for (const auto& entry : apps) - browser_shell_connection->AddEmbeddedApplication(entry.first, entry.second); + for (const auto& entry : apps) { + MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, + entry.second); + } ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; GetContentClient() ->browser() ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); for (const auto& app : sandboxed_apps) { - browser_shell_connection->AddShellClientRequestHandler( + MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( app.first, base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, true /* use_sandbox */)); @@ -297,27 +303,23 @@ MojoShellContext::MojoShellContext() { ->browser() ->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); for (const auto& app : unsandboxed_apps) { - browser_shell_connection->AddShellClientRequestHandler( + MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( app.first, base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, false /* use_sandbox */)); } #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) - browser_shell_connection->AddShellClientRequestHandler( + MojoShellConnection::GetForProcess()->AddShellClientRequestHandler( "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); #endif - - // Attach our ShellClientFactory implementation to the global connection. - MojoShellConnection* shell_connection = MojoShellConnection::Get(); - CHECK(shell_connection); - shell_connection->AddListener(base::WrapUnique( - new ShellConnectionListener(std::move(browser_shell_connection)))); } MojoShellContext::~MojoShellContext() { - if (!IsRunningInMojoShell()) - MojoShellConnectionImpl::Destroy(); + if (MojoShellConnection::GetForProcess()) + MojoShellConnection::DestroyForProcess(); + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, + base::Bind(&DestroyConnectorOnIOThread)); catalog_.reset(); } @@ -334,6 +336,12 @@ void MojoShellContext::ConnectToApplication( std::move(exposed_services), callback); } +// static +shell::Connector* MojoShellContext::GetConnectorForIOThread() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return io_connector_tls_ptr.Pointer()->Get(); +} + void MojoShellContext::ConnectToApplicationOnOwnThread( const std::string& user_id, const std::string& name, diff --git a/chromium/content/browser/mojo/mojo_shell_context.h b/chromium/content/browser/mojo/mojo_shell_context.h index dc738a45abb..6ef9f895680 100644 --- a/chromium/content/browser/mojo/mojo_shell_context.h +++ b/chromium/content/browser/mojo/mojo_shell_context.h @@ -45,6 +45,9 @@ class CONTENT_EXPORT MojoShellContext { shell::mojom::InterfaceProviderPtr exposed_services, const shell::mojom::Connector::ConnectCallback& callback); + // Returns a shell::Connector that can be used on the IO thread. + static shell::Connector* GetConnectorForIOThread(); + private: class BuiltinManifestProvider; class Proxy; |