Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Side by Side Diff: mojo/public/java/application/src/org/chromium/mojo/application/ApplicationConnection.java

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.mojo.application;
6
7 import org.chromium.mojo.bindings.Interface;
8 import org.chromium.mojo.bindings.InterfaceRequest;
9 import org.chromium.mojo.system.MessagePipeHandle;
10 import org.chromium.mojo.system.MojoException;
11 import org.chromium.mojom.mojo.ServiceProvider;
12
13 import java.io.Closeable;
14 import java.util.HashMap;
15 import java.util.Map;
16
17 /**
18 * Represents a connection to another application.
19 */
20 public class ApplicationConnection implements Closeable {
21 private final String mConnectionUrl;
22 private final String mRequestorUrl;
23 private final ServiceProviderImpl mServiceProviderImpl;
24
25 /**
26 * @param requestorUrl URL of the application requesting this connection.
27 */
28 public ApplicationConnection(String requestorUrl, String connectionUrl) {
29 mRequestorUrl = requestorUrl;
30 mConnectionUrl = connectionUrl;
31 mServiceProviderImpl = new ServiceProviderImpl();
32 }
33
34 /**
35 * @return URL of the application requesting this connection.
36 */
37 public String getRequestorUrl() {
38 return mRequestorUrl;
39 }
40
41 /**
42 * @return URL that was used by the source application to establish this con nection.
43 */
44 public String connectionUrl() {
45 return mConnectionUrl;
46 }
47
48 /**
49 * Add a new service for this application.
50 *
51 * @param binder Handle to a ServiceFactoryBinder which contains a service i mplementation.
52 */
53 public void addService(ServiceFactoryBinder<? extends Interface> binder) {
54 mServiceProviderImpl.addService(binder);
55 }
56
57 /**
58 * @return ServiceProvider for this application.
59 */
60 public ServiceProvider getLocalServiceProvider() {
61 return mServiceProviderImpl;
62 }
63
64 @Override
65 public void close() {
66 mServiceProviderImpl.close();
67 }
68 }
69
70 class ServiceProviderImpl implements ServiceProvider {
71 private final Map<String, ServiceFactoryBinder<? extends Interface>> mNameTo ServiceMap =
72 new HashMap<String, ServiceFactoryBinder<? extends Interface>>();
73
74 ServiceProviderImpl() {}
75
76 public void addService(ServiceFactoryBinder<? extends Interface> binder) {
77 mNameToServiceMap.put(binder.getInterfaceName(), binder);
78 }
79
80 @SuppressWarnings("unchecked")
81 @Override
82 public void connectToService(String interfaceName, MessagePipeHandle pipe) {
83 if (mNameToServiceMap.containsKey(interfaceName)) {
84 mNameToServiceMap.get(interfaceName)
85 .bind(InterfaceRequest.asInterfaceRequestUnsafe(pipe));
86 } else {
87 pipe.close();
88 }
89 }
90
91 @Override
92 public void close() {}
93
94 @Override
95 public void onConnectionError(MojoException e) {}
96 }
OLDNEW
« no previous file with comments | « mojo/public/java/BUILD.gn ('k') | mojo/public/java/application/src/org/chromium/mojo/application/ApplicationDelegate.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698