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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import org.chromium.base.annotations.CalledByNative; | 7 import org.chromium.base.annotations.CalledByNative; |
8 import org.chromium.base.annotations.JNINamespace; | 8 import org.chromium.base.annotations.JNINamespace; |
| 9 import org.chromium.content_public.browser.ServiceRegistryInterface; |
9 import org.chromium.mojo.bindings.Interface; | 10 import org.chromium.mojo.bindings.Interface; |
10 import org.chromium.mojo.bindings.Interface.Proxy; | 11 import org.chromium.mojo.bindings.Interface.Proxy; |
11 import org.chromium.mojo.bindings.InterfaceRequest; | 12 import org.chromium.mojo.bindings.InterfaceRequest; |
12 import org.chromium.mojo.system.Core; | 13 import org.chromium.mojo.system.Core; |
13 import org.chromium.mojo.system.MessagePipeHandle; | 14 import org.chromium.mojo.system.MessagePipeHandle; |
14 import org.chromium.mojo.system.impl.CoreImpl; | 15 import org.chromium.mojo.system.impl.CoreImpl; |
15 | 16 |
16 /** | 17 /** |
17 * Java wrapper over Mojo ServiceRegistry held by the browser. | 18 * Java wrapper over Mojo ServiceRegistry held by the browser. |
18 */ | 19 */ |
19 @JNINamespace("content") | 20 @JNINamespace("content") |
20 public class ServiceRegistry { | 21 public class ServiceRegistry implements ServiceRegistryInterface { |
21 | 22 @Override |
22 /** | |
23 * The interface that a factory should implement. | |
24 */ | |
25 public interface ImplementationFactory<I extends Interface> { | |
26 I createImpl(); | |
27 } | |
28 | |
29 /** | |
30 * Adds a service factory. | |
31 * | |
32 * @param manager The interface manager. | |
33 * @param factory The service factory. | |
34 */ | |
35 public <I extends Interface, P extends Proxy> void addService( | 23 public <I extends Interface, P extends Proxy> void addService( |
36 Interface.Manager<I, P> manager, ImplementationFactory<I> factory) { | 24 Interface.Manager<I, P> manager, ImplementationFactory<I> factory) { |
37 nativeAddService(mNativeServiceRegistryAndroid, manager, factory, manage
r.getName()); | 25 nativeAddService(mNativeServiceRegistryAndroid, manager, factory, manage
r.getName()); |
38 } | 26 } |
39 | 27 |
40 <I extends Interface, P extends Proxy> void removeService( | 28 <I extends Interface, P extends Proxy> void removeService( |
41 Interface.Manager<I, P> manager) { | 29 Interface.Manager<I, P> manager) { |
42 nativeRemoveService(mNativeServiceRegistryAndroid, manager.getName()); | 30 nativeRemoveService(mNativeServiceRegistryAndroid, manager.getName()); |
43 } | 31 } |
44 | 32 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 MessagePipeHandle handle = mCore.acquireNativeHandle(nativeHandle).toMes
sagePipeHandle(); | 64 MessagePipeHandle handle = mCore.acquireNativeHandle(nativeHandle).toMes
sagePipeHandle(); |
77 manager.bind(factory.createImpl(), handle); | 65 manager.bind(factory.createImpl(), handle); |
78 } | 66 } |
79 | 67 |
80 private native void nativeAddService(long nativeServiceRegistryAndroid, | 68 private native void nativeAddService(long nativeServiceRegistryAndroid, |
81 Interface.Manager manager, ImplementationFactory factory, String nam
e); | 69 Interface.Manager manager, ImplementationFactory factory, String nam
e); |
82 private native void nativeRemoveService(long nativeServiceRegistryAndroid, S
tring name); | 70 private native void nativeRemoveService(long nativeServiceRegistryAndroid, S
tring name); |
83 private native void nativeConnectToRemoteService(long nativeServiceRegistryA
ndroid, String name, | 71 private native void nativeConnectToRemoteService(long nativeServiceRegistryA
ndroid, String name, |
84 int handle); | 72 int handle); |
85 } | 73 } |
OLD | NEW |