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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.java

Issue 1486043002: [webnfc] Implement push method for Android nfc mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@step_6_add_mojo_service_CL
Patch Set: Rebased. Created 4 years, 7 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
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 android.content.Context; 7 import android.content.Context;
8 8
9 import org.chromium.base.annotations.CalledByNative; 9 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.base.annotations.JNINamespace; 10 import org.chromium.base.annotations.JNINamespace;
11 import org.chromium.content.browser.ServiceRegistry.ImplementationFactory; 11 import org.chromium.content.browser.ServiceRegistry.ImplementationFactory;
12 import org.chromium.device.battery.BatteryMonitorFactory; 12 import org.chromium.device.battery.BatteryMonitorFactory;
13 import org.chromium.device.nfc.NfcImpl;
13 import org.chromium.device.vibration.VibrationManagerImpl; 14 import org.chromium.device.vibration.VibrationManagerImpl;
14 import org.chromium.mojom.device.BatteryMonitor; 15 import org.chromium.mojom.device.BatteryMonitor;
16 import org.chromium.mojom.device.Nfc;
15 import org.chromium.mojom.device.VibrationManager; 17 import org.chromium.mojom.device.VibrationManager;
16 18
17 /** 19 /**
18 * Registers mojo services exposed by the browser in the given registry. 20 * Registers mojo services exposed by the browser in the given registry.
19 */ 21 */
20 @JNINamespace("content") 22 @JNINamespace("content")
21 class ServiceRegistrar { 23 class ServiceRegistrar {
22 // BatteryMonitorFactory can't implement ImplementationFactory itself, as we don't depend on 24 // BatteryMonitorFactory can't implement ImplementationFactory itself, as we don't depend on
23 // /content in /device. Hence we use BatteryMonitorImplementationFactory as a wrapper. 25 // /content in /device. Hence we use BatteryMonitorImplementationFactory as a wrapper.
24 private static class BatteryMonitorImplementationFactory 26 private static class BatteryMonitorImplementationFactory
25 implements ImplementationFactory<BatteryMonitor> { 27 implements ImplementationFactory<BatteryMonitor> {
26 private final BatteryMonitorFactory mFactory; 28 private final BatteryMonitorFactory mFactory;
27 29
28 BatteryMonitorImplementationFactory(Context applicationContext) { 30 BatteryMonitorImplementationFactory(Context applicationContext) {
29 mFactory = new BatteryMonitorFactory(applicationContext); 31 mFactory = new BatteryMonitorFactory(applicationContext);
30 } 32 }
31 33
32 @Override 34 @Override
33 public BatteryMonitor createImpl() { 35 public BatteryMonitor createImpl() {
34 return mFactory.createMonitor(); 36 return mFactory.createMonitor();
35 } 37 }
36 } 38 }
37 39
40 private static class NfcImplementationFactory implements ImplementationFacto ry<Nfc> {
41 private final Context mApplicationContext;
42
43 NfcImplementationFactory(Context applicationContext) {
44 mApplicationContext = applicationContext;
45 }
46
47 @Override
48 public Nfc createImpl() {
49 return new NfcImpl(mApplicationContext);
50 }
51 }
52
38 private static class VibrationManagerImplementationFactory 53 private static class VibrationManagerImplementationFactory
39 implements ImplementationFactory<VibrationManager> { 54 implements ImplementationFactory<VibrationManager> {
40 private final Context mApplicationContext; 55 private final Context mApplicationContext;
41 56
42 VibrationManagerImplementationFactory(Context applicationContext) { 57 VibrationManagerImplementationFactory(Context applicationContext) {
43 mApplicationContext = applicationContext; 58 mApplicationContext = applicationContext;
44 } 59 }
45 60
46 @Override 61 @Override
47 public VibrationManager createImpl() { 62 public VibrationManager createImpl() {
48 return new VibrationManagerImpl(mApplicationContext); 63 return new VibrationManagerImpl(mApplicationContext);
49 } 64 }
50 } 65 }
51 66
52 @CalledByNative 67 @CalledByNative
53 static void registerProcessHostServices(ServiceRegistry registry, Context ap plicationContext) { 68 static void registerProcessHostServices(ServiceRegistry registry, Context ap plicationContext) {
54 assert applicationContext != null; 69 assert applicationContext != null;
55 registry.addService(BatteryMonitor.MANAGER, 70 registry.addService(BatteryMonitor.MANAGER,
56 new BatteryMonitorImplementationFactory(applicationContext)); 71 new BatteryMonitorImplementationFactory(applicationContext));
57 registry.addService(VibrationManager.MANAGER, 72 registry.addService(VibrationManager.MANAGER,
58 new VibrationManagerImplementationFactory(applicationContext)); 73 new VibrationManagerImplementationFactory(applicationContext));
59 } 74 }
60 75
61 @CalledByNative 76 @CalledByNative
62 static void registerFrameHostServices(ServiceRegistry registry, Context appl icationContext) { 77 static void registerFrameHostServices(ServiceRegistry registry, Context appl icationContext) {
63 assert applicationContext != null; 78 assert applicationContext != null;
64 // TODO(avayvod): Register the PresentationService implementation here. 79 // TODO(avayvod): Register the PresentationService implementation here.
80 registry.addService(Nfc.MANAGER, new NfcImplementationFactory(applicatio nContext));
65 } 81 }
66 } 82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698