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_impl.h" | 5 #include "mojo/public/cpp/application/application_impl.h" |
6 | 6 |
7 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
8 #include "mojo/public/cpp/application/lib/service_registry.h" | 8 #include "mojo/public/cpp/application/lib/service_registry.h" |
9 #include "mojo/public/cpp/bindings/interface_ptr.h" | 9 #include "mojo/public/cpp/bindings/interface_ptr.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 | 12 |
| 13 ApplicationImpl::ShellPtrWatcher::ShellPtrWatcher(ApplicationImpl* impl) |
| 14 : impl_(impl) {} |
| 15 |
| 16 ApplicationImpl::ShellPtrWatcher::~ShellPtrWatcher() {} |
| 17 |
| 18 void ApplicationImpl::ShellPtrWatcher::OnConnectionError() { |
| 19 impl_->OnShellError(); |
| 20 } |
| 21 |
13 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate) | 22 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate) |
14 : delegate_(delegate) {} | 23 : delegate_(delegate), shell_watch_(this) {} |
15 | 24 |
16 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 25 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
17 ScopedMessagePipeHandle shell_handle) | 26 ScopedMessagePipeHandle shell_handle) |
18 : delegate_(delegate) { | 27 : delegate_(delegate), shell_watch_(this) { |
19 BindShell(shell_handle.Pass()); | 28 BindShell(shell_handle.Pass()); |
20 } | 29 } |
21 | 30 |
22 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 31 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
23 MojoHandle shell_handle) | 32 MojoHandle shell_handle) |
24 : delegate_(delegate) { | 33 : delegate_(delegate), shell_watch_(this) { |
25 BindShell(shell_handle); | 34 BindShell(shell_handle); |
26 } | 35 } |
27 | 36 |
28 ApplicationImpl::~ApplicationImpl() { | 37 void ApplicationImpl::ClearConnections() { |
29 for (ServiceRegistryList::iterator i(incoming_service_registries_.begin()); | 38 for (ServiceRegistryList::iterator i(incoming_service_registries_.begin()); |
30 i != incoming_service_registries_.end(); ++i) | 39 i != incoming_service_registries_.end(); ++i) |
31 delete *i; | 40 delete *i; |
32 for (ServiceRegistryList::iterator i(outgoing_service_registries_.begin()); | 41 for (ServiceRegistryList::iterator i(outgoing_service_registries_.begin()); |
33 i != outgoing_service_registries_.end(); ++i) | 42 i != outgoing_service_registries_.end(); ++i) |
34 delete *i; | 43 delete *i; |
| 44 incoming_service_registries_.clear(); |
| 45 outgoing_service_registries_.clear(); |
| 46 } |
| 47 |
| 48 ApplicationImpl::~ApplicationImpl() { |
| 49 ClearConnections(); |
35 } | 50 } |
36 | 51 |
37 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 52 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
38 const String& application_url) { | 53 const String& application_url) { |
39 ServiceProviderPtr out_service_provider; | 54 ServiceProviderPtr out_service_provider; |
40 shell_->ConnectToApplication(application_url, Get(&out_service_provider)); | 55 shell_->ConnectToApplication(application_url, Get(&out_service_provider)); |
41 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 56 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
42 this, | 57 this, |
43 application_url, | 58 application_url, |
44 out_service_provider.Pass()); | 59 out_service_provider.Pass()); |
45 if (!delegate_->ConfigureOutgoingConnection(registry)) { | 60 if (!delegate_->ConfigureOutgoingConnection(registry)) { |
46 delete registry; | 61 delete registry; |
47 return NULL; | 62 return NULL; |
48 } | 63 } |
49 outgoing_service_registries_.push_back(registry); | 64 outgoing_service_registries_.push_back(registry); |
50 return registry; | 65 return registry; |
51 } | 66 } |
52 | 67 |
53 void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) { | 68 void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) { |
54 shell_.Bind(shell_handle.Pass()); | 69 shell_.Bind(shell_handle.Pass()); |
55 shell_.set_client(this); | 70 shell_.set_client(this); |
| 71 shell_.set_error_handler(&shell_watch_); |
56 delegate_->Initialize(this); | 72 delegate_->Initialize(this); |
57 } | 73 } |
58 | 74 |
59 void ApplicationImpl::BindShell(MojoHandle shell_handle) { | 75 void ApplicationImpl::BindShell(MojoHandle shell_handle) { |
60 BindShell(mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | 76 BindShell(mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); |
61 } | 77 } |
62 | 78 |
63 void ApplicationImpl::AcceptConnection(const String& requestor_url, | 79 void ApplicationImpl::AcceptConnection(const String& requestor_url, |
64 ServiceProviderPtr service_provider) { | 80 ServiceProviderPtr service_provider) { |
65 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 81 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
66 this, requestor_url, service_provider.Pass()); | 82 this, requestor_url, service_provider.Pass()); |
67 if (!delegate_->ConfigureIncomingConnection(registry)) { | 83 if (!delegate_->ConfigureIncomingConnection(registry)) { |
68 delete registry; | 84 delete registry; |
69 return; | 85 return; |
70 } | 86 } |
71 incoming_service_registries_.push_back(registry); | 87 incoming_service_registries_.push_back(registry); |
72 } | 88 } |
73 | 89 |
74 } // namespace mojo | 90 } // namespace mojo |
OLD | NEW |