Commit 172f7207 authored by dgn's avatar dgn Committed by Commit bot

Move some calls from the Android UI thread to the Chrome one

Some callbacks (from AsyncTasks, broadcasts reciever and other
sources) are received on the Android UI thread but the code
expects to run on the Chrome UI thread.

BUG=568602
TBR=atwilson@chromium.org

Review URL: https://codereview.chromium.org/1514903002

Cr-Commit-Position: refs/heads/master@{#364476}
parent 7b4457e0
......@@ -640,7 +640,12 @@ public class AwContents implements SmartClipProvider,
if (isDestroyed(NO_WARN)) return;
boolean visibleRectEmpty = getGlobalVisibleRect().isEmpty();
final boolean visible = mIsViewVisible && mIsWindowVisible && !visibleRectEmpty;
nativeTrimMemory(mNativeAwContents, level, visible);
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
nativeTrimMemory(mNativeAwContents, level, visible);
}
});
}
@Override
......
......@@ -15,6 +15,7 @@ import android.os.Handler;
import android.util.Log;
import org.chromium.base.CommandLine;
import org.chromium.base.ThreadUtils;
import java.lang.reflect.Field;
......@@ -108,21 +109,23 @@ public final class AwDataReductionProxyManager {
private static void applyDataReductionProxySettingsAsync(
final Context context, final String key) {
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
protected Boolean doInBackground(Void... params) {
return isDataReductionProxyEnabled(context);
public void run() {
final boolean enabled = isDataReductionProxyEnabled(context);
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (enabled) {
// Set the data reduction proxy key.
AwContentsStatics.setDataReductionProxyKey(key);
}
AwContentsStatics.setDataReductionProxyEnabled(enabled);
}
});
}
@Override
protected void onPostExecute(Boolean enabled) {
if (enabled) {
// Set the data reduction proxy key.
AwContentsStatics.setDataReductionProxyKey(key);
}
AwContentsStatics.setDataReductionProxyEnabled(enabled);
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
});
}
private static boolean isDataReductionProxyEnabled(Context context) {
......
......@@ -11,11 +11,13 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.preference.PreferenceManager;
import android.util.Base64;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
......@@ -75,8 +77,10 @@ public abstract class AbstractAppRestrictionsProvider extends PolicyProvider {
public void startListeningForPolicyChanges() {
String changeIntentAction = getRestrictionChangeIntentAction();
if (changeIntentAction == null) return;
mContext.registerReceiver(
mAppRestrictionsChangedReceiver, new IntentFilter(changeIntentAction));
mContext.registerReceiver(mAppRestrictionsChangedReceiver,
new IntentFilter(changeIntentAction), null,
new Handler(ThreadUtils.getUiThreadLooper()));
}
/**
......@@ -95,21 +99,22 @@ public abstract class AbstractAppRestrictionsProvider extends PolicyProvider {
notifySettingsAvailable(cachedResult);
}
new AsyncTask<Void, Void, Bundle>() {
mExecutor.execute(new Runnable() {
@Override
protected Bundle doInBackground(Void... params) {
public void run() {
long startTime = System.currentTimeMillis();
Bundle bundle = getApplicationRestrictions(mContext.getPackageName());
final Bundle bundle = getApplicationRestrictions(mContext.getPackageName());
recordStartTimeHistogram(startTime);
return bundle;
}
@Override
protected void onPostExecute(Bundle result) {
cachePolicies(result);
notifySettingsAvailable(result);
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
cachePolicies(bundle);
notifySettingsAvailable(bundle);
}
});
}
}.executeOnExecutor(mExecutor);
});
}
@Override
......
......@@ -6,6 +6,7 @@ package org.chromium.policy;
import android.os.Bundle;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
/**
......@@ -18,6 +19,7 @@ public abstract class PolicyProvider {
protected PolicyProvider() {}
public void notifySettingsAvailable(Bundle settings) {
ThreadUtils.assertOnUiThread();
mCombinedPolicyProvider.onSettingsAvailable(mSource, settings);
}
......
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