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 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ | 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ | 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
10 #include "mojo/public/cpp/application/lib/service_connector.h" | 10 #include "mojo/public/cpp/application/lib/service_connector.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // }; | 51 // }; |
52 // | 52 // |
53 // or | 53 // or |
54 // | 54 // |
55 // class BarImpl : public InterfaceImpl<Bar> { | 55 // class BarImpl : public InterfaceImpl<Bar> { |
56 // public: | 56 // public: |
57 // // contexts will remain valid for the lifetime of BarImpl. | 57 // // contexts will remain valid for the lifetime of BarImpl. |
58 // BarImpl(ApplicationContext* app_context, BarContext* service_context) | 58 // BarImpl(ApplicationContext* app_context, BarContext* service_context) |
59 // : app_context_(app_context), servicecontext_(context) {} | 59 // : app_context_(app_context), servicecontext_(context) {} |
60 // | 60 // |
61 // Create an ApplicationDele instance that collects any service implementations. | 61 // Create an ApplicationImpl instance that collects any service implementations. |
62 // | 62 // |
63 // ApplicationImpl app(service_provider_handle); | 63 // ApplicationImpl app(service_provider_handle); |
64 // app.AddService<FooImpl>(); | 64 // app.AddService<FooImpl>(); |
65 // | 65 // |
66 // BarContext context; | 66 // BarContext context; |
67 // app.AddService<BarImpl>(&context); | 67 // app.AddService<BarImpl>(&context); |
68 // | 68 // |
69 // | 69 // |
70 class ApplicationImpl : public InterfaceImpl<Application> { | 70 class ApplicationImpl : public InterfaceImpl<Application> { |
71 public: | 71 public: |
72 explicit ApplicationImpl(ApplicationDelegate* delegate); | 72 explicit ApplicationImpl(ApplicationDelegate* delegate); |
73 ApplicationImpl(ApplicationDelegate* delegate, | 73 ApplicationImpl(ApplicationDelegate* delegate, |
74 ScopedMessagePipeHandle shell_handle); | 74 ScopedMessagePipeHandle shell_handle); |
75 ApplicationImpl(ApplicationDelegate* delegate, | 75 ApplicationImpl(ApplicationDelegate* delegate, |
76 MojoHandle shell_handle); | 76 MojoHandle shell_handle); |
77 virtual ~ApplicationImpl(); | 77 virtual ~ApplicationImpl(); |
78 | 78 |
79 // Establishes a new connection to an application. Caller does not own. | 79 // Establishes a new connection to an application. Caller does not own. |
80 ApplicationConnection* ConnectToApplication(const String& application_url); | 80 ApplicationConnection* ConnectToApplication(const String& application_url); |
81 | 81 |
82 // Connect to application identified by |application_url| and connect to | 82 // Connect to application identified by |application_url| and connect to |
83 // an the service implementation of the interface identified by |Interface|. | 83 // an the service implementation of the interface identified by |Interface|. |
84 template <typename Interface> | 84 template <typename Interface> |
85 void ConnectToService(const std::string& application_url, | 85 void ConnectToService(const std::string& application_url, |
86 InterfacePtr<Interface>* ptr) { | 86 InterfacePtr<Interface>* ptr) { |
87 ConnectToApplication(application_url)->ConnectToService(ptr); | 87 ConnectToApplication(application_url)->ConnectToService(ptr); |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
| 91 class ShellPtrWatcher : public ErrorHandler { |
| 92 public: |
| 93 explicit ShellPtrWatcher(ApplicationImpl* impl); |
| 94 virtual ~ShellPtrWatcher(); |
| 95 virtual void OnConnectionError() MOJO_OVERRIDE; |
| 96 private: |
| 97 ApplicationImpl* impl_; |
| 98 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellPtrWatcher); |
| 99 }; |
| 100 |
91 friend MojoResult (::MojoMain)(MojoHandle); | 101 friend MojoResult (::MojoMain)(MojoHandle); |
92 | 102 |
93 void BindShell(ScopedMessagePipeHandle shell_handle); | 103 void BindShell(ScopedMessagePipeHandle shell_handle); |
94 void BindShell(MojoHandle shell_handle); | 104 void BindShell(MojoHandle shell_handle); |
| 105 void ClearConnections(); |
| 106 void OnShellError() { ClearConnections(); Terminate(); }; |
| 107 |
| 108 // Quits the main run loop for this application. |
| 109 void Terminate(); |
95 | 110 |
96 // Application implementation. | 111 // Application implementation. |
97 virtual void AcceptConnection(const String& requestor_url, | 112 virtual void AcceptConnection(const String& requestor_url, |
98 ServiceProviderPtr provider) MOJO_OVERRIDE; | 113 ServiceProviderPtr provider) MOJO_OVERRIDE; |
99 | 114 |
100 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; | 115 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; |
101 ServiceRegistryList incoming_service_registries_; | 116 ServiceRegistryList incoming_service_registries_; |
102 ServiceRegistryList outgoing_service_registries_; | 117 ServiceRegistryList outgoing_service_registries_; |
103 ApplicationDelegate* delegate_; | 118 ApplicationDelegate* delegate_; |
104 ShellPtr shell_; | 119 ShellPtr shell_; |
| 120 ShellPtrWatcher shell_watch_; |
105 | 121 |
106 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 122 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
107 }; | 123 }; |
108 | 124 |
109 } // namespace mojo | 125 } // namespace mojo |
110 | 126 |
111 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ | 127 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
OLD | NEW |