OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "mojo/public/cpp/application/application.h" | 5 #include "mojo/public/cpp/application/application.h" |
6 | 6 |
7 namespace mojo { | 7 namespace mojo { |
8 | 8 |
9 Application::Application() {} | 9 Application::Application() : service_registry_(this) {} |
10 | 10 |
11 Application::Application(ScopedMessagePipeHandle service_provider_handle) | 11 Application::Application(ScopedMessagePipeHandle service_provider_handle) |
12 : internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) { | 12 : service_registry_(this, service_provider_handle.Pass()) {} |
13 } | |
14 | 13 |
15 Application::Application(MojoHandle service_provider_handle) | 14 Application::Application(MojoHandle service_provider_handle) |
16 : internal::ServiceConnectorBase::Owner( | 15 : service_registry_( |
| 16 this, |
17 mojo::MakeScopedHandle( | 17 mojo::MakeScopedHandle( |
18 MessagePipeHandle(service_provider_handle)).Pass()) {} | 18 MessagePipeHandle(service_provider_handle)).Pass()) {} |
19 | 19 |
20 Application::~Application() { | 20 Application::~Application() {} |
21 for (NameToServiceConnectorMap::iterator i = | 21 |
22 name_to_service_connector_.begin(); | 22 bool Application::AllowIncomingConnection(const mojo::String& service_name, |
23 i != name_to_service_connector_.end(); ++i) { | 23 const mojo::String& requestor_url) { |
24 delete i->second; | 24 return true; |
25 } | 25 } |
26 name_to_service_connector_.clear(); | 26 |
| 27 void Application::BindServiceProvider( |
| 28 ScopedMessagePipeHandle service_provider_handle) { |
| 29 service_registry_.BindRemoteServiceProvider(service_provider_handle.Pass()); |
27 } | 30 } |
28 | 31 |
29 void Application::Initialize() {} | 32 void Application::Initialize() {} |
30 | 33 |
31 void Application::AddServiceConnector( | |
32 internal::ServiceConnectorBase* service_connector) { | |
33 name_to_service_connector_[service_connector->name()] = service_connector; | |
34 set_service_connector_owner(service_connector, this); | |
35 } | |
36 | |
37 void Application::RemoveServiceConnector( | |
38 internal::ServiceConnectorBase* service_connector) { | |
39 NameToServiceConnectorMap::iterator it = | |
40 name_to_service_connector_.find(service_connector->name()); | |
41 assert(it != name_to_service_connector_.end()); | |
42 delete it->second; | |
43 name_to_service_connector_.erase(it); | |
44 if (name_to_service_connector_.empty()) | |
45 service_provider_.reset(); | |
46 } | |
47 | |
48 void Application::BindServiceProvider( | |
49 ScopedMessagePipeHandle service_provider_handle) { | |
50 service_provider_.Bind(service_provider_handle.Pass()); | |
51 service_provider_.set_client(this); | |
52 } | |
53 | |
54 void Application::ConnectToService(const mojo::String& service_url, | |
55 const mojo::String& service_name, | |
56 ScopedMessagePipeHandle client_handle, | |
57 const mojo::String& requestor_url) { | |
58 internal::ServiceConnectorBase* service_connector = | |
59 name_to_service_connector_[service_name]; | |
60 assert(service_connector); | |
61 // requestor_url is ignored because the service_connector stores the url | |
62 // of the requestor safely. | |
63 return service_connector->ConnectToService( | |
64 service_url, service_name, client_handle.Pass()); | |
65 } | |
66 | |
67 } // namespace mojo | 34 } // namespace mojo |
OLD | NEW |