Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: content/common/mojo/mojo_shell_connection_impl.cc

Issue 1442893002: Move Shell connection to content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i2
Patch Set: . Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/content_common.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/mojo/mojo_shell_connection_impl.cc
diff --git a/content/common/mojo/mojo_shell_connection_impl.cc b/content/common/mojo/mojo_shell_connection_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5125df35de953d4f6e615a3569d5035e4ca5ca6a
--- /dev/null
+++ b/content/common/mojo/mojo_shell_connection_impl.cc
@@ -0,0 +1,95 @@
+// 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/common/mojo/mojo_shell_connection_impl.h"
+
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#include "base/threading/thread_local.h"
+#include "mojo/application/public/cpp/application_delegate.h"
+#include "mojo/application/public/cpp/application_impl.h"
+#include "mojo/converters/network/network_type_converters.h"
+#include "mojo/runner/child/runner_connection.h"
+
+namespace content {
+namespace {
+using MojoShellConnectionPtr =
+ base::ThreadLocalPointer<MojoShellConnectionImpl>;
+
+// Env is thread local so that aura may be used on multiple threads.
+base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+bool IsRunningInMojoShell() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ "mojo-platform-channel-handle");
+}
+
+// static
+void MojoShellConnectionImpl::Create() {
+ DCHECK(IsRunningInMojoShell());
+ DCHECK(!lazy_tls_ptr.Pointer()->Get());
+ MojoShellConnectionImpl* connection = new MojoShellConnectionImpl;
+ lazy_tls_ptr.Pointer()->Set(connection);
+ connection->WaitForShell();
+}
+
+MojoShellConnectionImpl::MojoShellConnectionImpl() : initialized_(false) {}
+MojoShellConnectionImpl::~MojoShellConnectionImpl() {}
+
+void MojoShellConnectionImpl::WaitForShell() {
+ mojo::InterfaceRequest<mojo::Application> application_request;
+ runner_connection_.reset(
+ mojo::runner::RunnerConnection::ConnectToRunner(&application_request));
+ application_impl_.reset(new mojo::ApplicationImpl(
+ this, application_request.Pass()));
+ application_impl_->WaitForInitialize();
+}
+
+void MojoShellConnectionImpl::Initialize(mojo::ApplicationImpl* application) {
+ initialized_ = true;
+}
+
+bool MojoShellConnectionImpl::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ bool found = false;
+ for (auto listener : listeners_)
+ found |= listener->ConfigureIncomingConnection(connection);
+ return found;
+}
+
+mojo::ApplicationImpl* MojoShellConnectionImpl::GetApplication() {
+ DCHECK(initialized_);
+ return application_impl_.get();
+}
+
+void MojoShellConnectionImpl::AddListener(Listener* listener) {
+ DCHECK(std::find(listeners_.begin(), listeners_.end(), listener) ==
+ listeners_.end());
+ listeners_.push_back(listener);
+}
+
+void MojoShellConnectionImpl::RemoveListener(Listener* listener) {
+ auto it = std::find(listeners_.begin(), listeners_.end(), listener);
+ DCHECK(it != listeners_.end());
+ listeners_.erase(it);
+}
+
+// static
+MojoShellConnection* MojoShellConnection::Get() {
+ return lazy_tls_ptr.Pointer()->Get();
+}
+
+// static
+void MojoShellConnection::Destroy() {
+ // This joins the shell controller thread.
+ delete Get();
+ lazy_tls_ptr.Pointer()->Set(nullptr);
+}
+
+MojoShellConnection::~MojoShellConnection() {}
+
+} // namespace content
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698