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_SHELL_PUBLIC_CPP_APPLICATION_IMPL_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_APPLICATION_IMPL_H_ |
6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_IMPL_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_IMPL_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "mojo/public/cpp/bindings/callback.h" | 15 #include "mojo/public/cpp/bindings/callback.h" |
16 #include "mojo/public/cpp/system/core.h" | 16 #include "mojo/public/cpp/system/core.h" |
17 #include "mojo/shell/public/cpp/app_lifetime_helper.h" | 17 #include "mojo/shell/public/cpp/app_lifetime_helper.h" |
18 #include "mojo/shell/public/cpp/application_connection.h" | |
19 #include "mojo/shell/public/cpp/application_delegate.h" | |
20 #include "mojo/shell/public/cpp/lib/service_registry.h" | 18 #include "mojo/shell/public/cpp/lib/service_registry.h" |
21 #include "mojo/shell/public/cpp/shell.h" | 19 #include "mojo/shell/public/cpp/shell.h" |
| 20 #include "mojo/shell/public/cpp/shell_client.h" |
22 #include "mojo/shell/public/interfaces/application.mojom.h" | 21 #include "mojo/shell/public/interfaces/application.mojom.h" |
23 #include "mojo/shell/public/interfaces/shell.mojom.h" | 22 #include "mojo/shell/public/interfaces/shell.mojom.h" |
24 | 23 |
25 namespace mojo { | 24 namespace mojo { |
26 | 25 |
27 // TODO(beng): This comment is hilariously out of date. | 26 // TODO(beng): This comment is hilariously out of date. |
28 // Utility class for communicating with the Shell, and providing Services | 27 // Utility class for communicating with the Shell, and providing Services |
29 // to clients. | 28 // to clients. |
30 // | 29 // |
31 // To use define a class that implements your specific server api, e.g. FooImpl | 30 // To use define a class that implements your specific server api, e.g. FooImpl |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 shell::mojom::ShellPtr* shell) { | 69 shell::mojom::ShellPtr* shell) { |
71 application_->UnbindConnections(application_request, shell); | 70 application_->UnbindConnections(application_request, shell); |
72 } | 71 } |
73 | 72 |
74 private: | 73 private: |
75 ApplicationImpl* application_; | 74 ApplicationImpl* application_; |
76 }; | 75 }; |
77 | 76 |
78 // Does not take ownership of |delegate|, which must remain valid for the | 77 // Does not take ownership of |delegate|, which must remain valid for the |
79 // lifetime of ApplicationImpl. | 78 // lifetime of ApplicationImpl. |
80 ApplicationImpl(ApplicationDelegate* delegate, | 79 ApplicationImpl(ShellClient* client, |
81 InterfaceRequest<shell::mojom::Application> request); | 80 InterfaceRequest<shell::mojom::Application> request); |
82 // Constructs an ApplicationImpl with a custom termination closure. This | 81 // Constructs an ApplicationImpl with a custom termination closure. This |
83 // closure is invoked on Quit() instead of the default behavior of quitting | 82 // closure is invoked on Quit() instead of the default behavior of quitting |
84 // the current base::MessageLoop. | 83 // the current base::MessageLoop. |
85 ApplicationImpl(ApplicationDelegate* delegate, | 84 ApplicationImpl(ShellClient* client, |
86 InterfaceRequest<shell::mojom::Application> request, | 85 InterfaceRequest<shell::mojom::Application> request, |
87 const Closure& termination_closure); | 86 const Closure& termination_closure); |
88 ~ApplicationImpl() override; | 87 ~ApplicationImpl() override; |
89 | 88 |
90 // The Mojo shell. This will return a valid pointer after Initialize() has | 89 // The Mojo shell. This will return a valid pointer after Initialize() has |
91 // been invoked. It will remain valid until UnbindConnections() is invoked or | 90 // been invoked. It will remain valid until UnbindConnections() is invoked or |
92 // the ApplicationImpl is destroyed. | 91 // the ApplicationImpl is destroyed. |
93 shell::mojom::Shell* shell() const { return shell_.get(); } | 92 shell::mojom::Shell* shell() const { return shell_.get(); } |
94 | 93 |
95 // Block the calling thread until the Initialize() method is called by the | 94 // Block the calling thread until the Initialize() method is called by the |
96 // shell. | 95 // shell. |
97 void WaitForInitialize(); | 96 void WaitForInitialize(); |
98 | 97 |
99 // Shell. | 98 // Shell. |
100 scoped_ptr<ApplicationConnection> ConnectToApplication( | 99 scoped_ptr<Connection> ConnectToApplication(const std::string& url) override; |
101 const std::string& url) override; | 100 scoped_ptr<Connection> ConnectToApplication(ConnectParams* params) override; |
102 scoped_ptr<ApplicationConnection> ConnectToApplication( | |
103 ConnectParams* params) override; | |
104 void Quit() override; | 101 void Quit() override; |
105 scoped_ptr<AppRefCount> CreateAppRefCount() override; | 102 scoped_ptr<AppRefCount> CreateAppRefCount() override; |
106 | 103 |
107 private: | 104 private: |
108 // shell::mojom::Application implementation. | 105 // shell::mojom::Application implementation. |
109 void Initialize(shell::mojom::ShellPtr shell, | 106 void Initialize(shell::mojom::ShellPtr shell, |
110 const mojo::String& url, | 107 const mojo::String& url, |
111 uint32_t id) override; | 108 uint32_t id) override; |
112 void AcceptConnection(const String& requestor_url, | 109 void AcceptConnection(const String& requestor_url, |
113 uint32_t requestor_id, | 110 uint32_t requestor_id, |
(...skipping 11 matching lines...) Expand all Loading... |
125 | 122 |
126 // Unbinds the Shell and Application connections. Can be used to re-bind the | 123 // Unbinds the Shell and Application connections. Can be used to re-bind the |
127 // handles to another implementation of ApplicationImpl, for instance when | 124 // handles to another implementation of ApplicationImpl, for instance when |
128 // running apptests. | 125 // running apptests. |
129 void UnbindConnections( | 126 void UnbindConnections( |
130 InterfaceRequest<shell::mojom::Application>* application_request, | 127 InterfaceRequest<shell::mojom::Application>* application_request, |
131 shell::mojom::ShellPtr* shell); | 128 shell::mojom::ShellPtr* shell); |
132 | 129 |
133 // We track the lifetime of incoming connection registries as it more | 130 // We track the lifetime of incoming connection registries as it more |
134 // convenient for the client. | 131 // convenient for the client. |
135 ScopedVector<ApplicationConnection> incoming_connections_; | 132 ScopedVector<Connection> incoming_connections_; |
136 ApplicationDelegate* delegate_; | 133 ShellClient* client_; |
137 Binding<shell::mojom::Application> binding_; | 134 Binding<shell::mojom::Application> binding_; |
138 shell::mojom::ShellPtr shell_; | 135 shell::mojom::ShellPtr shell_; |
139 Closure termination_closure_; | 136 Closure termination_closure_; |
140 AppLifetimeHelper app_lifetime_helper_; | 137 AppLifetimeHelper app_lifetime_helper_; |
141 bool quit_requested_; | 138 bool quit_requested_; |
142 base::WeakPtrFactory<ApplicationImpl> weak_factory_; | 139 base::WeakPtrFactory<ApplicationImpl> weak_factory_; |
143 | 140 |
144 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 141 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
145 }; | 142 }; |
146 | 143 |
147 } // namespace mojo | 144 } // namespace mojo |
148 | 145 |
149 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_IMPL_H_ | 146 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_IMPL_H_ |
OLD | NEW |