| 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 | |
| 129 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 130 // MojoShellConnectionImpl, | 104 // MojoShellConnectionImpl, |
| 131 // shell::InterfaceFactory<shell::mojom::ShellClientFactory> implementation: | 105 // shell::InterfaceFactory<shell::mojom::ShellClientFactory> implementation: |
| 132 | 106 |
| 133 void MojoShellConnectionImpl::Create( | 107 void MojoShellConnectionImpl::Create( |
| 134 shell::Connection* connection, | 108 shell::Connection* connection, |
| 135 shell::mojom::ShellClientFactoryRequest request) { | 109 shell::mojom::ShellClientFactoryRequest request) { |
| 136 factory_bindings_.AddBinding(this, std::move(request)); | 110 factory_bindings_.AddBinding(this, std::move(request)); |
| 137 } | 111 } |
| 138 | 112 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 164 return shell_connection_->identity(); | 138 return shell_connection_->identity(); |
| 165 } | 139 } |
| 166 | 140 |
| 167 void MojoShellConnectionImpl::SetConnectionLostClosure( | 141 void MojoShellConnectionImpl::SetConnectionLostClosure( |
| 168 const base::Closure& closure) { | 142 const base::Closure& closure) { |
| 169 shell_connection_->SetConnectionLostClosure(closure); | 143 shell_connection_->SetConnectionLostClosure(closure); |
| 170 } | 144 } |
| 171 | 145 |
| 172 void MojoShellConnectionImpl::AddEmbeddedShellClient( | 146 void MojoShellConnectionImpl::AddEmbeddedShellClient( |
| 173 std::unique_ptr<shell::ShellClient> shell_client) { | 147 std::unique_ptr<shell::ShellClient> shell_client) { |
| 174 embedded_shell_clients_.push_back(shell_client.get()); | 148 embedded_shell_clients_.push_back(std::move(shell_client)); |
| 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); | |
| 181 } | 149 } |
| 182 | 150 |
| 183 void MojoShellConnectionImpl::AddEmbeddedService( | 151 void MojoShellConnectionImpl::AddEmbeddedService( |
| 184 const std::string& name, | 152 const std::string& name, |
| 185 const MojoApplicationInfo& info) { | 153 const MojoApplicationInfo& info) { |
| 186 std::unique_ptr<EmbeddedApplicationRunner> app( | 154 std::unique_ptr<EmbeddedApplicationRunner> app( |
| 187 new EmbeddedApplicationRunner(name, info)); | 155 new EmbeddedApplicationRunner(name, info)); |
| 188 AddShellClientRequestHandler( | 156 AddShellClientRequestHandler( |
| 189 name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, | 157 name, base::Bind(&EmbeddedApplicationRunner::BindShellClientRequest, |
| 190 base::Unretained(app.get()))); | 158 base::Unretained(app.get()))); |
| 191 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); | 159 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); |
| 192 DCHECK(result.second); | 160 DCHECK(result.second); |
| 193 } | 161 } |
| 194 | 162 |
| 195 void MojoShellConnectionImpl::AddShellClientRequestHandler( | 163 void MojoShellConnectionImpl::AddShellClientRequestHandler( |
| 196 const std::string& name, | 164 const std::string& name, |
| 197 const ShellClientRequestHandler& handler) { | 165 const ShellClientRequestHandler& handler) { |
| 198 auto result = request_handlers_.insert(std::make_pair(name, handler)); | 166 auto result = request_handlers_.insert(std::make_pair(name, handler)); |
| 199 DCHECK(result.second); | 167 DCHECK(result.second); |
| 200 } | 168 } |
| 201 | 169 |
| 202 } // namespace content | 170 } // namespace content |
| OLD | NEW |