This source file includes following definitions.
- JNINamespace
- nativeGetDefaultNativeAwQuotaManagerBridge
- getInstance
- getNextId
- deleteAllData
- deleteOrigin
- getOrigins
- getQuotaForOrigin
- getUsageForOrigin
- onGetOriginsCallback
- onGetUsageAndQuotaForOriginCallback
- nativeInit
- nativeDeleteAllData
- nativeDeleteOrigin
- nativeGetOrigins
- nativeGetUsageAndQuotaForOrigin
package org.chromium.android_webview;
import android.util.SparseArray;
import android.webkit.ValueCallback;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.base.ThreadUtils;
@JNINamespace("android_webview")
public class AwQuotaManagerBridge {
private static native long nativeGetDefaultNativeAwQuotaManagerBridge();
private static AwQuotaManagerBridge sInstance;
public static AwQuotaManagerBridge getInstance() {
ThreadUtils.assertOnUiThread();
if (sInstance == null) {
sInstance = new AwQuotaManagerBridge(nativeGetDefaultNativeAwQuotaManagerBridge());
}
return sInstance;
}
public static class Origins {
public final String[] mOrigins;
public final long[] mUsages;
public final long[] mQuotas;
Origins(String[] origins, long[] usages, long[] quotas) {
mOrigins = origins;
mUsages = usages;
mQuotas = quotas;
}
}
private long mNativeAwQuotaManagerBridgeImpl;
private int mNextId;
private SparseArray<ValueCallback<Origins>> mPendingGetOriginCallbacks;
private SparseArray<ValueCallback<Long>> mPendingGetQuotaForOriginCallbacks;
private SparseArray<ValueCallback<Long>> mPendingGetUsageForOriginCallbacks;
private AwQuotaManagerBridge(long nativeAwQuotaManagerBridgeImpl) {
mNativeAwQuotaManagerBridgeImpl = nativeAwQuotaManagerBridgeImpl;
mPendingGetOriginCallbacks =
new SparseArray<ValueCallback<Origins>>();
mPendingGetQuotaForOriginCallbacks = new SparseArray<ValueCallback<Long>>();
mPendingGetUsageForOriginCallbacks = new SparseArray<ValueCallback<Long>>();
nativeInit(mNativeAwQuotaManagerBridgeImpl);
}
private int getNextId() {
ThreadUtils.assertOnUiThread();
return ++mNextId;
}
public void deleteAllData() {
nativeDeleteAllData(mNativeAwQuotaManagerBridgeImpl);
}
public void deleteOrigin(String origin) {
nativeDeleteOrigin(mNativeAwQuotaManagerBridgeImpl, origin);
}
public void getOrigins(ValueCallback<Origins> callback) {
int callbackId = getNextId();
assert mPendingGetOriginCallbacks.get(callbackId) == null;
mPendingGetOriginCallbacks.put(callbackId, callback);
nativeGetOrigins(mNativeAwQuotaManagerBridgeImpl, callbackId);
}
public void getQuotaForOrigin(String origin, ValueCallback<Long> callback) {
int callbackId = getNextId();
assert mPendingGetQuotaForOriginCallbacks.get(callbackId) == null;
mPendingGetQuotaForOriginCallbacks.put(callbackId, callback);
nativeGetUsageAndQuotaForOrigin(mNativeAwQuotaManagerBridgeImpl, origin, callbackId, true);
}
public void getUsageForOrigin(String origin, ValueCallback<Long> callback) {
int callbackId = getNextId();
assert mPendingGetUsageForOriginCallbacks.get(callbackId) == null;
mPendingGetUsageForOriginCallbacks.put(callbackId, callback);
nativeGetUsageAndQuotaForOrigin(mNativeAwQuotaManagerBridgeImpl, origin, callbackId, false);
}
@CalledByNative
private void onGetOriginsCallback(int callbackId, String[] origin, long[] usages,
long[] quotas) {
assert mPendingGetOriginCallbacks.get(callbackId) != null;
mPendingGetOriginCallbacks.get(callbackId).onReceiveValue(
new Origins(origin, usages, quotas));
mPendingGetOriginCallbacks.remove(callbackId);
}
@CalledByNative
private void onGetUsageAndQuotaForOriginCallback(
int callbackId, boolean isQuota, long usage, long quota) {
if (isQuota) {
assert mPendingGetQuotaForOriginCallbacks.get(callbackId) != null;
mPendingGetQuotaForOriginCallbacks.get(callbackId).onReceiveValue(quota);
mPendingGetQuotaForOriginCallbacks.remove(callbackId);
} else {
assert mPendingGetUsageForOriginCallbacks.get(callbackId) != null;
mPendingGetUsageForOriginCallbacks.get(callbackId).onReceiveValue(usage);
mPendingGetUsageForOriginCallbacks.remove(callbackId);
}
}
private native void nativeInit(long nativeAwQuotaManagerBridgeImpl);
private native void nativeDeleteAllData(long nativeAwQuotaManagerBridgeImpl);
private native void nativeDeleteOrigin(long nativeAwQuotaManagerBridgeImpl, String origin);
private native void nativeGetOrigins(long nativeAwQuotaManagerBridgeImpl, int callbackId);
private native void nativeGetUsageAndQuotaForOrigin(long nativeAwQuotaManagerBridgeImpl,
String origin, int callbackId, boolean isQuota);
}