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 #include "mojo/public/cpp/environment/logging.h" | 10 #include "mojo/public/cpp/environment/logging.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 delete *i; | 47 delete *i; |
48 incoming_service_registries_.clear(); | 48 incoming_service_registries_.clear(); |
49 outgoing_service_registries_.clear(); | 49 outgoing_service_registries_.clear(); |
50 } | 50 } |
51 | 51 |
52 ApplicationImpl::~ApplicationImpl() { | 52 ApplicationImpl::~ApplicationImpl() { |
53 ClearConnections(); | 53 ClearConnections(); |
54 delete shell_watch_; | 54 delete shell_watch_; |
55 } | 55 } |
56 | 56 |
57 void ApplicationImpl::Initialize(Array<String> args) { | |
58 MOJO_CHECK(!initialized_); | |
59 initialized_ = true; | |
60 args_ = args.To<std::vector<std::string>>(); | |
61 delegate_->Initialize(this); | |
62 } | |
63 | |
64 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 57 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
65 const String& application_url) { | 58 const String& application_url) { |
66 MOJO_CHECK(initialized_); | 59 MOJO_CHECK(initialized_); |
67 ServiceProviderPtr out_service_provider; | 60 ServiceProviderPtr out_service_provider; |
68 shell_->ConnectToApplication(application_url, | 61 shell_->ConnectToApplication(application_url, |
69 GetProxy(&out_service_provider)); | 62 GetProxy(&out_service_provider)); |
70 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 63 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
71 this, application_url, out_service_provider.Pass()); | 64 this, application_url, out_service_provider.Pass()); |
72 if (!delegate_->ConfigureOutgoingConnection(registry)) { | 65 if (!delegate_->ConfigureOutgoingConnection(registry)) { |
73 delete registry; | 66 delete registry; |
74 return nullptr; | 67 return nullptr; |
75 } | 68 } |
76 outgoing_service_registries_.push_back(registry); | 69 outgoing_service_registries_.push_back(registry); |
77 return registry; | 70 return registry; |
78 } | 71 } |
79 | 72 |
80 bool ApplicationImpl::WaitForInitialize() { | 73 bool ApplicationImpl::WaitForInitialize() { |
81 MOJO_CHECK(!initialized_); | 74 MOJO_CHECK(!initialized_); |
82 bool result = shell_.WaitForIncomingMethodCall(); | 75 bool result = shell_.WaitForIncomingMethodCall(); |
83 MOJO_CHECK(initialized_ || !result); | 76 MOJO_CHECK(initialized_ || !result); |
84 return result; | 77 return result; |
85 } | 78 } |
86 | 79 |
| 80 ScopedMessagePipeHandle ApplicationImpl::UnbindShell() { |
| 81 return shell_.PassMessagePipe(); |
| 82 } |
| 83 |
| 84 void ApplicationImpl::Initialize(Array<String> args) { |
| 85 MOJO_CHECK(!initialized_); |
| 86 initialized_ = true; |
| 87 args_ = args.To<std::vector<std::string>>(); |
| 88 delegate_->Initialize(this); |
| 89 } |
| 90 |
87 void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) { | 91 void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) { |
88 shell_watch_ = new ShellPtrWatcher(this); | 92 shell_watch_ = new ShellPtrWatcher(this); |
89 shell_.Bind(shell_handle.Pass()); | 93 shell_.Bind(shell_handle.Pass()); |
90 shell_.set_client(this); | 94 shell_.set_client(this); |
91 shell_.set_error_handler(shell_watch_); | 95 shell_.set_error_handler(shell_watch_); |
92 } | 96 } |
93 | 97 |
94 void ApplicationImpl::AcceptConnection(const String& requestor_url, | 98 void ApplicationImpl::AcceptConnection(const String& requestor_url, |
95 ServiceProviderPtr service_provider) { | 99 ServiceProviderPtr service_provider) { |
96 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 100 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
97 this, requestor_url, service_provider.Pass()); | 101 this, requestor_url, service_provider.Pass()); |
98 if (!delegate_->ConfigureIncomingConnection(registry)) { | 102 if (!delegate_->ConfigureIncomingConnection(registry)) { |
99 delete registry; | 103 delete registry; |
100 return; | 104 return; |
101 } | 105 } |
102 incoming_service_registries_.push_back(registry); | 106 incoming_service_registries_.push_back(registry); |
103 } | 107 } |
104 | 108 |
105 } // namespace mojo | 109 } // namespace mojo |
OLD | NEW |