summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/browser_main_loop.cc8
-rw-r--r--content/browser/mojo/mojo_shell_context.cc5
-rw-r--r--content/common/mojo/mojo_shell_connection_impl.cc58
-rw-r--r--content/common/mojo/mojo_shell_connection_impl.h14
-rw-r--r--content/public/DEPS2
-rw-r--r--content/public/common/mojo_shell_connection.h12
6 files changed, 74 insertions, 25 deletions
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index 91fec92..eab70cef 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -922,9 +922,11 @@ int BrowserMainLoop::CreateThreads() {
int BrowserMainLoop::PreMainMessageLoopRun() {
if (IsRunningInMojoShell()) {
- mojo::edk::SetParentPipeHandleFromCommandLine();
- MojoShellConnectionImpl::Create();
- MojoShellConnectionImpl::Get()->BindToRequestFromCommandLine();
+ if (!MojoShellConnectionImpl::CreateUsingFactory()) {
+ mojo::edk::SetParentPipeHandleFromCommandLine();
+ MojoShellConnectionImpl::Create();
+ MojoShellConnectionImpl::Get()->BindToRequestFromCommandLine();
+ }
#if defined(MOJO_SHELL_CLIENT) && defined(USE_AURA)
if (MojoShellConnection::Get()) {
views::WindowManagerConnection::Create(
diff --git a/content/browser/mojo/mojo_shell_context.cc b/content/browser/mojo/mojo_shell_context.cc
index 6c1e7a7..80857cd 100644
--- a/content/browser/mojo/mojo_shell_context.cc
+++ b/content/browser/mojo/mojo_shell_context.cc
@@ -259,8 +259,9 @@ MojoShellContext::MojoShellContext() {
make_scoped_ptr(new StaticLoader(profile_callback)), "mojo:profile");
if (!IsRunningInMojoShell()) {
- MojoShellConnectionImpl::Create(
- shell_->InitInstanceForEmbedder(kBrowserAppName));
+ const bool is_external = false;
+ MojoShellConnection::Create(
+ shell_->InitInstanceForEmbedder(kBrowserAppName), is_external);
}
}
diff --git a/content/common/mojo/mojo_shell_connection_impl.cc b/content/common/mojo/mojo_shell_connection_impl.cc
index 8321673..44310d3 100644
--- a/content/common/mojo/mojo_shell_connection_impl.cc
+++ b/content/common/mojo/mojo_shell_connection_impl.cc
@@ -29,17 +29,32 @@ using MojoShellConnectionPtr =
base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr =
LAZY_INSTANCE_INITIALIZER;
+MojoShellConnection::Factory* mojo_shell_connection_factory = nullptr;
+
} // namespace
bool IsRunningInMojoShell() {
- return base::CommandLine::ForCurrentProcess()->HasSwitch(
- mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch);
+ return mojo_shell_connection_factory ||
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch);
}
bool ShouldWaitForShell() {
- return IsRunningInMojoShell() &&
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kWaitForMojoShell);
+ return mojo_shell_connection_factory ||
+ (IsRunningInMojoShell() &&
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kWaitForMojoShell));
+}
+
+// static
+bool MojoShellConnectionImpl::CreateUsingFactory() {
+ if (mojo_shell_connection_factory) {
+ DCHECK(!lazy_tls_ptr.Pointer()->Get());
+ mojo_shell_connection_factory->Run();
+ DCHECK(lazy_tls_ptr.Pointer()->Get());
+ return true;
+ }
+ return false;
}
// static
@@ -51,18 +66,28 @@ void MojoShellConnectionImpl::Create() {
}
// static
-void MojoShellConnectionImpl::Create(
- mojo::shell::mojom::ShellClientRequest request) {
+void MojoShellConnection::Create(mojo::shell::mojom::ShellClientRequest request,
+ bool is_external) {
DCHECK(!lazy_tls_ptr.Pointer()->Get());
MojoShellConnectionImpl* connection =
- new MojoShellConnectionImpl(false /* external */);
+ new MojoShellConnectionImpl(is_external);
lazy_tls_ptr.Pointer()->Set(connection);
connection->shell_connection_.reset(
new mojo::ShellConnection(connection, std::move(request)));
+ if (is_external)
+ connection->WaitForShellIfNecessary();
+}
+
+// static
+void MojoShellConnection::SetFactoryForTest(Factory* factory) {
+ DCHECK(!lazy_tls_ptr.Pointer()->Get());
+ mojo_shell_connection_factory = factory;
}
// static
MojoShellConnectionImpl* MojoShellConnectionImpl::Get() {
+ // Assume that if a mojo_shell_connection_factory was set that it did not
+ // create a MojoShellConnectionImpl.
return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get());
}
@@ -70,7 +95,17 @@ void MojoShellConnectionImpl::BindToRequestFromCommandLine() {
DCHECK(!shell_connection_);
shell_connection_.reset(new mojo::ShellConnection(
this, mojo::shell::GetShellClientRequestFromCommandLine()));
+ WaitForShellIfNecessary();
+}
+MojoShellConnectionImpl::MojoShellConnectionImpl(bool external)
+ : external_(external) {}
+
+MojoShellConnectionImpl::~MojoShellConnectionImpl() {
+ STLDeleteElements(&listeners_);
+}
+
+void MojoShellConnectionImpl::WaitForShellIfNecessary() {
// TODO(rockot): Remove this. http://crbug.com/594852.
if (ShouldWaitForShell()) {
base::RunLoop wait_loop;
@@ -79,13 +114,6 @@ void MojoShellConnectionImpl::BindToRequestFromCommandLine() {
}
}
-MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) :
- external_(external) {}
-
-MojoShellConnectionImpl::~MojoShellConnectionImpl() {
- STLDeleteElements(&listeners_);
-}
-
void MojoShellConnectionImpl::Initialize(mojo::Connector* connector,
const mojo::Identity& identity,
uint32_t id) {
diff --git a/content/common/mojo/mojo_shell_connection_impl.h b/content/common/mojo/mojo_shell_connection_impl.h
index 478260d..52ce78e 100644
--- a/content/common/mojo/mojo_shell_connection_impl.h
+++ b/content/common/mojo/mojo_shell_connection_impl.h
@@ -23,14 +23,14 @@ bool IsRunningInMojoShell();
class MojoShellConnectionImpl : public MojoShellConnection,
public mojo::ShellClient {
public:
+ // Creates the MojoShellConnection using MojoShellConnection::Factory. Returns
+ // true if a factory was set and the connection was created, false otherwise.
+ static bool CreateUsingFactory();
+
// Creates an instance of this class and stuffs it in TLS on the calling
// thread. Retrieve it using MojoShellConnection::Get().
static void Create();
- // Like above but for initializing a connection to an embedded in-process
- // shell implementation. Binds to |request|.
- static void Create(mojo::shell::mojom::ShellClientRequest request);
-
// Will return null if no connection has been established (either because it
// hasn't happened yet or the application was not spawned from the external
// Mojo shell).
@@ -41,9 +41,13 @@ class MojoShellConnectionImpl : public MojoShellConnection,
void BindToRequestFromCommandLine();
private:
+ friend class MojoShellConnection;
+
explicit MojoShellConnectionImpl(bool external);
~MojoShellConnectionImpl() override;
+ void WaitForShellIfNecessary();
+
// mojo::ShellClient:
void Initialize(mojo::Connector* connector,
const mojo::Identity& identity,
@@ -57,7 +61,7 @@ class MojoShellConnectionImpl : public MojoShellConnection,
void AddListener(Listener* listener) override;
void RemoveListener(Listener* listener) override;
- bool external_;
+ const bool external_;
scoped_ptr<mojo::ShellConnection> shell_connection_;
std::vector<Listener*> listeners_;
diff --git a/content/public/DEPS b/content/public/DEPS
index 7358adb..d811be3 100644
--- a/content/public/DEPS
+++ b/content/public/DEPS
@@ -1,6 +1,8 @@
include_rules = [
"-content",
+ "+mojo/shell/public",
+
# This file does not belong in content/public as it should not be
# included directly by embedders of content/. It must however be
# available to code in content/public.
diff --git a/content/public/common/mojo_shell_connection.h b/content/public/common/mojo_shell_connection.h
index 50827a9..7077dce 100644
--- a/content/public/common/mojo_shell_connection.h
+++ b/content/public/common/mojo_shell_connection.h
@@ -5,7 +5,9 @@
#ifndef CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_
#define CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_
+#include "base/callback_forward.h"
#include "content/common/content_export.h"
+#include "mojo/shell/public/interfaces/shell_client.mojom.h"
namespace mojo {
class Connection;
@@ -32,6 +34,11 @@ class CONTENT_EXPORT MojoShellConnection {
virtual ~Listener() {}
};
+ using Factory = base::Closure;
+ // Sets the factory used to create the MojoShellConnection. This must be
+ // called before the MojoShellConnection has been created.
+ static void SetFactoryForTest(Factory* factory);
+
// Will return null if no connection has been established (either because it
// hasn't happened yet or the application was not spawned from the external
// Mojo shell.
@@ -41,6 +48,11 @@ class CONTENT_EXPORT MojoShellConnection {
// created on.
static void Destroy();
+ // Creates the appropriate MojoShellConnection from |request|. See
+ // UsingExternalShell() for details of |is_external|.
+ static void Create(mojo::shell::mojom::ShellClientRequest request,
+ bool is_external);
+
virtual mojo::Connector* GetConnector() = 0;
// Indicates whether the shell connection is to an external shell (true) or