1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/public/cpp/shell/application.h"
9 Application::Application(ScopedMessagePipeHandle shell_handle)
10 : internal::ServiceConnectorBase::Owner(shell_handle.Pass()) {
13 Application::Application(MojoHandle shell_handle)
14 : internal::ServiceConnectorBase::Owner(
15 mojo::MakeScopedHandle(MessagePipeHandle(shell_handle)).Pass()) {}
17 Application::~Application() {
18 for (ServiceConnectorList::iterator it = service_connectors_.begin();
19 it != service_connectors_.end(); ++it) {
24 void Application::AddServiceConnector(
25 internal::ServiceConnectorBase* service_connector) {
26 service_connectors_.push_back(service_connector);
27 set_service_connector_owner(service_connector, this);
30 void Application::RemoveServiceConnector(
31 internal::ServiceConnectorBase* service_connector) {
32 for (ServiceConnectorList::iterator it = service_connectors_.begin();
33 it != service_connectors_.end(); ++it) {
34 if (*it == service_connector) {
35 service_connectors_.erase(it);
36 delete service_connector;
40 if (service_connectors_.empty())
44 void Application::AcceptConnection(const mojo::String& url,
45 ScopedMessagePipeHandle client_handle) {
46 // TODO(davemoore): This method must be overridden by an Application subclass
47 // to dispatch to the right ServiceConnector. We need to figure out an
48 // approach to registration to make this better.
49 assert(1 == service_connectors_.size());
50 return service_connectors_.front()->AcceptConnection(url.To<std::string>(),
51 client_handle.Pass());