Index: mojo/public/java/application/src/org/chromium/mojo/application/ApplicationHelper.java |
diff --git a/mojo/public/java/application/src/org/chromium/mojo/application/ApplicationHelper.java b/mojo/public/java/application/src/org/chromium/mojo/application/ApplicationHelper.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d2b125ef8e15964cb5da25e71dc2bb86af3f0246 |
--- /dev/null |
+++ b/mojo/public/java/application/src/org/chromium/mojo/application/ApplicationHelper.java |
@@ -0,0 +1,40 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.mojo.application; |
+ |
+import org.chromium.mojo.bindings.Interface; |
+import org.chromium.mojo.bindings.Interface.Proxy; |
+import org.chromium.mojo.bindings.InterfaceRequest; |
+import org.chromium.mojo.system.Core; |
+import org.chromium.mojo.system.Pair; |
+import org.chromium.mojom.mojo.ServiceProvider; |
+import org.chromium.mojom.mojo.Shell; |
+ |
+/** |
+ * Helper class to write mojo application. |
+ */ |
+public class ApplicationHelper { |
ppi
2015/04/07 15:42:13
just a thought - would it be fitting to call it mo
qsr
2015/04/08 10:04:13
Done.
|
+ /** |
+ * Connects to a service in another application. |
+ * |
+ * @param core Implementation of the {@link Core} api. |
+ * @param shell Instance of the shell. |
+ * @param application URL to the application to use. |
+ * @param manager {@link org.chromium.mojo.bindings.Interface.Manager} for the service to |
+ * connect to. |
+ * @return a proxy to the service. |
+ */ |
+ public static <I extends Interface, P extends Proxy> P connectToService( |
+ Core core, Shell shell, String application, Interface.Manager<I, P> manager) { |
+ Pair<ServiceProvider.Proxy, InterfaceRequest<ServiceProvider>> ir = |
ppi
2015/04/07 15:42:13
how about calling this |providerRequest|?
qsr
2015/04/08 10:04:13
Done.
|
+ ServiceProvider.MANAGER.getInterfaceRequest(core); |
+ try (ServiceProvider.Proxy spp = ir.first) { |
ppi
2015/04/07 15:42:13
how about calling this |provider|?
qsr
2015/04/08 10:04:13
Done.
|
+ shell.connectToApplication(application, ir.second, null); |
+ Pair<P, InterfaceRequest<I>> fir = manager.getInterfaceRequest(core); |
ppi
2015/04/07 15:42:13
how about calling this |serviceRequest|?
qsr
2015/04/08 10:04:13
Done.
|
+ spp.connectToService(manager.getName(), fir.second.passHandle()); |
+ return fir.first; |
+ } |
+ } |
+} |