| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 // static | 59 // static |
| 60 void MojoShellConnectionImpl::Create() { | 60 void MojoShellConnectionImpl::Create() { |
| 61 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 61 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
| 62 MojoShellConnectionImpl* connection = | 62 MojoShellConnectionImpl* connection = |
| 63 new MojoShellConnectionImpl(true /* external */); | 63 new MojoShellConnectionImpl(true /* external */); |
| 64 lazy_tls_ptr.Pointer()->Set(connection); | 64 lazy_tls_ptr.Pointer()->Set(connection); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // static | 67 // static |
| 68 void MojoShellConnection::Create(mojo::shell::mojom::ShellClientRequest request, | 68 void MojoShellConnection::Create(shell::mojom::ShellClientRequest request, |
| 69 bool is_external) { | 69 bool is_external) { |
| 70 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 70 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
| 71 MojoShellConnectionImpl* connection = | 71 MojoShellConnectionImpl* connection = |
| 72 new MojoShellConnectionImpl(is_external); | 72 new MojoShellConnectionImpl(is_external); |
| 73 lazy_tls_ptr.Pointer()->Set(connection); | 73 lazy_tls_ptr.Pointer()->Set(connection); |
| 74 connection->shell_connection_.reset( | 74 connection->shell_connection_.reset( |
| 75 new mojo::ShellConnection(connection, std::move(request))); | 75 new shell::ShellConnection(connection, std::move(request))); |
| 76 if (is_external) | 76 if (is_external) |
| 77 connection->WaitForShellIfNecessary(); | 77 connection->WaitForShellIfNecessary(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // static | 80 // static |
| 81 void MojoShellConnection::SetFactoryForTest(Factory* factory) { | 81 void MojoShellConnection::SetFactoryForTest(Factory* factory) { |
| 82 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 82 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
| 83 mojo_shell_connection_factory = factory; | 83 mojo_shell_connection_factory = factory; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() { | 87 MojoShellConnectionImpl* MojoShellConnectionImpl::Get() { |
| 88 // Assume that if a mojo_shell_connection_factory was set that it did not | 88 // Assume that if a mojo_shell_connection_factory was set that it did not |
| 89 // create a MojoShellConnectionImpl. | 89 // create a MojoShellConnectionImpl. |
| 90 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); | 90 return static_cast<MojoShellConnectionImpl*>(MojoShellConnection::Get()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void MojoShellConnectionImpl::BindToRequestFromCommandLine() { | 93 void MojoShellConnectionImpl::BindToRequestFromCommandLine() { |
| 94 DCHECK(!shell_connection_); | 94 DCHECK(!shell_connection_); |
| 95 shell_connection_.reset(new mojo::ShellConnection( | 95 shell_connection_.reset(new shell::ShellConnection( |
| 96 this, mojo::shell::GetShellClientRequestFromCommandLine())); | 96 this, shell::GetShellClientRequestFromCommandLine())); |
| 97 WaitForShellIfNecessary(); | 97 WaitForShellIfNecessary(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) | 100 MojoShellConnectionImpl::MojoShellConnectionImpl(bool external) |
| 101 : external_(external) {} | 101 : external_(external) {} |
| 102 | 102 |
| 103 MojoShellConnectionImpl::~MojoShellConnectionImpl() { | 103 MojoShellConnectionImpl::~MojoShellConnectionImpl() { |
| 104 STLDeleteElements(&listeners_); | 104 STLDeleteElements(&listeners_); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void MojoShellConnectionImpl::WaitForShellIfNecessary() { | 107 void MojoShellConnectionImpl::WaitForShellIfNecessary() { |
| 108 // TODO(rockot): Remove this. http://crbug.com/594852. | 108 // TODO(rockot): Remove this. http://crbug.com/594852. |
| 109 if (ShouldWaitForShell()) { | 109 if (ShouldWaitForShell()) { |
| 110 base::RunLoop wait_loop; | 110 base::RunLoop wait_loop; |
| 111 shell_connection_->set_initialize_handler(wait_loop.QuitClosure()); | 111 shell_connection_->set_initialize_handler(wait_loop.QuitClosure()); |
| 112 wait_loop.Run(); | 112 wait_loop.Run(); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 void MojoShellConnectionImpl::Initialize(mojo::Connector* connector, | 116 void MojoShellConnectionImpl::Initialize(shell::Connector* connector, |
| 117 const mojo::Identity& identity, | 117 const shell::Identity& identity, |
| 118 uint32_t id) { | 118 uint32_t id) {} |
| 119 } | |
| 120 | 119 |
| 121 bool MojoShellConnectionImpl::AcceptConnection(mojo::Connection* connection) { | 120 bool MojoShellConnectionImpl::AcceptConnection(shell::Connection* connection) { |
| 122 bool found = false; | 121 bool found = false; |
| 123 for (auto listener : listeners_) | 122 for (auto listener : listeners_) |
| 124 found |= listener->AcceptConnection(connection); | 123 found |= listener->AcceptConnection(connection); |
| 125 return found; | 124 return found; |
| 126 } | 125 } |
| 127 | 126 |
| 128 mojo::Connector* MojoShellConnectionImpl::GetConnector() { | 127 shell::Connector* MojoShellConnectionImpl::GetConnector() { |
| 129 DCHECK(shell_connection_); | 128 DCHECK(shell_connection_); |
| 130 return shell_connection_->connector(); | 129 return shell_connection_->connector(); |
| 131 } | 130 } |
| 132 | 131 |
| 133 bool MojoShellConnectionImpl::UsingExternalShell() const { | 132 bool MojoShellConnectionImpl::UsingExternalShell() const { |
| 134 return external_; | 133 return external_; |
| 135 } | 134 } |
| 136 | 135 |
| 137 void MojoShellConnectionImpl::SetConnectionLostClosure( | 136 void MojoShellConnectionImpl::SetConnectionLostClosure( |
| 138 const base::Closure& closure) { | 137 const base::Closure& closure) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 159 // static | 158 // static |
| 160 void MojoShellConnection::Destroy() { | 159 void MojoShellConnection::Destroy() { |
| 161 // This joins the shell controller thread. | 160 // This joins the shell controller thread. |
| 162 delete Get(); | 161 delete Get(); |
| 163 lazy_tls_ptr.Pointer()->Set(nullptr); | 162 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 164 } | 163 } |
| 165 | 164 |
| 166 MojoShellConnection::~MojoShellConnection() {} | 165 MojoShellConnection::~MojoShellConnection() {} |
| 167 | 166 |
| 168 } // namespace content | 167 } // namespace content |
| OLD | NEW |