| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/mojo/mojo_shell_connection_impl.h" | 5 #include "content/common/mojo/mojo_shell_connection_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 13 #include "mojo/converters/network/network_type_converters.h" | 13 #include "mojo/converters/network/network_type_converters.h" |
| 14 #include "mojo/edk/embedder/embedder.h" | 14 #include "mojo/edk/embedder/embedder.h" |
| 15 #include "mojo/shell/public/cpp/shell_client.h" | 15 #include "mojo/shell/public/cpp/shell_client.h" |
| 16 #include "mojo/shell/public/cpp/shell_connection.h" | 16 #include "mojo/shell/public/cpp/shell_connection.h" |
| 17 #include "mojo/shell/runner/child/runner_connection.h" | 17 #include "mojo/shell/runner/common/client_util.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 using MojoShellConnectionPtr = | 22 using MojoShellConnectionPtr = |
| 23 base::ThreadLocalPointer<MojoShellConnectionImpl>; | 23 base::ThreadLocalPointer<MojoShellConnectionImpl>; |
| 24 | 24 |
| 25 // Env is thread local so that aura may be used on multiple threads. | 25 // Env is thread local so that aura may be used on multiple threads. |
| 26 base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr = | 26 base::LazyInstance<MojoShellConnectionPtr>::Leaky lazy_tls_ptr = |
| 27 LAZY_INSTANCE_INITIALIZER; | 27 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 new mojo::ShellConnection(connection, std::move(request))); | 52 new mojo::ShellConnection(connection, std::move(request))); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() { | 56 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() { |
| 57 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); | 57 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void MojoShellConnectionImpl::BindToRequestFromCommandLine() { | 60 void MojoShellConnectionImpl::BindToRequestFromCommandLine() { |
| 61 DCHECK(!shell_connection_); | 61 DCHECK(!shell_connection_); |
| 62 | 62 shell_connection_.reset(new mojo::ShellConnection( |
| 63 shell_connection_.reset(new mojo::ShellConnection(this)); | 63 this, mojo::shell::GetShellClientRequestFromCommandLine())); |
| 64 runner_connection_ = | |
| 65 mojo::shell::RunnerConnection::Create(shell_connection_.get(), | |
| 66 false /* exit_on_error */); | |
| 67 if (!runner_connection_) { | |
| 68 delete this; | |
| 69 lazy_tls_ptr.Pointer()->Set(nullptr); | |
| 70 } | |
| 71 } | 64 } |
| 72 | 65 |
| 73 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) : | 66 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) : |
| 74 external_(external) {} | 67 external_(external) {} |
| 75 | 68 |
| 76 MojoShellConnectionImpl::~MojoShellConnectionImpl() { | 69 MojoShellConnectionImpl::~MojoShellConnectionImpl() { |
| 77 STLDeleteElements(&listeners_); | 70 STLDeleteElements(&listeners_); |
| 78 } | 71 } |
| 79 | 72 |
| 80 void MojoShellConnectionImpl::Initialize(mojo::Connector* connector, | 73 void MojoShellConnectionImpl::Initialize(mojo::Connector* connector, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // static | 111 // static |
| 119 void MojoShellConnection::Destroy() { | 112 void MojoShellConnection::Destroy() { |
| 120 // This joins the shell controller thread. | 113 // This joins the shell controller thread. |
| 121 delete Get(); | 114 delete Get(); |
| 122 lazy_tls_ptr.Pointer()->Set(nullptr); | 115 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 123 } | 116 } |
| 124 | 117 |
| 125 MojoShellConnection::~MojoShellConnection() {} | 118 MojoShellConnection::~MojoShellConnection() {} |
| 126 | 119 |
| 127 } // namespace content | 120 } // namespace content |
| OLD | NEW |