Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java |
| index 5d46b9af41313935c1badb72270086742d22208b..0d1244395de75451f026937c8d592993dcad6ea4 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java |
| @@ -18,7 +18,7 @@ import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.library_loader.ProcessInitException; |
| import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| -import org.chromium.components.webrestrictions.WebRestrictionsContentProvider; |
| +import org.chromium.components.webrestrictions.browser.WebRestrictionsContentProvider; |
| import java.util.concurrent.CountDownLatch; |
| @@ -50,25 +50,36 @@ public class SupervisedUserContentProvider extends WebRestrictionsContentProvide |
| mNativeSupervisedUserContentProvider = nativeProvider; |
| } |
| - static class SupervisedUserQueryReply { |
| + static class SupervisedUserReply<T> { |
|
Bernhard Bauer
2016/04/18 14:48:34
I still think you could do this with a BlockingQue
aberent
2016/05/18 20:06:49
Done.
|
| final CountDownLatch mLatch = new CountDownLatch(1); |
| - private WebRestrictionsResult mResult; |
| + T mResult; |
| + void onQueryFinished(T reply) { |
| + // This must be called precisely once per query. |
| + assert mResult == null; |
| + assert mLatch.getCount() == 1; |
| + mResult = reply; |
| + mLatch.countDown(); |
| + } |
| + |
| + T getResult() throws InterruptedException { |
| + mLatch.await(); |
|
Bernhard Bauer
2016/04/18 14:48:34
Right now we block indefinitely, right? We might w
aberent
2016/05/18 20:06:49
Done.
|
| + return mResult; |
| + } |
| + } |
| + |
| + static class SupervisedUserQueryReply extends SupervisedUserReply<WebRestrictionsResult> { |
| // One of the following three functions must be called precisely once per query. |
| @CalledByNative("SupervisedUserQueryReply") |
| void onQueryComplete() { |
| - assert mResult == null; |
| - |
| - mResult = new WebRestrictionsResult(true, null, null); |
| - mLatch.countDown(); |
| + onQueryFinished(new WebRestrictionsResult(true, null, null)); |
| } |
| @CalledByNative("SupervisedUserQueryReply") |
| void onQueryFailed(int reason, int allowAccessRequests, int isChildAccount, |
| String profileImageUrl, String profileImageUrl2, String custodian, |
| String custodianEmail, String secondCustodian, String secondCustodianEmail) { |
| - assert mResult == null; |
| int errorInt[] = new int[] {reason, allowAccessRequests, isChildAccount}; |
| String errorString[] = new String[] { |
| profileImageUrl, |
| @@ -78,20 +89,11 @@ public class SupervisedUserContentProvider extends WebRestrictionsContentProvide |
| secondCustodian, |
| secondCustodianEmail |
| }; |
| - mResult = new WebRestrictionsResult(false, errorInt, errorString); |
| - mLatch.countDown(); |
| + onQueryFinished(new WebRestrictionsResult(false, errorInt, errorString)); |
| } |
| void onQueryFailedNoErrorData() { |
| - assert mResult == null; |
| - |
| - mResult = new WebRestrictionsResult(false, null, null); |
| - mLatch.countDown(); |
| - } |
| - |
| - WebRestrictionsResult getResult() throws InterruptedException { |
| - mLatch.await(); |
| - return mResult; |
| + onQueryFinished(new WebRestrictionsResult(false, null, null)); |
| } |
| } |
| @@ -129,21 +131,10 @@ public class SupervisedUserContentProvider extends WebRestrictionsContentProvide |
| return true; |
| } |
| - static class SupervisedUserInsertReply { |
| - final CountDownLatch mLatch = new CountDownLatch(1); |
| - boolean mResult; |
| - |
| + static class SupervisedUserInsertReply extends SupervisedUserReply<Boolean> { |
| @CalledByNative("SupervisedUserInsertReply") |
| void onInsertRequestSendComplete(boolean result) { |
| - // This must be called precisely once per query. |
| - assert mLatch.getCount() == 1; |
| - mResult = result; |
| - mLatch.countDown(); |
| - } |
| - |
| - boolean getResult() throws InterruptedException { |
| - mLatch.await(); |
| - return mResult; |
| + onQueryFinished(result); |
| } |
| } |