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

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

Issue 2468353002: Added UnguessableToken.java . (Closed)
Patch Set: comments Created 4 years, 1 month 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/UnguessableToken.java
diff --git a/base/android/java/src/org/chromium/base/UnguessableToken.java b/base/android/java/src/org/chromium/base/UnguessableToken.java
new file mode 100644
index 0000000000000000000000000000000000000000..4286f71191b4cf430edbe46c880efef94eef4235
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/UnguessableToken.java
@@ -0,0 +1,70 @@
+// 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.base;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import org.chromium.base.annotations.CalledByNative;
+
+/**
+ * This class mirrors unguessable_token.h . Since tokens are passed by value,
+ * we don't bother to maintain a native token. This implements Parcelable so
+ * that it may be sent via binder.
+ *
+ * To get one of these from native, one must start with a
+ * base::UnguessableToken, then create a java object from it. See
+ * jni_unguessable_token.h for information.
+ */
+public class UnguessableToken implements Parcelable {
+ private long mHigh;
+ private long mLow;
+
+ private UnguessableToken(long high, long low) {
+ mHigh = high;
+ mLow = low;
+ }
+
+ @CalledByNative
+ private static UnguessableToken create(long high, long low) {
+ return new UnguessableToken(high, low);
+ }
+
+ @CalledByNative
+ private long getHighForSerialization() {
+ return mHigh;
+ }
+
+ @CalledByNative
+ private long getLowForSerialization() {
+ return mLow;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
liberato (no reviews please) 2016/11/02 22:18:24 i need to add unit tests for these. didn't see an
+ dest.writeLong(mHigh);
+ dest.writeLong(mLow);
+ }
+
+ public static Parcelable.Creator<UnguessableToken> CREATOR =
+ new Parcelable.Creator<UnguessableToken>() {
+ @Override
+ public UnguessableToken createFromParcel(Parcel source) {
+ final long high = source.readLong();
+ final long low = source.readLong();
+ return new UnguessableToken(high, low);
+ }
+
+ @Override
+ public UnguessableToken[] newArray(int size) {
+ return new UnguessableToken[size];
+ }
+ };
+};

Powered by Google App Engine
This is Rietveld 408576698