| 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_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ | 5 #ifndef MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ |
| 6 #define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ | 6 #define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "mojo/application/public/cpp/app_lifetime_helper.h" | 11 #include "mojo/application/public/cpp/app_lifetime_helper.h" |
| 12 #include "mojo/application/public/cpp/application_connection.h" | 12 #include "mojo/application/public/cpp/application_connection.h" |
| 13 #include "mojo/application/public/cpp/application_delegate.h" | 13 #include "mojo/application/public/cpp/application_delegate.h" |
| 14 #include "mojo/application/public/cpp/lib/service_registry.h" | 14 #include "mojo/application/public/cpp/lib/service_registry.h" |
| 15 #include "mojo/application/public/interfaces/application.mojom.h" | 15 #include "mojo/application/public/interfaces/application.mojom.h" |
| 16 #include "mojo/application/public/interfaces/shell.mojom.h" | 16 #include "mojo/application/public/interfaces/shell.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/callback.h" | 17 #include "mojo/public/cpp/bindings/callback.h" |
| 18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 | 21 |
| 22 // TODO(beng): This comment is hilariously out of date. | |
| 23 // Utility class for communicating with the Shell, and providing Services | 22 // Utility class for communicating with the Shell, and providing Services |
| 24 // to clients. | 23 // to clients. |
| 25 // | 24 // |
| 26 // To use define a class that implements your specific server api, e.g. FooImpl | 25 // To use define a class that implements your specific server api, e.g. FooImpl |
| 27 // to implement a service named Foo. | 26 // to implement a service named Foo. |
| 28 // That class must subclass an InterfaceImpl specialization. | 27 // That class must subclass an InterfaceImpl specialization. |
| 29 // | 28 // |
| 30 // If there is context that is to be shared amongst all instances, define a | 29 // If there is context that is to be shared amongst all instances, define a |
| 31 // constructor with that class as its only argument, otherwise define an empty | 30 // constructor with that class as its only argument, otherwise define an empty |
| 32 // constructor. | 31 // constructor. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 // app.AddService<BarImpl>(&context); | 52 // app.AddService<BarImpl>(&context); |
| 54 // | 53 // |
| 55 // | 54 // |
| 56 class ApplicationImpl : public Application { | 55 class ApplicationImpl : public Application { |
| 57 public: | 56 public: |
| 58 // Does not take ownership of |delegate|, which must remain valid for the | 57 // Does not take ownership of |delegate|, which must remain valid for the |
| 59 // lifetime of ApplicationImpl. | 58 // lifetime of ApplicationImpl. |
| 60 ApplicationImpl(ApplicationDelegate* delegate, | 59 ApplicationImpl(ApplicationDelegate* delegate, |
| 61 InterfaceRequest<Application> request); | 60 InterfaceRequest<Application> request); |
| 62 // Constructs an ApplicationImpl with a custom termination closure. This | 61 // Constructs an ApplicationImpl with a custom termination closure. This |
| 63 // closure is invoked on Quit() instead of the default behavior of quitting | 62 // closure is invoked on Terminate() instead of the default behavior of |
| 64 // the current base::MessageLoop. | 63 // quitting the current MessageLoop. |
| 65 ApplicationImpl(ApplicationDelegate* delegate, | 64 ApplicationImpl(ApplicationDelegate* delegate, |
| 66 InterfaceRequest<Application> request, | 65 InterfaceRequest<Application> request, |
| 67 const Closure& termination_closure); | 66 const Closure& termination_closure); |
| 68 ~ApplicationImpl() override; | 67 ~ApplicationImpl() override; |
| 69 | 68 |
| 70 // The Mojo shell. This will return a valid pointer after Initialize() has | 69 // The Mojo shell. This will return a valid pointer after Initialize() has |
| 71 // been invoked. It will remain valid until UnbindConnections() is invoked or | 70 // been invoked. It will remain valid until UnbindConnections() is invoked or |
| 72 // the ApplicationImpl is destroyed. | 71 // the ApplicationImpl is destroyed. |
| 73 Shell* shell() const { return shell_.get(); } | 72 Shell* shell() const { return shell_.get(); } |
| 74 | 73 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 106 |
| 108 // Block until the Application is initialized, if it is not already. | 107 // Block until the Application is initialized, if it is not already. |
| 109 void WaitForInitialize(); | 108 void WaitForInitialize(); |
| 110 | 109 |
| 111 // Unbinds the Shell and Application connections. Can be used to re-bind the | 110 // Unbinds the Shell and Application connections. Can be used to re-bind the |
| 112 // handles to another implementation of ApplicationImpl, for instance when | 111 // handles to another implementation of ApplicationImpl, for instance when |
| 113 // running apptests. | 112 // running apptests. |
| 114 void UnbindConnections(InterfaceRequest<Application>* application_request, | 113 void UnbindConnections(InterfaceRequest<Application>* application_request, |
| 115 ShellPtr* shell); | 114 ShellPtr* shell); |
| 116 | 115 |
| 117 // Initiate shutdown of this application. This may involve a round trip to the | 116 // Quits the main run loop for this application. It first checks with the |
| 118 // Shell to ensure there are no inbound service requests. | 117 // shell to ensure there are no outstanding service requests. |
| 119 void Quit(); | 118 void Terminate(); |
| 119 |
| 120 // Quits without waiting to check with the shell. |
| 121 void QuitNow(); |
| 120 | 122 |
| 121 private: | 123 private: |
| 122 // Application implementation. | 124 // Application implementation. |
| 123 void AcceptConnection(const String& requestor_url, | 125 void AcceptConnection(const String& requestor_url, |
| 124 InterfaceRequest<ServiceProvider> services, | 126 InterfaceRequest<ServiceProvider> services, |
| 125 ServiceProviderPtr exposed_services, | 127 ServiceProviderPtr exposed_services, |
| 126 Array<String> allowed_interfaces, | 128 Array<String> allowed_interfaces, |
| 127 const String& url) override; | 129 const String& url) override; |
| 128 void OnQuitRequested(const Callback<void(bool)>& callback) override; | 130 void OnQuitRequested(const Callback<void(bool)>& callback) override; |
| 129 | 131 |
| 130 void OnConnectionError(); | 132 void OnConnectionError(); |
| 131 | 133 |
| 132 void ClearConnections(); | 134 void ClearConnections(); |
| 133 | 135 |
| 134 // Called from Quit() when there is no Shell connection, or asynchronously | |
| 135 // from Quit() once the Shell has OK'ed shutdown. | |
| 136 void QuitNow(); | |
| 137 | |
| 138 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; | 136 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; |
| 139 | 137 |
| 140 ServiceRegistryList incoming_service_registries_; | 138 ServiceRegistryList incoming_service_registries_; |
| 141 ServiceRegistryList outgoing_service_registries_; | 139 ServiceRegistryList outgoing_service_registries_; |
| 142 ApplicationDelegate* delegate_; | 140 ApplicationDelegate* delegate_; |
| 143 Binding<Application> binding_; | 141 Binding<Application> binding_; |
| 144 ShellPtr shell_; | 142 ShellPtr shell_; |
| 145 std::string url_; | 143 std::string url_; |
| 146 Closure termination_closure_; | 144 Closure termination_closure_; |
| 147 AppLifetimeHelper app_lifetime_helper_; | 145 AppLifetimeHelper app_lifetime_helper_; |
| 148 bool quit_requested_; | 146 bool quit_requested_; |
| 149 bool in_destructor_; | 147 bool in_destructor_; |
| 150 base::WeakPtrFactory<ApplicationImpl> weak_factory_; | 148 base::WeakPtrFactory<ApplicationImpl> weak_factory_; |
| 151 | 149 |
| 152 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 150 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
| 153 }; | 151 }; |
| 154 | 152 |
| 155 } // namespace mojo | 153 } // namespace mojo |
| 156 | 154 |
| 157 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ | 155 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ |
| OLD | NEW |