OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SHELL_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_H_ |
6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_H_ |
7 | 7 |
8 #include "mojo/shell/public/cpp/app_lifetime_helper.h" | 8 #include "mojo/shell/public/cpp/app_lifetime_helper.h" |
9 #include "mojo/shell/public/cpp/application_connection.h" | 9 #include "mojo/shell/public/cpp/connection.h" |
10 #include "mojo/shell/public/interfaces/application.mojom.h" | 10 #include "mojo/shell/public/interfaces/application.mojom.h" |
11 #include "mojo/shell/public/interfaces/shell.mojom.h" | 11 #include "mojo/shell/public/interfaces/shell.mojom.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 | 14 |
15 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter(); | 15 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter(); |
16 | 16 |
17 using ApplicationRequest = InterfaceRequest<shell::mojom::Application>; | 17 using ApplicationRequest = InterfaceRequest<shell::mojom::Application>; |
18 | 18 |
19 class Shell { | 19 class Shell { |
(...skipping 15 matching lines...) Expand all Loading... |
35 private: | 35 private: |
36 URLRequestPtr request_; | 36 URLRequestPtr request_; |
37 shell::mojom::CapabilityFilterPtr filter_; | 37 shell::mojom::CapabilityFilterPtr filter_; |
38 | 38 |
39 DISALLOW_COPY_AND_ASSIGN(ConnectParams); | 39 DISALLOW_COPY_AND_ASSIGN(ConnectParams); |
40 }; | 40 }; |
41 | 41 |
42 // Requests a new connection to an application. Returns a pointer to the | 42 // Requests a new connection to an application. Returns a pointer to the |
43 // connection if the connection is permitted by this application's delegate, | 43 // connection if the connection is permitted by this application's delegate, |
44 // or nullptr otherwise. Caller takes ownership. | 44 // or nullptr otherwise. Caller takes ownership. |
45 virtual scoped_ptr<ApplicationConnection> ConnectToApplication( | 45 virtual scoped_ptr<Connection> ConnectToApplication( |
46 const std::string& url) = 0; | 46 const std::string& url) = 0; |
47 virtual scoped_ptr<ApplicationConnection> ConnectToApplication( | 47 virtual scoped_ptr<Connection> ConnectToApplication( |
48 ConnectParams* params) = 0; | 48 ConnectParams* params) = 0; |
49 | 49 |
50 // Connect to application identified by |request->url| and connect to the | 50 // Connect to application identified by |request->url| and connect to the |
51 // service implementation of the interface identified by |Interface|. | 51 // service implementation of the interface identified by |Interface|. |
52 template <typename Interface> | 52 template <typename Interface> |
53 void ConnectToService(ConnectParams* params, InterfacePtr<Interface>* ptr) { | 53 void ConnectToService(ConnectParams* params, InterfacePtr<Interface>* ptr) { |
54 scoped_ptr<ApplicationConnection> connection = ConnectToApplication(params); | 54 scoped_ptr<Connection> connection = ConnectToApplication(params); |
55 if (!connection.get()) | 55 if (!connection.get()) |
56 return; | 56 return; |
57 connection->ConnectToService(ptr); | 57 connection->ConnectToService(ptr); |
58 } | 58 } |
59 template <typename Interface> | 59 template <typename Interface> |
60 void ConnectToService(const std::string& url, InterfacePtr<Interface>* ptr) { | 60 void ConnectToService(const std::string& url, InterfacePtr<Interface>* ptr) { |
61 ConnectParams params(url); | 61 ConnectParams params(url); |
62 params.set_filter(CreatePermissiveCapabilityFilter()); | 62 params.set_filter(CreatePermissiveCapabilityFilter()); |
63 return ConnectToService(¶ms, ptr); | 63 return ConnectToService(¶ms, ptr); |
64 } | 64 } |
65 | 65 |
66 // Initiate shutdown of this application. This may involve a round trip to the | 66 // Initiate shutdown of this application. This may involve a round trip to the |
67 // Shell to ensure there are no inbound service requests. | 67 // Shell to ensure there are no inbound service requests. |
68 virtual void Quit() = 0; | 68 virtual void Quit() = 0; |
69 | 69 |
70 // Create an object that can be used to refcount the lifetime of the | 70 // Create an object that can be used to refcount the lifetime of the |
71 // application. The returned object may be cloned, and when the refcount falls | 71 // application. The returned object may be cloned, and when the refcount falls |
72 // to zero Quit() is called. | 72 // to zero Quit() is called. |
73 virtual scoped_ptr<AppRefCount> CreateAppRefCount() = 0; | 73 virtual scoped_ptr<AppRefCount> CreateAppRefCount() = 0; |
74 }; | 74 }; |
75 | 75 |
76 } // namespace mojo | 76 } // namespace mojo |
77 | 77 |
78 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_H_ | 78 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_H_ |
OLD | NEW |