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