| 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/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // | 49 // |
| 50 // ApplicationImpl app(service_provider_handle); | 50 // ApplicationImpl app(service_provider_handle); |
| 51 // app.AddService<FooImpl>(); | 51 // app.AddService<FooImpl>(); |
| 52 // | 52 // |
| 53 // BarContext context; | 53 // BarContext context; |
| 54 // app.AddService<BarImpl>(&context); | 54 // app.AddService<BarImpl>(&context); |
| 55 // | 55 // |
| 56 // | 56 // |
| 57 class ApplicationImpl : public Application { | 57 class ApplicationImpl : public Application { |
| 58 public: | 58 public: |
| 59 class TestApi { |
| 60 public: |
| 61 explicit TestApi(ApplicationImpl* application) |
| 62 : application_(application) {} |
| 63 |
| 64 void UnbindConnections(InterfaceRequest<Application>* application_request, |
| 65 ShellPtr* shell) { |
| 66 application_->UnbindConnections(application_request, shell); |
| 67 } |
| 68 |
| 69 private: |
| 70 ApplicationImpl* application_; |
| 71 }; |
| 72 |
| 59 // Does not take ownership of |delegate|, which must remain valid for the | 73 // Does not take ownership of |delegate|, which must remain valid for the |
| 60 // lifetime of ApplicationImpl. | 74 // lifetime of ApplicationImpl. |
| 61 ApplicationImpl(ApplicationDelegate* delegate, | 75 ApplicationImpl(ApplicationDelegate* delegate, |
| 62 InterfaceRequest<Application> request); | 76 InterfaceRequest<Application> request); |
| 63 // Constructs an ApplicationImpl with a custom termination closure. This | 77 // Constructs an ApplicationImpl with a custom termination closure. This |
| 64 // closure is invoked on Quit() instead of the default behavior of quitting | 78 // closure is invoked on Quit() instead of the default behavior of quitting |
| 65 // the current base::MessageLoop. | 79 // the current base::MessageLoop. |
| 66 ApplicationImpl(ApplicationDelegate* delegate, | 80 ApplicationImpl(ApplicationDelegate* delegate, |
| 67 InterfaceRequest<Application> request, | 81 InterfaceRequest<Application> request, |
| 68 const Closure& termination_closure); | 82 const Closure& termination_closure); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 template <typename Interface> | 105 template <typename Interface> |
| 92 void ConnectToService(mojo::URLRequestPtr request, | 106 void ConnectToService(mojo::URLRequestPtr request, |
| 93 InterfacePtr<Interface>* ptr) { | 107 InterfacePtr<Interface>* ptr) { |
| 94 scoped_ptr<ApplicationConnection> connection = | 108 scoped_ptr<ApplicationConnection> connection = |
| 95 ConnectToApplication(request.Pass()); | 109 ConnectToApplication(request.Pass()); |
| 96 if (!connection.get()) | 110 if (!connection.get()) |
| 97 return; | 111 return; |
| 98 connection->ConnectToService(ptr); | 112 connection->ConnectToService(ptr); |
| 99 } | 113 } |
| 100 | 114 |
| 101 // Application implementation. | |
| 102 void Initialize(ShellPtr shell, const mojo::String& url) override; | |
| 103 | |
| 104 // Block until the Application is initialized, if it is not already. | |
| 105 void WaitForInitialize(); | |
| 106 | |
| 107 // Unbinds the Shell and Application connections. Can be used to re-bind the | |
| 108 // handles to another implementation of ApplicationImpl, for instance when | |
| 109 // running apptests. | |
| 110 void UnbindConnections(InterfaceRequest<Application>* application_request, | |
| 111 ShellPtr* shell); | |
| 112 | |
| 113 // Initiate shutdown of this application. This may involve a round trip to the | 115 // Initiate shutdown of this application. This may involve a round trip to the |
| 114 // Shell to ensure there are no inbound service requests. | 116 // Shell to ensure there are no inbound service requests. |
| 115 void Quit(); | 117 void Quit(); |
| 116 | 118 |
| 117 private: | 119 private: |
| 118 // Application implementation. | 120 // Application implementation. |
| 121 void Initialize(ShellPtr shell, const mojo::String& url) override; |
| 119 void AcceptConnection(const String& requestor_url, | 122 void AcceptConnection(const String& requestor_url, |
| 120 InterfaceRequest<ServiceProvider> services, | 123 InterfaceRequest<ServiceProvider> services, |
| 121 ServiceProviderPtr exposed_services, | 124 ServiceProviderPtr exposed_services, |
| 122 Array<String> allowed_interfaces, | 125 Array<String> allowed_interfaces, |
| 123 const String& url) override; | 126 const String& url) override; |
| 124 void OnQuitRequested(const Callback<void(bool)>& callback) override; | 127 void OnQuitRequested(const Callback<void(bool)>& callback) override; |
| 125 | 128 |
| 126 void OnConnectionError(); | 129 void OnConnectionError(); |
| 127 | 130 |
| 128 // Called from Quit() when there is no Shell connection, or asynchronously | 131 // Called from Quit() when there is no Shell connection, or asynchronously |
| 129 // from Quit() once the Shell has OK'ed shutdown. | 132 // from Quit() once the Shell has OK'ed shutdown. |
| 130 void QuitNow(); | 133 void QuitNow(); |
| 131 | 134 |
| 135 // Unbinds the Shell and Application connections. Can be used to re-bind the |
| 136 // handles to another implementation of ApplicationImpl, for instance when |
| 137 // running apptests. |
| 138 void UnbindConnections(InterfaceRequest<Application>* application_request, |
| 139 ShellPtr* shell); |
| 140 |
| 132 // We track the lifetime of incoming connection registries as it more | 141 // We track the lifetime of incoming connection registries as it more |
| 133 // convenient for the client. | 142 // convenient for the client. |
| 134 ScopedVector<ApplicationConnection> incoming_connections_; | 143 ScopedVector<ApplicationConnection> incoming_connections_; |
| 135 ApplicationDelegate* delegate_; | 144 ApplicationDelegate* delegate_; |
| 136 Binding<Application> binding_; | 145 Binding<Application> binding_; |
| 137 ShellPtr shell_; | 146 ShellPtr shell_; |
| 138 std::string url_; | 147 std::string url_; |
| 139 Closure termination_closure_; | 148 Closure termination_closure_; |
| 140 AppLifetimeHelper app_lifetime_helper_; | 149 AppLifetimeHelper app_lifetime_helper_; |
| 141 bool quit_requested_; | 150 bool quit_requested_; |
| 142 base::WeakPtrFactory<ApplicationImpl> weak_factory_; | 151 base::WeakPtrFactory<ApplicationImpl> weak_factory_; |
| 143 | 152 |
| 144 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 153 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
| 145 }; | 154 }; |
| 146 | 155 |
| 147 } // namespace mojo | 156 } // namespace mojo |
| 148 | 157 |
| 149 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ | 158 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ |
| OLD | NEW |