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

Unified Diff: mojo/public/java/bindings/src/org/chromium/mojo/bindings/DelegatingConnectionErrorHandler.java

Issue 411913002: mojo: generate Proxies and Stubs for java bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update landmines Created 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/java/bindings/src/org/chromium/mojo/bindings/DelegatingConnectionErrorHandler.java
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/DelegatingConnectionErrorHandler.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/DelegatingConnectionErrorHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ee2ae7493dc7cab17af5fdeed64536f54b0d714
--- /dev/null
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/DelegatingConnectionErrorHandler.java
@@ -0,0 +1,49 @@
+// Copyright 2014 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.mojo.bindings;
+
+import org.chromium.mojo.system.MojoException;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+/**
+ * A {@link ConnectionErrorHandler} that delegate the errors to a list of registered handlers. This
+ * class will use weak pointers to prevent keeping references to any handlers it delegates to.
+ */
+public class DelegatingConnectionErrorHandler implements ConnectionErrorHandler {
+
+ /**
+ * The registered handlers. This uses a {@link WeakHashMap} so that it doesn't prevent the
+ * handler from being garbage collected.
+ */
+ private final Set<ConnectionErrorHandler> mHandlers =
+ Collections.newSetFromMap(new WeakHashMap<ConnectionErrorHandler, Boolean>());
+
+ /**
+ * @see ConnectionErrorHandler#onConnectionError(MojoException)
+ */
+ @Override
+ public void onConnectionError(MojoException e) {
+ for (ConnectionErrorHandler handler : mHandlers) {
+ handler.onConnectionError(e);
+ }
+ }
+
+ /**
+ * Add a handler that will be notified of any error this object receives.
+ */
+ public void addConnectionErrorHandler(ConnectionErrorHandler handler) {
+ mHandlers.add(handler);
+ }
+
+ /**
+ * Remove a previously registered handler.
+ */
+ public void removeConnectionErrorHandler(ConnectionErrorHandler handler) {
+ mHandlers.remove(handler);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698