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

Unified Diff: base/android/java/src/org/chromium/base/ParcelableChannelServer.java

Issue 2735113003: Changing SpawnChild to return a struct.
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: base/android/java/src/org/chromium/base/ParcelableChannelServer.java
diff --git a/base/android/java/src/org/chromium/base/ParcelableChannelServer.java b/base/android/java/src/org/chromium/base/ParcelableChannelServer.java
new file mode 100644
index 0000000000000000000000000000000000000000..a12f4a59a3c00f03953756f5208bf6f852e08396
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/ParcelableChannelServer.java
@@ -0,0 +1,64 @@
+// Copyright 2017 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.base;
+
+import android.os.Parcelable;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.concurrent.GuardedBy;
+
+/**
+ * Provides an implementation of IParcelableChannel that stores the received parcelables and make
+ * them accessible to native code.
+ */
+@JNINamespace("base::android")
+public class ParcelableChannelServer extends IParcelableChannel.Stub {
+ private static final String TAG = "ParcelableChanServer";
+
+ private final String mName;
+ private final Object mLock = new Object();
+
+ @GuardedBy("mLock")
+ private final Map<Integer, Parcelable> mReceivedParcelables = new HashMap<>();
+
+ public ParcelableChannelServer(String name) {
+ mName = name;
+ }
+
+ public void clearReceivedParcelables() {
+ mReceivedParcelables.clear();
+ }
+
+ @Override
+ public void sendParcelable(ParcelableWrapper parcelableValue) {
+ synchronized (mLock) {
+ mReceivedParcelables.put(parcelableValue.getId(), parcelableValue.getParcelable());
+ mLock.notifyAll();
+ }
+ }
+
+ @CalledByNative
+ public Parcelable takeParcelable(int id) {
+ Parcelable parcelable = null;
+ synchronized (mLock) {
+ while (parcelable == null) {
+ parcelable = mReceivedParcelables.remove(id);
+ if (parcelable == null) {
+ try {
+ mLock.wait();
+ } catch (InterruptedException ie) {
+ Log.e(TAG, "Interrupted while waiting.", ie);
+ }
+ }
+ }
+ }
+ return parcelable;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698