| Index: content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java
|
| diff --git a/content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java b/content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1978aa1661eef1ef4ad9e65c4947903d61b5d684
|
| --- /dev/null
|
| +++ b/content/public/android/java/src/org/chromium/content_public/common/ResourceRequestBody.java
|
| @@ -0,0 +1,76 @@
|
| +// 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.content_public.common;
|
| +
|
| +import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.base.annotations.JNINamespace;
|
| +
|
| +/**
|
| + * Wrapper around the native content::ResourceRequestBody.
|
| + * Takes care of managing the ref-count of the native counterpart.
|
| + */
|
| +@JNINamespace("content")
|
| +public final class ResourceRequestBody {
|
| + // Pointer to the native content:ResourceRequestBody.
|
| + // The Java object owns 1 ref-count to the native object.
|
| + private long mNativePtr;
|
| +
|
| + // ResourceRequestBody Java objects can only be constructed by
|
| + // - ResourceRequestBody::create(byte[]) (called from Java code)
|
| + // - ResourceRequestBody::create(long) (called from native code)
|
| + private ResourceRequestBody(long nativePtr) {
|
| + mNativePtr = nativePtr;
|
| + }
|
| +
|
| + protected void finalize() {
|
| + // content::ResourceRequestBody derives from a thread-safe
|
| + // base::RefCountedThreadSafe<ResourceRequestBody>, so it should
|
| + // be fine to rely on a finalizer (despite the warning from
|
| + // jni_generator/SampleForTests.java).
|
| + nativeReleaseResourceRequestBodyRefCount(mNativePtr);
|
| + }
|
| +
|
| + /**
|
| + * Releases refcount to the ptr.
|
| + * @param ptr native pointer to ResourceRequestBody
|
| + */
|
| + private static native void nativeReleaseResourceRequestBodyRefCount(long ptr);
|
| +
|
| + /**
|
| + * Used by native code to construct ResourceRequestBody.
|
| + * Caller should make sure nativePtr has 1 extra ref-count.
|
| + * @param nativePtr native pointer to ResourceRequestBody
|
| + */
|
| + @CalledByNative
|
| + private static ResourceRequestBody create(long nativePtr) {
|
| + return new ResourceRequestBody(nativePtr);
|
| + }
|
| +
|
| + /**
|
| + * Used by native code to get the wrapped ResourceRequestBody pointer.
|
| + * Caller should secure an extra ref-count by wrapping the returned
|
| + * value in scoped_refptr.
|
| + */
|
| + @CalledByNative
|
| + private long getNativePtr() {
|
| + return mNativePtr;
|
| + }
|
| +
|
| + /**
|
| + * Creates an instance wrapping a copy of the specified byte array.
|
| + * @param body the HTTP body
|
| + */
|
| + public static ResourceRequestBody create(byte[] body) {
|
| + long nativePtr = nativeCreateResourceRequestBodyFromBytes(body);
|
| + return new ResourceRequestBody(nativePtr);
|
| + }
|
| +
|
| + /**
|
| + * Equivalent of the native content::ResourceRequestBody::CreateFromBytes.
|
| + * The returned pointer has 1 extra ref-count.
|
| + * @param nativePtr native pointer to ResourceRequestBody
|
| + */
|
| + private static native long nativeCreateResourceRequestBodyFromBytes(byte[] body);
|
| +}
|
|
|