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

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

Issue 2214323002: Add a Java InterfaceRegistry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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.system.MessagePipeHandle;
9 import org.chromium.mojo.system.MojoException;
10 import org.chromium.mojom.mojo.ServiceProvider;
11
12 import java.io.Closeable;
13 import java.util.HashMap;
14 import java.util.Map;
15
16 /**
17 * Represents a connection to another application.
18 */
19 public class ApplicationConnection implements Closeable {
20 private final String mConnectionUrl;
21 private final ServiceProvider mExposedServices;
22 private final String mRequestorUrl;
23 private final ServiceProviderImpl mServiceProviderImpl;
24
25 /**
26 * @param requestorUrl URL of the application requesting this connection.
27 * @param exposedServices ServiceProvider for services exposed by the remote application.
28 */
29 public ApplicationConnection(
30 String requestorUrl, ServiceProvider exposedServices, String connect ionUrl) {
31 mRequestorUrl = requestorUrl;
32 mExposedServices = exposedServices;
33 mConnectionUrl = connectionUrl;
34 mServiceProviderImpl = new ServiceProviderImpl();
35 }
36
37 /**
38 * @return URL of the application requesting this connection.
39 */
40 public String getRequestorUrl() {
41 return mRequestorUrl;
42 }
43
44 /**
45 * @return URL that was used by the source application to establish this con nection.
46 */
47 public String connectionUrl() {
48 return mConnectionUrl;
49 }
50
51 /**
52 * @return ServiceProvider for services exposed by the remote application.
53 */
54 public ServiceProvider getRemoteServiceProvider() {
55 return mExposedServices;
56 }
57
58 /**
59 * Add a new service for this application.
60 *
61 * @param binder Handle to a ServiceFactoryBinder which contains a service i mplementation.
62 */
63 public void addService(ServiceFactoryBinder<? extends Interface> binder) {
64 mServiceProviderImpl.addService(binder);
65 }
66
67 /**
68 * @return ServiceProvider for this application.
69 */
70 public ServiceProvider getLocalServiceProvider() {
71 return mServiceProviderImpl;
72 }
73
74 @Override
75 public void close() {
76 mServiceProviderImpl.close();
77 if (mExposedServices != null) {
78 mExposedServices.close();
79 }
80 }
81 }
82
83 class ServiceProviderImpl implements ServiceProvider {
84 private final Map<String, ServiceFactoryBinder<? extends Interface>> mNameTo ServiceMap =
85 new HashMap<String, ServiceFactoryBinder<? extends Interface>>();
86
87 ServiceProviderImpl() {}
88
89 public void addService(ServiceFactoryBinder<? extends Interface> binder) {
90 mNameToServiceMap.put(binder.getInterfaceName(), binder);
91 }
92
93 @Override
94 public void connectToService(String interfaceName, MessagePipeHandle pipe) {
95 if (mNameToServiceMap.containsKey(interfaceName)) {
96 mNameToServiceMap.get(interfaceName).bindNewInstanceToMessagePipe(pi pe);
97 } else {
98 pipe.close();
99 }
100 }
101
102 @Override
103 public void close() {}
104
105 @Override
106 public void onConnectionError(MojoException e) {}
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698