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 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 impl_->OnShellError(); | 21 impl_->OnShellError(); |
22 } | 22 } |
23 | 23 |
24 private: | 24 private: |
25 ApplicationImpl* impl_; | 25 ApplicationImpl* impl_; |
26 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellPtrWatcher); | 26 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellPtrWatcher); |
27 }; | 27 }; |
28 | 28 |
29 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 29 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
30 ScopedMessagePipeHandle shell_handle) | 30 ScopedMessagePipeHandle shell_handle) |
31 : delegate_(delegate), shell_watch_(NULL) { | 31 : initialized_(false), delegate_(delegate), shell_watch_(NULL) { |
32 BindShell(shell_handle.Pass()); | 32 BindShell(shell_handle.Pass()); |
33 } | 33 } |
34 | 34 |
35 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 35 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
36 MojoHandle shell_handle) | 36 MojoHandle shell_handle) |
37 : delegate_(delegate), shell_watch_(NULL) { | 37 : initialized_(false), delegate_(delegate), shell_watch_(NULL) { |
38 BindShell(MakeScopedHandle(MessagePipeHandle(shell_handle))); | 38 BindShell(MakeScopedHandle(MessagePipeHandle(shell_handle))); |
39 } | 39 } |
40 | 40 |
41 void ApplicationImpl::ClearConnections() { | 41 void ApplicationImpl::ClearConnections() { |
42 for (ServiceRegistryList::iterator i(incoming_service_registries_.begin()); | 42 for (ServiceRegistryList::iterator i(incoming_service_registries_.begin()); |
43 i != incoming_service_registries_.end(); ++i) | 43 i != incoming_service_registries_.end(); ++i) |
44 delete *i; | 44 delete *i; |
45 for (ServiceRegistryList::iterator i(outgoing_service_registries_.begin()); | 45 for (ServiceRegistryList::iterator i(outgoing_service_registries_.begin()); |
46 i != outgoing_service_registries_.end(); ++i) | 46 i != outgoing_service_registries_.end(); ++i) |
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 assert(!initialized_); | |
viettrungluu
2014/09/15 17:26:19
You can actually use mojo/public/cpp/environment/l
DaveMoore
2014/09/15 22:35:08
Done.
| |
59 initialized_ = true; | |
60 args_ = args.Pass(); | |
61 delegate_->Initialize(this); | |
62 } | |
63 | |
57 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 64 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
58 const String& application_url) { | 65 const String& application_url) { |
66 assert(initialized_); | |
viettrungluu
2014/09/15 17:26:19
"
DaveMoore
2014/09/15 22:35:08
Done.
| |
59 ServiceProviderPtr out_service_provider; | 67 ServiceProviderPtr out_service_provider; |
60 shell_->ConnectToApplication(application_url, Get(&out_service_provider)); | 68 shell_->ConnectToApplication(application_url, Get(&out_service_provider)); |
61 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 69 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
62 this, | 70 this, |
63 application_url, | 71 application_url, |
64 out_service_provider.Pass()); | 72 out_service_provider.Pass()); |
65 if (!delegate_->ConfigureOutgoingConnection(registry)) { | 73 if (!delegate_->ConfigureOutgoingConnection(registry)) { |
66 delete registry; | 74 delete registry; |
67 return NULL; | 75 return NULL; |
68 } | 76 } |
69 outgoing_service_registries_.push_back(registry); | 77 outgoing_service_registries_.push_back(registry); |
70 return registry; | 78 return registry; |
71 } | 79 } |
72 | 80 |
73 void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) { | 81 void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) { |
82 initialized_ = false; | |
viettrungluu
2014/09/15 17:26:19
I don't think you need this. Maybe a MOJO_DCHECK(!
DaveMoore
2014/09/15 22:35:08
Removed. At one point this was where I initialized
| |
74 shell_watch_ = new ShellPtrWatcher(this); | 83 shell_watch_ = new ShellPtrWatcher(this); |
75 shell_.Bind(shell_handle.Pass()); | 84 shell_.Bind(shell_handle.Pass()); |
76 shell_.set_client(this); | 85 shell_.set_client(this); |
77 shell_.set_error_handler(shell_watch_); | 86 shell_.set_error_handler(shell_watch_); |
78 delegate_->Initialize(this); | |
79 } | 87 } |
80 | 88 |
81 void ApplicationImpl::AcceptConnection(const String& requestor_url, | 89 void ApplicationImpl::AcceptConnection(const String& requestor_url, |
82 ServiceProviderPtr service_provider) { | 90 ServiceProviderPtr service_provider) { |
83 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 91 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
84 this, requestor_url, service_provider.Pass()); | 92 this, requestor_url, service_provider.Pass()); |
85 if (!delegate_->ConfigureIncomingConnection(registry)) { | 93 if (!delegate_->ConfigureIncomingConnection(registry)) { |
86 delete registry; | 94 delete registry; |
87 return; | 95 return; |
88 } | 96 } |
89 incoming_service_registries_.push_back(registry); | 97 incoming_service_registries_.push_back(registry); |
90 } | 98 } |
91 | 99 |
92 } // namespace mojo | 100 } // namespace mojo |
OLD | NEW |