Commit e77291a7 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

android: Remove initial binding

Use moderate binding instead which has the exact same flags, and also
supports refcounting.

Bug: 813232
Change-Id: I22a56345a835c5916e6604bfb7cb2fc5cae6ceb5
Reviewed-on: https://chromium-review.googlesource.com/1033799Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554795}
parent 41a2a781
......@@ -199,14 +199,12 @@ public class ChildProcessConnection {
// Process ID of the corresponding child process.
private int mPid;
// Inital moderate binding.
private final ChildServiceConnection mInitialBinding;
// Strong binding will make the service priority equal to the priority of the activity.
private final ChildServiceConnection mStrongBinding;
// Moderate binding will make the service priority equal to the priority of a visible process
// while the app is in the foreground.
// This is also used as the initial binding before any priorities are set.
private final ChildServiceConnection mModerateBinding;
// Low priority binding maintained in the entire lifetime of the connection, i.e. between calls
......@@ -287,7 +285,6 @@ public class ChildProcessConnection {
int defaultFlags = Context.BIND_AUTO_CREATE
| (bindAsExternalService ? Context.BIND_EXTERNAL_SERVICE : 0);
mInitialBinding = connectionFactory.createConnection(intent, defaultFlags, delegate);
mModerateBinding = connectionFactory.createConnection(intent, defaultFlags, delegate);
mStrongBinding = connectionFactory.createConnection(
intent, defaultFlags | Context.BIND_IMPORTANT, delegate);
......@@ -520,7 +517,13 @@ public class ChildProcessConnection {
assert isRunningOnLauncherThread();
assert !mUnbound;
boolean success = useStrongBinding ? mStrongBinding.bind() : mInitialBinding.bind();
boolean success;
if (useStrongBinding) {
success = mStrongBinding.bind();
} else {
mModerateBindingCount++;
success = mModerateBinding.bind();
}
if (!success) return false;
updateWaivedBoundOnlyState();
......@@ -537,7 +540,6 @@ public class ChildProcessConnection {
mStrongBinding.unbind();
mWaivedBinding.unbind();
mModerateBinding.unbind();
mInitialBinding.unbind();
// Note that we don't update the waived bound only state here as to preserve the state when
// disconnected.
......@@ -548,28 +550,11 @@ public class ChildProcessConnection {
}
}
public boolean isInitialBindingBound() {
assert isRunningOnLauncherThread();
return mInitialBinding.isBound();
}
public void addInitialBinding() {
assert isRunningOnLauncherThread();
mInitialBinding.bind();
updateWaivedBoundOnlyState();
}
public boolean isStrongBindingBound() {
assert isRunningOnLauncherThread();
return mStrongBinding.isBound();
}
public void removeInitialBinding() {
assert isRunningOnLauncherThread();
mInitialBinding.unbind();
updateWaivedBoundOnlyState();
}
public void addStrongBinding() {
assert isRunningOnLauncherThread();
if (!isConnected()) {
......@@ -650,11 +635,10 @@ public class ChildProcessConnection {
return mKilledByUs;
}
// Should be called every time the mInitialBinding or mStrongBinding are bound/unbound.
// Should be called every time the mModerateBinding or mStrongBinding are bound/unbound.
private void updateWaivedBoundOnlyState() {
if (!mUnbound) {
mWaivedBoundOnly = !mInitialBinding.isBound() && !mStrongBinding.isBound()
&& !mModerateBinding.isBound();
mWaivedBoundOnly = !mStrongBinding.isBound() && !mModerateBinding.isBound();
}
}
......
......@@ -193,7 +193,7 @@ public class ChildProcessConnectionTest {
ChildProcessConnection connection = createDefaultTestConnection();
assertNotNull(mFirstServiceConnection);
connection.start(false /* useStrongBinding */, mServiceCallback);
Assert.assertTrue(connection.isInitialBindingBound());
Assert.assertTrue(connection.isModerateBindingBound());
Assert.assertFalse(connection.didOnServiceConnectedForTesting());
verify(mServiceCallback, never()).onChildStarted();
verify(mServiceCallback, never()).onChildStartFailed(any());
......@@ -216,7 +216,7 @@ public class ChildProcessConnectionTest {
doReturn(false).when(mFirstServiceConnection).bind();
connection.start(false /* useStrongBinding */, mServiceCallback);
Assert.assertFalse(connection.isInitialBindingBound());
Assert.assertFalse(connection.isModerateBindingBound());
Assert.assertFalse(connection.didOnServiceConnectedForTesting());
verify(mServiceCallback, never()).onChildStarted();
verify(mServiceCallback, never()).onChildStartFailed(any());
......
......@@ -484,7 +484,7 @@ public class ChildProcessLauncherHelper {
manager.increaseRecency(connection);
}
}
if (!mBoostPriorityForPendingViews && boostForPendingViews) connection.addInitialBinding();
if (!mBoostPriorityForPendingViews && boostForPendingViews) connection.addModerateBinding();
if (mImportance != importance) {
switch (importance) {
case ChildProcessImportance.NORMAL:
......@@ -506,7 +506,7 @@ public class ChildProcessLauncherHelper {
if (mForeground && !foreground) connection.removeStrongBinding();
if (mBoostPriorityForPendingViews && !boostForPendingViews) {
connection.removeInitialBinding();
connection.removeModerateBinding();
}
if (mRanking != null) {
......
......@@ -57,7 +57,7 @@ public class ChildProcessLauncherIntegrationTest {
}
private static class TestChildProcessConnection extends ChildProcessConnection {
private RuntimeException mRemovedBothInitialAndStrongBinding;
private RuntimeException mRemovedBothModerateAndStrongBinding;
public TestChildProcessConnection(Context context, ComponentName serviceName,
boolean bindToCaller, boolean bindAsExternalService,
......@@ -69,30 +69,31 @@ public class ChildProcessLauncherIntegrationTest {
@Override
protected void unbind() {
super.unbind();
if (mRemovedBothInitialAndStrongBinding == null) {
mRemovedBothInitialAndStrongBinding = new RuntimeException("unbind");
if (mRemovedBothModerateAndStrongBinding == null) {
mRemovedBothModerateAndStrongBinding = new RuntimeException("unbind");
}
}
@Override
public void removeInitialBinding() {
super.removeInitialBinding();
if (mRemovedBothInitialAndStrongBinding == null && !isStrongBindingBound()) {
mRemovedBothInitialAndStrongBinding = new RuntimeException("removeInitialBinding");
public void removeModerateBinding() {
super.removeModerateBinding();
if (mRemovedBothModerateAndStrongBinding == null && !isStrongBindingBound()) {
mRemovedBothModerateAndStrongBinding =
new RuntimeException("removeModerateBinding");
}
}
@Override
public void removeStrongBinding() {
super.removeStrongBinding();
if (mRemovedBothInitialAndStrongBinding == null && !isInitialBindingBound()) {
mRemovedBothInitialAndStrongBinding = new RuntimeException("removeStrongBinding");
if (mRemovedBothModerateAndStrongBinding == null && !isModerateBindingBound()) {
mRemovedBothModerateAndStrongBinding = new RuntimeException("removeStrongBinding");
}
}
public void throwIfDroppedBothInitialAndStrongBinding() {
if (mRemovedBothInitialAndStrongBinding != null) {
throw mRemovedBothInitialAndStrongBinding;
public void throwIfDroppedBothModerateAndStrongBinding() {
if (mRemovedBothModerateAndStrongBinding != null) {
throw mRemovedBothModerateAndStrongBinding;
}
}
}
......@@ -119,7 +120,7 @@ public class ChildProcessLauncherIntegrationTest {
@Override
public void run() {
Assert.assertEquals(1, connections.size());
connections.get(0).throwIfDroppedBothInitialAndStrongBinding();
connections.get(0).throwIfDroppedBothModerateAndStrongBinding();
}
});
......@@ -130,7 +131,7 @@ public class ChildProcessLauncherIntegrationTest {
public void run() {
Assert.assertEquals(2, connections.size());
// connections.get(0).didDropBothInitialAndImportantBindings();
connections.get(1).throwIfDroppedBothInitialAndStrongBinding();
connections.get(1).throwIfDroppedBothModerateAndStrongBinding();
}
});
}
......
......@@ -47,9 +47,8 @@ public class BindingManagerImplTest {
null /* serviceBundle */);
connection.setPid(pid);
connection.start(false /* useStrongBinding */, null /* serviceCallback */);
if (manager != null) {
manager.increaseRecency(connection);
}
manager.increaseRecency(connection);
connection.removeModerateBinding(); // Remove initial binding.
return connection;
}
......
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