| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool accept = false; | 95 bool accept = false; |
| 96 for (auto& client : embedded_shell_clients_) | 96 for (auto& client : embedded_shell_clients_) |
| 97 accept |= client->AcceptConnection(connection); | 97 accept |= client->AcceptConnection(connection); |
| 98 | 98 |
| 99 // Reject all other connections to this application. | 99 // Reject all other connections to this application. |
| 100 return accept; | 100 return accept; |
| 101 } | 101 } |
| 102 | 102 |
| 103 shell::InterfaceRegistry* |
| 104 MojoShellConnectionImpl::GetInterfaceRegistryForConnection() { |
| 105 // TODO(beng): This is really horrible since obviously subject to issues |
| 106 // of ordering, but is no more horrible than this API is in general. |
| 107 shell::InterfaceRegistry* registry = nullptr; |
| 108 for (auto& client : embedded_shell_clients_) { |
| 109 registry = client->GetInterfaceRegistryForConnection(); |
| 110 if (registry) |
| 111 return registry; |
| 112 } |
| 113 return nullptr; |
| 114 } |
| 115 |
| 116 shell::InterfaceProvider* |
| 117 MojoShellConnectionImpl::GetInterfaceProviderForConnection() { |
| 118 // TODO(beng): This is really horrible since obviously subject to issues |
| 119 // of ordering, but is no more horrible than this API is in general. |
| 120 shell::InterfaceProvider* provider = nullptr; |
| 121 for (auto& client : embedded_shell_clients_) { |
| 122 provider = client->GetInterfaceProviderForConnection(); |
| 123 if (provider) |
| 124 return provider; |
| 125 } |
| 126 return nullptr; |
| 127 } |
| 128 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
| 104 // MojoShellConnectionImpl, | 130 // MojoShellConnectionImpl, |
| 105 // shell::InterfaceFactory<shell::mojom::ShellClientFactory> implementation: | 131 // shell::InterfaceFactory<shell::mojom::ShellClientFactory> implementation: |
| 106 | 132 |
| 107 void MojoShellConnectionImpl::Create( | 133 void MojoShellConnectionImpl::Create( |
| 108 shell::Connection* connection, | 134 shell::Connection* connection, |
| 109 shell::mojom::ShellClientFactoryRequest request) { | 135 shell::mojom::ShellClientFactoryRequest request) { |
| 110 factory_bindings_.AddBinding(this, std::move(request)); | 136 factory_bindings_.AddBinding(this, std::move(request)); |
| 111 } | 137 } |
| 112 | 138 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 138 return shell_connection_->identity(); | 164 return shell_connection_->identity(); |
| 139 } | 165 } |
| 140 | 166 |
| 141 void MojoShellConnectionImpl::SetConnectionLostClosure( | 167 void MojoShellConnectionImpl::SetConnectionLostClosure( |
| 142 const base::Closure& closure) { | 168 const base::Closure& closure) { |
| 143 shell_connection_->SetConnectionLostClosure(closure); | 169 shell_connection_->SetConnectionLostClosure(closure); |
| 144 } | 170 } |
| 145 | 171 |
| 146 void MojoShellConnectionImpl::AddEmbeddedShellClient( | 172 void MojoShellConnectionImpl::AddEmbeddedShellClient( |
| 147 std::unique_ptr<shell::ShellClient> shell_client) { | 173 std::unique_ptr<shell::ShellClient> shell_client) { |
| 148 embedded_shell_clients_.push_back(std::move(shell_client)); | 174 embedded_shell_clients_.push_back(shell_client.get()); |
| 175 owned_shell_clients_.push_back(std::move(shell_client)); |
| 176 } |
| 177 |
| 178 void MojoShellConnectionImpl::AddEmbeddedShellClient( |
| 179 shell::ShellClient* shell_client) { |
| 180 embedded_shell_clients_.push_back(shell_client); |
| 149 } | 181 } |
| 150 | 182 |
| 151 void MojoShellConnectionImpl::AddEmbeddedService( | 183 void MojoShellConnectionImpl::AddEmbeddedService( |
| 152 const std::string& name, | 184 const std::string& name, |
| 153 const MojoApplicationInfo& info) { | 185 const MojoApplicationInfo& info) { |
| 154 std::unique_ptr<EmbeddedApplicationRunner> app( | 186 std::unique_ptr<EmbeddedApplicationRunner> app( |
| 155 new EmbeddedApplicationRunner(name, info)); | 187 new EmbeddedApplicationRunner(name, info)); |
| 156 AddShellClientRequestHandler( | 188 AddShellClientRequestHandler( |
| 157 name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, | 189 name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, |
| 158 base::Unretained(app.get()))); | 190 base::Unretained(app.get()))); |
| 159 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); | 191 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); |
| 160 DCHECK(result.second); | 192 DCHECK(result.second); |
| 161 } | 193 } |
| 162 | 194 |
| 163 void MojoShellConnectionImpl::AddShellClientRequestHandler( | 195 void MojoShellConnectionImpl::AddShellClientRequestHandler( |
| 164 const std::string& name, | 196 const std::string& name, |
| 165 const ShellClientRequestHandler& handler) { | 197 const ShellClientRequestHandler& handler) { |
| 166 auto result = request_handlers_.insert(std::make_pair(name, handler)); | 198 auto result = request_handlers_.insert(std::make_pair(name, handler)); |
| 167 DCHECK(result.second); | 199 DCHECK(result.second); |
| 168 } | 200 } |
| 169 | 201 |
| 170 } // namespace content | 202 } // namespace content |
| OLD | NEW |