Commit 93b6d651 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

[aw] Make java part of AwQuotaManagerBridge not a singleton.

Java AwQuotaManagerBridge is now owned by Java AwBrowserContext.

Bug: 963875
Change-Id: I517b1d17f17f6bda9ce93de09baa4861a74bc179
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742171Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Anna Malova <amalova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685395}
parent 193cea1d
...@@ -452,4 +452,8 @@ AwBrowserContext::GetJavaBrowserContext() { ...@@ -452,4 +452,8 @@ AwBrowserContext::GetJavaBrowserContext() {
return base::android::ScopedJavaLocalRef<jobject>(obj_); return base::android::ScopedJavaLocalRef<jobject>(obj_);
} }
jlong AwBrowserContext::GetQuotaManagerBridge(JNIEnv* env) {
return reinterpret_cast<intptr_t>(GetQuotaManagerBridge());
}
} // namespace android_webview } // namespace android_webview
...@@ -74,6 +74,8 @@ class AwBrowserContext : public content::BrowserContext, ...@@ -74,6 +74,8 @@ class AwBrowserContext : public content::BrowserContext,
void AddVisitedURLs(const std::vector<GURL>& urls); void AddVisitedURLs(const std::vector<GURL>& urls);
AwQuotaManagerBridge* GetQuotaManagerBridge(); AwQuotaManagerBridge* GetQuotaManagerBridge();
jlong GetQuotaManagerBridge(JNIEnv* env);
AwFormDatabaseService* GetFormDatabaseService(); AwFormDatabaseService* GetFormDatabaseService();
autofill::AutocompleteHistoryManager* GetAutocompleteHistoryManager(); autofill::AutocompleteHistoryManager* GetAutocompleteHistoryManager();
......
...@@ -28,7 +28,6 @@ import org.chromium.android_webview.AwFirebaseConfig; ...@@ -28,7 +28,6 @@ import org.chromium.android_webview.AwFirebaseConfig;
import org.chromium.android_webview.AwLocaleConfig; import org.chromium.android_webview.AwLocaleConfig;
import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
import org.chromium.android_webview.AwProxyController; import org.chromium.android_webview.AwProxyController;
import org.chromium.android_webview.AwQuotaManagerBridge;
import org.chromium.android_webview.AwServiceWorkerController; import org.chromium.android_webview.AwServiceWorkerController;
import org.chromium.android_webview.AwTracingController; import org.chromium.android_webview.AwTracingController;
import org.chromium.android_webview.HttpAuthDatabase; import org.chromium.android_webview.HttpAuthDatabase;
...@@ -205,7 +204,8 @@ public class WebViewChromiumAwInit { ...@@ -205,7 +204,8 @@ public class WebViewChromiumAwInit {
AwBrowserContext awBrowserContext = getBrowserContextOnUiThread(); AwBrowserContext awBrowserContext = getBrowserContextOnUiThread();
mGeolocationPermissions = new GeolocationPermissionsAdapter( mGeolocationPermissions = new GeolocationPermissionsAdapter(
mFactory, awBrowserContext.getGeolocationPermissions()); mFactory, awBrowserContext.getGeolocationPermissions());
mWebStorage = new WebStorageAdapter(mFactory, AwQuotaManagerBridge.getInstance()); mWebStorage =
new WebStorageAdapter(mFactory, mBrowserContext.getQuotaManagerBridge());
mAwTracingController = getTracingController(); mAwTracingController = getTracingController();
mServiceWorkerController = awBrowserContext.getServiceWorkerController(); mServiceWorkerController = awBrowserContext.getServiceWorkerController();
mAwProxyController = new AwProxyController(); mAwProxyController = new AwProxyController();
......
...@@ -33,6 +33,7 @@ public class AwBrowserContext { ...@@ -33,6 +33,7 @@ public class AwBrowserContext {
private AwGeolocationPermissions mGeolocationPermissions; private AwGeolocationPermissions mGeolocationPermissions;
private AwFormDatabase mFormDatabase; private AwFormDatabase mFormDatabase;
private AwServiceWorkerController mServiceWorkerController; private AwServiceWorkerController mServiceWorkerController;
private AwQuotaManagerBridge mQuotaManagerBridge;
/** Pointer to the Native-side AwBrowserContext. */ /** Pointer to the Native-side AwBrowserContext. */
private long mNativeAwBrowserContext; private long mNativeAwBrowserContext;
...@@ -85,6 +86,14 @@ public class AwBrowserContext { ...@@ -85,6 +86,14 @@ public class AwBrowserContext {
return mServiceWorkerController; return mServiceWorkerController;
} }
public AwQuotaManagerBridge getQuotaManagerBridge() {
if (mQuotaManagerBridge == null) {
mQuotaManagerBridge =
new AwQuotaManagerBridge(nativeGetQuotaManagerBridge(mNativeAwBrowserContext));
}
return mQuotaManagerBridge;
}
/** /**
* @see android.webkit.WebView#pauseTimers() * @see android.webkit.WebView#pauseTimers()
*/ */
...@@ -121,4 +130,5 @@ public class AwBrowserContext { ...@@ -121,4 +130,5 @@ public class AwBrowserContext {
} }
private static native AwBrowserContext nativeGetDefaultJava(); private static native AwBrowserContext nativeGetDefaultJava();
private static native long nativeGetQuotaManagerBridge(long nativeAwBrowserContext);
} }
...@@ -14,24 +14,9 @@ import org.chromium.base.annotations.JNINamespace; ...@@ -14,24 +14,9 @@ import org.chromium.base.annotations.JNINamespace;
/** /**
* Bridge between android.webview.WebStorage and native QuotaManager. This object is owned by Java * Bridge between android.webview.WebStorage and native QuotaManager. This object is owned by Java
* AwBrowserContext and the native side is owned by the native AwBrowserContext. * AwBrowserContext and the native side is owned by the native AwBrowserContext.
*
* TODO(boliu): Actually make this true after Java AwBrowserContext is added.
*/ */
@JNINamespace("android_webview") @JNINamespace("android_webview")
public class AwQuotaManagerBridge { public class AwQuotaManagerBridge {
// TODO(boliu): This should be obtained from Java AwBrowserContext that owns this.
private static native long nativeGetDefaultNativeAwQuotaManagerBridge();
// TODO(boliu): This should be owned by Java AwBrowserContext, not a singleton.
private static AwQuotaManagerBridge sInstance;
public static AwQuotaManagerBridge getInstance() {
ThreadUtils.assertOnUiThread();
if (sInstance == null) {
sInstance = new AwQuotaManagerBridge(nativeGetDefaultNativeAwQuotaManagerBridge());
}
return sInstance;
}
/** /**
* This class represent the callback value of android.webview.WebStorage.getOrigins. The values * This class represent the callback value of android.webview.WebStorage.getOrigins. The values
* are optimized for JNI convenience and need to be converted. * are optimized for JNI convenience and need to be converted.
...@@ -59,7 +44,7 @@ public class AwQuotaManagerBridge { ...@@ -59,7 +44,7 @@ public class AwQuotaManagerBridge {
private SparseArray<Callback<Long>> mPendingGetQuotaForOriginCallbacks; private SparseArray<Callback<Long>> mPendingGetQuotaForOriginCallbacks;
private SparseArray<Callback<Long>> mPendingGetUsageForOriginCallbacks; private SparseArray<Callback<Long>> mPendingGetUsageForOriginCallbacks;
private AwQuotaManagerBridge(long nativeAwQuotaManagerBridge) { public AwQuotaManagerBridge(long nativeAwQuotaManagerBridge) {
mNativeAwQuotaManagerBridge = nativeAwQuotaManagerBridge; mNativeAwQuotaManagerBridge = nativeAwQuotaManagerBridge;
mPendingGetOriginCallbacks = new SparseArray<Callback<Origins>>(); mPendingGetOriginCallbacks = new SparseArray<Callback<Origins>>();
mPendingGetQuotaForOriginCallbacks = new SparseArray<Callback<Long>>(); mPendingGetQuotaForOriginCallbacks = new SparseArray<Callback<Long>>();
......
...@@ -63,12 +63,14 @@ public class AwQuotaManagerBridgeTest { ...@@ -63,12 +63,14 @@ public class AwQuotaManagerBridgeTest {
} }
private void deleteAllData() throws Exception { private void deleteAllData() throws Exception {
final AwQuotaManagerBridge bridge = AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(); final AwQuotaManagerBridge bridge =
mActivityTestRule.getAwBrowserContext().getQuotaManagerBridge();
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> bridge.deleteAllData()); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> bridge.deleteAllData());
} }
private void deleteOrigin(final String origin) throws Exception { private void deleteOrigin(final String origin) throws Exception {
final AwQuotaManagerBridge bridge = AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(); final AwQuotaManagerBridge bridge =
mActivityTestRule.getAwBrowserContext().getQuotaManagerBridge();
InstrumentationRegistry.getInstrumentation().runOnMainSync( InstrumentationRegistry.getInstrumentation().runOnMainSync(
() -> bridge.deleteOrigin(origin)); () -> bridge.deleteOrigin(origin));
} }
...@@ -89,7 +91,8 @@ public class AwQuotaManagerBridgeTest { ...@@ -89,7 +91,8 @@ public class AwQuotaManagerBridgeTest {
private long getQuotaForOrigin() throws Exception { private long getQuotaForOrigin() throws Exception {
final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper(); final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper();
final AwQuotaManagerBridge bridge = AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(); final AwQuotaManagerBridge bridge =
mActivityTestRule.getAwBrowserContext().getQuotaManagerBridge();
int callCount = callbackHelper.getCallCount(); int callCount = callbackHelper.getCallCount();
InstrumentationRegistry.getInstrumentation().runOnMainSync( InstrumentationRegistry.getInstrumentation().runOnMainSync(
...@@ -102,7 +105,8 @@ public class AwQuotaManagerBridgeTest { ...@@ -102,7 +105,8 @@ public class AwQuotaManagerBridgeTest {
private long getUsageForOrigin(final String origin) throws Exception { private long getUsageForOrigin(final String origin) throws Exception {
final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper(); final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper();
final AwQuotaManagerBridge bridge = AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(); final AwQuotaManagerBridge bridge =
mActivityTestRule.getAwBrowserContext().getQuotaManagerBridge();
int callCount = callbackHelper.getCallCount(); int callCount = callbackHelper.getCallCount();
InstrumentationRegistry.getInstrumentation().runOnMainSync( InstrumentationRegistry.getInstrumentation().runOnMainSync(
...@@ -176,11 +180,12 @@ public class AwQuotaManagerBridgeTest { ...@@ -176,11 +180,12 @@ public class AwQuotaManagerBridgeTest {
@DisabledTest(message = "crbug.com/609977") @DisabledTest(message = "crbug.com/609977")
public void testGetResultsMatch() throws Exception { public void testGetResultsMatch() throws Exception {
useAppCache(); useAppCache();
AwQuotaManagerBridge bridge =
mActivityTestRule.getAwBrowserContext().getQuotaManagerBridge();
AwActivityTestRule.pollInstrumentationThread( AwActivityTestRule.pollInstrumentationThread(
() -> AwQuotaManagerBridgeTestUtil.getOrigins().mOrigins.length > 0); () -> AwQuotaManagerBridgeTestUtil.getOrigins(bridge).mOrigins.length > 0);
AwQuotaManagerBridge.Origins origins = AwQuotaManagerBridgeTestUtil.getOrigins(); AwQuotaManagerBridge.Origins origins = AwQuotaManagerBridgeTestUtil.getOrigins(bridge);
Assert.assertEquals(origins.mOrigins.length, origins.mUsages.length); Assert.assertEquals(origins.mOrigins.length, origins.mUsages.length);
Assert.assertEquals(origins.mOrigins.length, origins.mQuotas.length); Assert.assertEquals(origins.mOrigins.length, origins.mQuotas.length);
......
...@@ -28,7 +28,8 @@ public class StandaloneAwQuotaManagerBridgeTest { ...@@ -28,7 +28,8 @@ public class StandaloneAwQuotaManagerBridgeTest {
@SmallTest @SmallTest
public void testStartup() throws Exception { public void testStartup() throws Exception {
// AwQuotaManager should run without any issue. // AwQuotaManager should run without any issue.
AwQuotaManagerBridge.Origins origins = AwQuotaManagerBridgeTestUtil.getOrigins(); AwQuotaManagerBridge.Origins origins = AwQuotaManagerBridgeTestUtil.getOrigins(
mActivityTestRule.getAwBrowserContext().getQuotaManagerBridge());
Assert.assertEquals(origins.mOrigins.length, 0); Assert.assertEquals(origins.mOrigins.length, 0);
Assert.assertEquals(AwContents.getNativeInstanceCount(), 0); Assert.assertEquals(AwContents.getNativeInstanceCount(), 0);
} }
......
...@@ -8,16 +8,11 @@ import android.support.test.InstrumentationRegistry; ...@@ -8,16 +8,11 @@ import android.support.test.InstrumentationRegistry;
import org.chromium.android_webview.AwQuotaManagerBridge; import org.chromium.android_webview.AwQuotaManagerBridge;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/** /**
* This class provides common methods for AwQuotaManagerBridge related tests * This class provides common methods for AwQuotaManagerBridge related tests
*/ */
public class AwQuotaManagerBridgeTestUtil { public class AwQuotaManagerBridgeTestUtil {
public static AwQuotaManagerBridge getQuotaManagerBridge() throws Exception {
return TestThreadUtils.runOnUiThreadBlocking(() -> AwQuotaManagerBridge.getInstance());
}
private static class GetOriginsCallbackHelper extends CallbackHelper { private static class GetOriginsCallbackHelper extends CallbackHelper {
private AwQuotaManagerBridge.Origins mOrigins; private AwQuotaManagerBridge.Origins mOrigins;
...@@ -32,9 +27,9 @@ public class AwQuotaManagerBridgeTestUtil { ...@@ -32,9 +27,9 @@ public class AwQuotaManagerBridgeTestUtil {
} }
} }
public static AwQuotaManagerBridge.Origins getOrigins() throws Exception { public static AwQuotaManagerBridge.Origins getOrigins(AwQuotaManagerBridge bridge)
throws Exception {
final GetOriginsCallbackHelper callbackHelper = new GetOriginsCallbackHelper(); final GetOriginsCallbackHelper callbackHelper = new GetOriginsCallbackHelper();
final AwQuotaManagerBridge bridge = getQuotaManagerBridge();
int callCount = callbackHelper.getCallCount(); int callCount = callbackHelper.getCallCount();
InstrumentationRegistry.getInstrumentation().runOnMainSync( InstrumentationRegistry.getInstrumentation().runOnMainSync(
...@@ -43,5 +38,4 @@ public class AwQuotaManagerBridgeTestUtil { ...@@ -43,5 +38,4 @@ public class AwQuotaManagerBridgeTestUtil {
return callbackHelper.getOrigins(); return callbackHelper.getOrigins();
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment