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

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

Issue 2692023002: Make PaymentRequestImpl work with RenderFrameHost (Closed)
Patch Set: Address review comment Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_public.browser; 5 package org.chromium.content_public.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 8
9 import org.chromium.services.service_manager.InterfaceRegistry; 9 import org.chromium.services.service_manager.InterfaceRegistry;
10 10
11 import java.util.ArrayList; 11 import java.util.ArrayList;
12 import java.util.List; 12 import java.util.List;
13 13
14 /** 14 /**
15 * A registrar for mojo interface implementations to provide to an InterfaceRegi stry. 15 * A registrar for mojo interface implementations to provide to an InterfaceRegi stry.
16 * 16 *
17 * @param <ParamType> the type of parameter to pass to the InterfaceRegistrar wh en adding its 17 * @param <ParamType> the type of parameter to pass to the InterfaceRegistrar wh en adding its
18 * interfaces to an InterfaceRegistry 18 * interfaces to an InterfaceRegistry
19 */ 19 */
20 public interface InterfaceRegistrar<ParamType> { 20 public interface InterfaceRegistrar<ParamType> {
21 /** Invoked to register interfaces on |registry|, parametrized by |paramValu e|. */ 21 /** Invoked to register interfaces on |registry|, parametrized by |paramValu e|. */
22 public void registerInterfaces(InterfaceRegistry registry, ParamType paramVa lue); 22 public void registerInterfaces(InterfaceRegistry registry, ParamType paramVa lue);
23 23
24 /** A registry of InterfaceRegistrars. */ 24 /** A registry of InterfaceRegistrars. */
25 public static class Registry<ParamType> { 25 public static class Registry<ParamType> {
26 private static Registry<Context> sContextRegistry; 26 private static Registry<Context> sContextRegistry;
27 private static Registry<WebContents> sWebContentsRegistry; 27 private static Registry<WebContents> sWebContentsRegistry;
28 private static Registry<RenderFrameHost> sRenderFrameHostRegistry;
28 29
29 private List<InterfaceRegistrar<ParamType>> mRegistrars = 30 private List<InterfaceRegistrar<ParamType>> mRegistrars =
30 new ArrayList<InterfaceRegistrar<ParamType>>(); 31 new ArrayList<InterfaceRegistrar<ParamType>>();
31 32
32 public static void applyContextRegistrars( 33 public static void applyContextRegistrars(
33 InterfaceRegistry interfaceRegistry, Context context) { 34 InterfaceRegistry interfaceRegistry, Context context) {
34 if (sContextRegistry == null) { 35 if (sContextRegistry == null) {
35 return; 36 return;
36 } 37 }
37 sContextRegistry.applyRegistrars(interfaceRegistry, context); 38 sContextRegistry.applyRegistrars(interfaceRegistry, context);
38 } 39 }
39 40
40 public static void applyWebContentsRegistrars( 41 public static void applyWebContentsRegistrars(
41 InterfaceRegistry interfaceRegistry, WebContents webContents) { 42 InterfaceRegistry interfaceRegistry, WebContents webContents) {
42 if (sWebContentsRegistry == null) { 43 if (sWebContentsRegistry == null) {
43 return; 44 return;
44 } 45 }
45 sWebContentsRegistry.applyRegistrars(interfaceRegistry, webContents) ; 46 sWebContentsRegistry.applyRegistrars(interfaceRegistry, webContents) ;
46 } 47 }
47 48
49 public static void applyRenderFrameHostRegistrars(
50 InterfaceRegistry interfaceRegistry, RenderFrameHost renderFrame Host) {
51 if (sRenderFrameHostRegistry == null) {
52 return;
53 }
54 sRenderFrameHostRegistry.applyRegistrars(interfaceRegistry, renderFr ameHost);
55 }
56
48 public static void addContextRegistrar(InterfaceRegistrar<Context> regis trar) { 57 public static void addContextRegistrar(InterfaceRegistrar<Context> regis trar) {
49 if (sContextRegistry == null) { 58 if (sContextRegistry == null) {
50 sContextRegistry = new Registry<Context>(); 59 sContextRegistry = new Registry<Context>();
51 } 60 }
52 sContextRegistry.addRegistrar(registrar); 61 sContextRegistry.addRegistrar(registrar);
53 } 62 }
54 63
55 public static void addWebContentsRegistrar(InterfaceRegistrar<WebContent s> registrar) { 64 public static void addWebContentsRegistrar(InterfaceRegistrar<WebContent s> registrar) {
56 if (sWebContentsRegistry == null) { 65 if (sWebContentsRegistry == null) {
57 sWebContentsRegistry = new Registry<WebContents>(); 66 sWebContentsRegistry = new Registry<WebContents>();
58 } 67 }
59 sWebContentsRegistry.addRegistrar(registrar); 68 sWebContentsRegistry.addRegistrar(registrar);
60 } 69 }
61 70
71 public static void addRenderFrameHostRegistrar(
72 InterfaceRegistrar<RenderFrameHost> registrar) {
73 if (sRenderFrameHostRegistry == null) {
74 sRenderFrameHostRegistry = new Registry<RenderFrameHost>();
75 }
76 sRenderFrameHostRegistry.addRegistrar(registrar);
77 }
78
62 private Registry() {} 79 private Registry() {}
63 80
64 private void addRegistrar(InterfaceRegistrar<ParamType> registrar) { 81 private void addRegistrar(InterfaceRegistrar<ParamType> registrar) {
65 mRegistrars.add(registrar); 82 mRegistrars.add(registrar);
66 } 83 }
67 84
68 private void applyRegistrars(InterfaceRegistry interfaceRegistry, ParamT ype param) { 85 private void applyRegistrars(InterfaceRegistry interfaceRegistry, ParamT ype param) {
69 for (InterfaceRegistrar<ParamType> registrar : mRegistrars) { 86 for (InterfaceRegistrar<ParamType> registrar : mRegistrars) {
70 registrar.registerInterfaces(interfaceRegistry, param); 87 registrar.registerInterfaces(interfaceRegistry, param);
71 } 88 }
72 } 89 }
73 } 90 }
74 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698