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/shell/application.h"
9 Application::Application(ScopedShellHandle shell_handle)
10 : internal::ServiceFactoryBase::Owner(shell_handle.Pass()) {
13 Application::Application(MojoHandle shell_handle)
14 : internal::ServiceFactoryBase::Owner(
15 mojo::MakeScopedHandle(ShellHandle(shell_handle)).Pass()) {}
17 Application::~Application() {
18 for (ServiceFactoryList::iterator it = service_factories_.begin();
19 it != service_factories_.end(); ++it) {
24 void Application::AddServiceFactory(
25 internal::ServiceFactoryBase* service_factory) {
26 service_factories_.push_back(service_factory);
27 set_service_factory_owner(service_factory, this);
30 void Application::RemoveServiceFactory(
31 internal::ServiceFactoryBase* service_factory) {
32 for (ServiceFactoryList::iterator it = service_factories_.begin();
33 it != service_factories_.end(); ++it) {
34 if (*it == service_factory) {
35 service_factories_.erase(it);
36 delete service_factory;
40 if (service_factories_.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 ServiceFactory. We need to figure out an approach
48 // to registration to make this better.
49 assert(1 == service_factories_.size());
50 return service_factories_.front()->AcceptConnection(url.To<std::string>(),
51 client_handle.Pass());