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

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

Issue 2468353002: Added UnguessableToken.java . (Closed)
Patch Set: added final for findbugs compilation failure 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..7e8d696c4d23c06bd65a2942633f9e0789de94d1
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/UnguessableToken.java
@@ -0,0 +1,91 @@
+// 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
nyquist 2016/11/08 19:04:42 Nit: Java here and in the TODO
liberato (no reviews please) 2016/11/09 18:18:33 Done.
+ * jni_unguessable_token.h for information.
+ */
+public class UnguessableToken implements Parcelable {
+ private long mHigh;
nyquist 2016/11/08 19:04:42 final for these two fields.
liberato (no reviews please) 2016/11/09 18:18:33 Done.
+ 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) {
+ dest.writeLong(mHigh);
+ dest.writeLong(mLow);
+ }
+
+ public static final Parcelable.Creator<UnguessableToken> CREATOR =
+ new Parcelable.Creator<UnguessableToken>() {
+ @Override
+ public UnguessableToken createFromParcel(Parcel source) {
+ final long high = source.readLong();
nyquist 2016/11/08 19:04:42 Nit: unnecessary final here and below
liberato (no reviews please) 2016/11/09 18:18:33 Done.
+ final long low = source.readLong();
+ if (high == 0 || low == 0) {
+ // Refuse to create an empty UnguessableToken.
+ return null;
+ }
+ return new UnguessableToken(high, low);
+ }
+
+ @Override
+ public UnguessableToken[] newArray(int size) {
+ return new UnguessableToken[size];
+ }
+ };
+
+ // To avoid unwieldy calls in JNI for tests, parcel and unparcel.
+ // TODO(liberato): It would be nice if we could include this only with a
+ // java driver that's linked only with unit tests, but i don't see a way
+ // to do that.
+ @CalledByNative
+ private UnguessableToken parcelAndUnparcelForTesting() {
+ Parcel parcel = Parcel.obtain();
+ writeToParcel(parcel, 0);
+
+ // Rewind the parcel and un-parcel.
+ parcel.setDataPosition(0);
+ UnguessableToken token = CREATOR.createFromParcel(parcel);
+ parcel.recycle();
+
+ return token;
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698