| 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_CPP_APPLICATION_APPLICATION_IMPL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_H_ |
| 6 #define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_H_ | 6 #define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include "mojo/public/cpp/application/application_impl_base.h" |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | |
| 13 #include "mojo/public/cpp/system/macros.h" | 9 #include "mojo/public/cpp/system/macros.h" |
| 14 #include "mojo/public/interfaces/application/application.mojom.h" | |
| 15 #include "mojo/public/interfaces/application/shell.mojom.h" | |
| 16 | 10 |
| 17 namespace mojo { | 11 namespace mojo { |
| 18 | 12 |
| 13 class ApplicationDelegate; |
| 19 class ServiceProviderImpl; | 14 class ServiceProviderImpl; |
| 20 | 15 |
| 21 // Implements the Application interface, which the shell uses for basic | 16 // Implements the Application interface, which the shell uses for basic |
| 22 // communication with an application (e.g., to connect clients to services | 17 // communication with an application (e.g., to connect clients to services |
| 23 // provided by an application). Also provides the application access to the | 18 // provided by an application). Also provides the application access to the |
| 24 // Shell, which, e.g., may be used by an application to connect to other | 19 // Shell, which, e.g., may be used by an application to connect to other |
| 25 // services. | 20 // services. |
| 26 // | 21 // |
| 27 // Typically, you create one or more classes implementing your APIs (e.g., | 22 // Typically, you create one or more classes implementing your APIs (e.g., |
| 28 // FooImpl implementing Foo). See bindings/binding.h for more information. Then | 23 // FooImpl implementing Foo). See bindings/binding.h for more information. Then |
| 29 // you implement an mojo::ApplicationDelegate whose | 24 // you implement an mojo::ApplicationDelegate whose |
| 30 // ConfigureIncomingConnection() adds services to each connection. Finally, you | 25 // ConfigureIncomingConnection() adds services to each connection. Finally, you |
| 31 // instantiate your delegate and pass it to an ApplicationRunner, which will | 26 // instantiate your delegate and pass it to an ApplicationRunner, which will |
| 32 // create the ApplicationImpl and then run a message (or run) loop. | 27 // create the ApplicationImpl and then run a message (or run) loop. |
| 33 class ApplicationImpl : public Application { | 28 class ApplicationImpl : public ApplicationImplBase { |
| 34 public: | 29 public: |
| 35 // Does not take ownership of |delegate|, which must remain valid for the | 30 // Does not take ownership of |delegate|, which must remain valid for the |
| 36 // lifetime of ApplicationImpl. | 31 // lifetime of ApplicationImpl. |
| 37 ApplicationImpl(ApplicationDelegate* delegate, | 32 ApplicationImpl(ApplicationDelegate* delegate, |
| 38 InterfaceRequest<Application> request); | 33 InterfaceRequest<Application> request); |
| 39 ~ApplicationImpl() override; | 34 ~ApplicationImpl() override; |
| 40 | 35 |
| 41 // Quits the main run loop for this application. | 36 private: |
| 42 // TODO(vtl): This is implemented in application_runner.cc (for example). Its | 37 // |ApplicationImplBase| implementation/overrides: |
| 43 // presence here is pretty dubious. | 38 void OnInitialize() final; |
| 44 static void Terminate(); | 39 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) final; |
| 40 void OnQuit() final; |
| 45 | 41 |
| 46 // The Mojo shell. This will return a valid pointer after Initialize() has | 42 ApplicationDelegate* const delegate_; |
| 47 // been invoked. It will remain valid until this object is destroyed. | |
| 48 Shell* shell() const { return shell_.get(); } | |
| 49 | |
| 50 const std::string& url() const { return url_; } | |
| 51 | |
| 52 // Returns any initial configuration arguments, passed by the Shell. | |
| 53 const std::vector<std::string>& args() const { return args_; } | |
| 54 bool HasArg(const std::string& arg) const; | |
| 55 | |
| 56 private: | |
| 57 // |Application| implementation. | |
| 58 void Initialize(InterfaceHandle<Shell> shell, | |
| 59 Array<String> args, | |
| 60 const mojo::String& url) override; | |
| 61 void AcceptConnection(const String& requestor_url, | |
| 62 InterfaceRequest<ServiceProvider> services, | |
| 63 InterfaceHandle<ServiceProvider> exposed_services, | |
| 64 const String& url) override; | |
| 65 void RequestQuit() override; | |
| 66 | |
| 67 std::vector<std::unique_ptr<ServiceProviderImpl>> service_provider_impls_; | |
| 68 ApplicationDelegate* delegate_; | |
| 69 Binding<Application> application_binding_; | |
| 70 ShellPtr shell_; | |
| 71 std::string url_; | |
| 72 std::vector<std::string> args_; | |
| 73 | 43 |
| 74 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 44 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
| 75 }; | 45 }; |
| 76 | 46 |
| 77 } // namespace mojo | 47 } // namespace mojo |
| 78 | 48 |
| 79 #endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_H_ | 49 #endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_IMPL_H_ |
| OLD | NEW |