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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java

Issue 1452603002: Supervised user web restrictions content provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add GN build of junit tests. Created 5 years 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: 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
new file mode 100644
index 0000000000000000000000000000000000000000..ae5e479212a97f154131e06881fc71f4bb6983fb
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProvider.java
@@ -0,0 +1,133 @@
+// Copyright 2015 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.chrome.browser.superviseduser;
+
+import android.os.Bundle;
+import android.util.Pair;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.VisibleForTesting;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.library_loader.LibraryProcessType;
+import org.chromium.base.library_loader.ProcessInitException;
+import org.chromium.components.webrestriction.WebRestrictionsContentProvider;
+import org.chromium.content.browser.BrowserStartupController;
+
+import java.util.concurrent.SynchronousQueue;
+
+/**
+ * Content provider for telling other apps (e.g. WebView apps) about the supervised user URL filter.
+ */
+public class SupervisedUserContentProvider extends WebRestrictionsContentProvider {
+ private long mNativeSupervisedUserContentProvider = 0;
+
+ private SynchronousQueue<Pair<Boolean, String>> mResultQueue;
Bernhard Bauer 2015/12/14 17:58:37 Can you make this final?
aberent 2015/12/16 15:20:37 Done.
+
+ public SupervisedUserContentProvider() {
+ super();
Bernhard Bauer 2015/12/14 17:58:37 This can be removed, right?
aberent 2015/12/16 15:20:37 Done.
+ mResultQueue = new SynchronousQueue<Pair<Boolean, String>>();
Bernhard Bauer 2015/12/14 17:58:37 Initialize this where it's declared?
aberent 2015/12/16 15:20:37 Done.
+ }
+
+ private long getSupervisedUserContentProvider() throws ProcessInitException {
+ if (mNativeSupervisedUserContentProvider != 0) {
+ return mNativeSupervisedUserContentProvider;
+ }
+
+ BrowserStartupController.get(getContext(), LibraryProcessType.PROCESS_BROWSER)
+ .startBrowserProcessesSync(false);
+
+ mNativeSupervisedUserContentProvider = nativeCreateSupervisedUserContentProvider();
+ return mNativeSupervisedUserContentProvider;
+ }
+
+ @VisibleForTesting
+ void setNativeSupervisedUserContentProviderForTesting(long nativeProvider) {
+ mNativeSupervisedUserContentProvider = nativeProvider;
+ }
+
+ @Override
+ protected synchronized Pair<Boolean, String> shouldProceed(final String url) {
Bernhard Bauer 2015/12/14 17:58:37 Synchronize on a member variable of type Object. D
aberent 2015/12/16 15:20:37 Done.
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ nativeShouldProceed(getSupervisedUserContentProvider(), url);
+ } catch (ProcessInitException e) {
+ onQueryComplete(false, null);
+ }
+ }
+ });
+ try {
+ return mResultQueue.take();
Bernhard Bauer 2015/12/14 17:58:37 Can you add a comment that this will block until a
aberent 2015/12/16 15:20:37 Done.
+ } catch (InterruptedException e) {
+ return new Pair<Boolean, String>(false, null);
+ }
+ }
+
+ @Override
+ protected boolean canInsert() {
+ // Chromium always allows insertion requests.
+ return true;
+ }
+
+ @Override
+ protected void requestInsert(final String url) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ nativeRequestInsert(getSupervisedUserContentProvider(), url);
+ } catch (ProcessInitException e) {
+ // There is no way of returning anything sensible here, so ignore the error and
+ // do nothing.
+ }
+ }
+ });
+ }
+
+ @VisibleForTesting
+ @Override
+ public Bundle call(String method, String arg, Bundle bundle) {
+ if (method == "setFilterForTesting") setFilterForTesting();
+ return null;
+ }
+
+ @VisibleForTesting
+ void setFilterForTesting() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ nativeSetFilterForTesting(getSupervisedUserContentProvider());
+ } catch (ProcessInitException e) {
+ // There is no way of returning anything sensible here, so ignore the error and
+ // do nothing.
+ }
+ }
+ });
+ }
+
+ @VisibleForTesting
+ @CalledByNative
+ void onQueryComplete(boolean result, String errorMessage) {
+ mResultQueue.add(new Pair<Boolean, String>(result, errorMessage));
+ }
+
+ @VisibleForTesting
+ @CalledByNative
+ void onSupervisedUserFilterUpdated() {
+ onFilterChanged();
+ }
+
+ @VisibleForTesting native long nativeCreateSupervisedUserContentProvider();
+
+ @VisibleForTesting
+ native void nativeShouldProceed(long nativeSupervisedUserContentProvider, String url);
+
+ @VisibleForTesting
+ native void nativeRequestInsert(long nativeSupervisedUserContentProvider, String url);
+
+ private native void nativeSetFilterForTesting(long nativeSupervisedUserContentProvider);
+}

Powered by Google App Engine
This is Rietveld 408576698