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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java

Issue 1146813010: Introduce moderate binding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments Created 5 years, 6 months 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: content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
index e134d3625d3ab16879dfe1c59ed732eb93b97a4f..8170a70bc3c757b7599f7856764755007cbb5132 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
@@ -12,9 +12,9 @@ import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.os.RemoteException;
-import android.util.Log;
import org.chromium.base.CpuFeatures;
+import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent;
import org.chromium.base.VisibleForTesting;
@@ -63,13 +63,17 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
private ChildServiceConnection mWaivedBinding = null;
// Incremented on addStrongBinding(), decremented on removeStrongBinding().
private int mStrongBindingCount = 0;
+ // Moderate binding will make the service priority equal to the priority of a visible process
+ // while the app is in the foreground. It will stay bound only while the app is in the
+ // foreground to protect a background process from the system out-of-memory killer.
+ private ChildServiceConnection mModerateBinding = null;
// Linker-related parameters.
private ChromiumLinkerParams mLinkerParams = null;
private final boolean mAlwaysInForeground;
- private static final String TAG = "ChildProcessConnection";
+ private static final String TAG = "cr.ChildProcessConnect";
private static class ConnectionParams {
final String[] mCommandLine;
@@ -212,6 +216,7 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT);
mWaivedBinding = new ChildServiceConnection(
Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY);
+ mModerateBinding = new ChildServiceConnection(Context.BIND_AUTO_CREATE);
}
@Override
@@ -297,6 +302,7 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
mInitialBinding.unbind();
mStrongBinding.unbind();
mWaivedBinding.unbind();
+ mModerateBinding.unbind();
mStrongBindingCount = 0;
if (mService != null) {
mService = null;
@@ -398,6 +404,8 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
mStrongBindingCount = 0;
mStrongBinding.unbind();
+
+ mModerateBinding.unbind();
}
}
@@ -430,6 +438,35 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
}
}
+ @Override
+ public boolean isModerateBindingBound() {
+ synchronized (mLock) {
+ return mModerateBinding.isBound();
+ }
+ }
+
+ @Override
+ public void addModerateBinding() {
+ synchronized (mLock) {
+ if (mService == null) {
+ Log.w(TAG, "The connection is not bound for " + mPid);
+ return;
+ }
+ mModerateBinding.bind(null);
+ }
+ }
+
+ @Override
+ public void removeModerateBinding() {
+ synchronized (mLock) {
+ if (mService == null) {
+ Log.w(TAG, "The connection is not bound for " + mPid);
+ return;
+ }
+ mModerateBinding.unbind();
+ }
+ }
+
@VisibleForTesting
public boolean crashServiceForTesting() throws RemoteException {
try {

Powered by Google App Engine
This is Rietveld 408576698