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

Unified Diff: services/shell/public/java/src/org/chromium/services/shell/InterfaceRegistry.java

Issue 2419723002: Move services/shell to services/service_manager (Closed)
Patch Set: rebase Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: services/shell/public/java/src/org/chromium/services/shell/InterfaceRegistry.java
diff --git a/services/shell/public/java/src/org/chromium/services/shell/InterfaceRegistry.java b/services/shell/public/java/src/org/chromium/services/shell/InterfaceRegistry.java
deleted file mode 100644
index 5838a64992b6b368524cc387986119a823d199a2..0000000000000000000000000000000000000000
--- a/services/shell/public/java/src/org/chromium/services/shell/InterfaceRegistry.java
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.services.shell;
-
-import org.chromium.mojo.bindings.Interface;
-import org.chromium.mojo.system.MessagePipeHandle;
-import org.chromium.mojo.system.MojoException;
-import org.chromium.shell.mojom.InterfaceProvider;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A registry where interfaces may be registered to be exposed to another application.
- *
- * To use, define a class that implements your specific interface. Then
- * implement an InterfaceFactory that creates instances of your implementation
- * and register that on the registry with a Manager for the interface like this:
- *
- * registry.addInterface(InterfaceType.MANAGER, factory);
- */
-public class InterfaceRegistry implements InterfaceProvider {
- private final Map<String, InterfaceBinder> mBinders = new HashMap<String, InterfaceBinder>();
-
- public <I extends Interface> void addInterface(
- Interface.Manager<I, ? extends I.Proxy> manager, InterfaceFactory<I> factory) {
- mBinders.put(manager.getName(), new InterfaceBinder<I>(manager, factory));
- }
-
- public static InterfaceRegistry create(MessagePipeHandle pipe) {
- InterfaceRegistry registry = new InterfaceRegistry();
- InterfaceProvider.MANAGER.bind(registry, pipe);
- return registry;
- }
-
- @Override
- public void getInterface(String name, MessagePipeHandle pipe) {
- InterfaceBinder binder = mBinders.get(name);
- if (binder == null) {
- return;
- }
- binder.bindToMessagePipe(pipe);
- }
-
- @Override
- public void close() {
- mBinders.clear();
- }
-
- @Override
- public void onConnectionError(MojoException e) {
- close();
- }
-
- InterfaceRegistry() {}
-
- private static class InterfaceBinder<I extends Interface> {
- private Interface.Manager<I, ? extends I.Proxy> mManager;
- private InterfaceFactory<I> mFactory;
-
- public InterfaceBinder(
- Interface.Manager<I, ? extends I.Proxy> manager, InterfaceFactory<I> factory) {
- mManager = manager;
- mFactory = factory;
- }
-
- public void bindToMessagePipe(MessagePipeHandle pipe) {
- I impl = mFactory.createImpl();
- if (impl == null) {
- pipe.close();
- return;
- }
- mManager.bind(impl, pipe);
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698