Index: content/browser/mojo/mojo_shell_context.cc |
diff --git a/content/browser/mojo/mojo_shell_context.cc b/content/browser/mojo/mojo_shell_context.cc |
index af716e209da880f34cc47fba5c5c19c15dd482da..4736a541668a0762f8f8d31471ef9744ac2f7ecf 100644 |
--- a/content/browser/mojo/mojo_shell_context.cc |
+++ b/content/browser/mojo/mojo_shell_context.cc |
@@ -16,10 +16,10 @@ |
#include "base/single_thread_task_runner.h" |
#include "base/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" |
-#include "content/common/mojo/static_loader.h" |
#include "content/common/process_control.mojom.h" |
#include "content/grit/content_resources.h" |
#include "content/public/browser/browser_thread.h" |
@@ -35,11 +35,12 @@ |
#include "services/catalog/manifest_provider.h" |
#include "services/catalog/store.h" |
#include "services/shell/connect_params.h" |
-#include "services/shell/loader.h" |
#include "services/shell/native_runner.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/host/in_process_native_runner.h" |
#include "services/user/public/cpp/constants.h" |
@@ -70,34 +71,22 @@ void OnApplicationLoaded(const std::string& name, bool success) { |
LOG(ERROR) << "Failed to launch Mojo application for " << name; |
} |
-// This launches a utility process and forwards the Load request the |
-// mojom::ProcessControl service there. The utility process is sandboxed iff |
-// |use_sandbox| is true. |
-class UtilityProcessLoader : public shell::Loader { |
- public: |
- UtilityProcessLoader(const base::string16& process_name, bool use_sandbox) |
- : process_name_(process_name), use_sandbox_(use_sandbox) {} |
- ~UtilityProcessLoader() override {} |
- |
- private: |
- // shell::Loader: |
- void Load(const std::string& name, |
- shell::mojom::ShellClientRequest request) override { |
- mojom::ProcessControlPtr process_control; |
- auto process_request = mojo::GetProxy(&process_control); |
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
- base::Bind(&StartUtilityProcessOnIOThread, |
- base::Passed(&process_request), |
- process_name_, use_sandbox_)); |
- process_control->LoadApplication(name, std::move(request), |
- base::Bind(&OnApplicationLoaded, name)); |
- } |
- |
- const base::string16 process_name_; |
- const bool use_sandbox_; |
+void LaunchAppInUtilityProcess(const std::string& app_name, |
+ const base::string16& process_name, |
+ bool use_sandbox, |
+ shell::mojom::ShellClientRequest request) { |
+ mojom::ProcessControlPtr process_control; |
+ mojom::ProcessControlRequest process_request = |
+ mojo::GetProxy(&process_control); |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ base::Bind(&StartUtilityProcessOnIOThread, |
+ base::Passed(&process_request), |
+ process_name, use_sandbox)); |
+ process_control->LoadApplication(app_name, std::move(request), |
+ base::Bind(&OnApplicationLoaded, app_name)); |
+} |
- DISALLOW_COPY_AND_ASSIGN(UtilityProcessLoader); |
-}; |
+#if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
// Request mojom::ProcessControl from GPU process host. Must be called on IO |
// thread. |
@@ -120,27 +109,19 @@ void RequestGpuProcessControl( |
std::move(request)); |
} |
-// Forwards the load request to the GPU process. |
-class GpuProcessLoader : public shell::Loader { |
- public: |
- GpuProcessLoader() {} |
- ~GpuProcessLoader() override {} |
- |
- private: |
- // shell::Loader: |
- void Load(const std::string& name, |
- shell::mojom::ShellClientRequest request) override { |
- mojom::ProcessControlPtr process_control; |
- auto process_request = mojo::GetProxy(&process_control); |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
- process_control->LoadApplication(name, std::move(request), |
- base::Bind(&OnApplicationLoaded, name)); |
- } |
+void LaunchAppInGpuProcess(const std::string& app_name, |
+ shell::mojom::ShellClientRequest request) { |
+ mojom::ProcessControlPtr process_control; |
+ mojom::ProcessControlRequest process_request = |
+ mojo::GetProxy(&process_control); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
+ process_control->LoadApplication(app_name, std::move(request), |
+ base::Bind(&OnApplicationLoaded, app_name)); |
+} |
- DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); |
-}; |
+#endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS |
} // namespace |
@@ -216,6 +197,26 @@ 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; |
@@ -249,6 +250,15 @@ MojoShellContext::MojoShellContext() { |
shell_.reset(new shell::Shell(std::move(native_runner_factory), |
catalog_->TakeShellClient())); |
+ if (!IsRunningInMojoShell()) { |
+ MojoShellConnection::Create( |
+ shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), |
+ false /* is_external */); |
+ } |
+ |
+ std::unique_ptr<BrowserShellConnection> browser_shell_connection( |
+ new BrowserShellConnection); |
+ |
StaticApplicationMap apps; |
GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
if (g_applications_for_test) { |
@@ -258,8 +268,8 @@ MojoShellContext::MojoShellContext() { |
apps[entry.first] = entry.second; |
} |
for (const auto& entry : apps) { |
- shell_->SetLoaderForName(base::WrapUnique(new StaticLoader(entry.second)), |
- entry.first); |
+ browser_shell_connection->AddEmbeddedApplication( |
+ entry.first, entry.second, nullptr); |
} |
ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; |
@@ -267,9 +277,10 @@ MojoShellContext::MojoShellContext() { |
->browser() |
->RegisterOutOfProcessMojoApplications(&sandboxed_apps); |
for (const auto& app : sandboxed_apps) { |
- shell_->SetLoaderForName(base::WrapUnique(new UtilityProcessLoader( |
- app.second, true /* use_sandbox */)), |
- app.first); |
+ browser_shell_connection->AddShellClientRequestHandler( |
+ app.first, |
+ base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, |
+ true /* use_sandbox */)); |
} |
ContentBrowserClient::OutOfProcessMojoApplicationMap unsandboxed_apps; |
@@ -277,21 +288,22 @@ MojoShellContext::MojoShellContext() { |
->browser() |
->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); |
for (const auto& app : unsandboxed_apps) { |
- shell_->SetLoaderForName(base::WrapUnique(new UtilityProcessLoader( |
- app.second, false /* use_sandbox */)), |
- app.first); |
+ browser_shell_connection->AddShellClientRequestHandler( |
+ app.first, |
+ base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, |
+ false /* use_sandbox */)); |
} |
#if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
- shell_->SetLoaderForName(base::WrapUnique(new GpuProcessLoader), |
- "mojo:media"); |
+ browser_shell_connection->AddShellClientRequestHandler( |
+ "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); |
#endif |
- if (!IsRunningInMojoShell()) { |
- MojoShellConnection::Create( |
- shell_->InitInstanceForEmbedder(kBrowserMojoApplicationName), |
- false /* is_external */); |
- } |
+ // Attach our ShellClientFactory implementation to the global connection. |
+ MojoShellConnection* shell_connection = MojoShellConnection::Get(); |
+ CHECK(shell_connection); |
+ shell_connection->AddListener( |
+ new ShellConnectionListener(std::move(browser_shell_connection))); |
} |
MojoShellContext::~MojoShellContext() { |