| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.ComponentCallbacks2; | 7 import android.content.ComponentCallbacks2; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.Configuration; | 9 import android.content.res.Configuration; |
| 10 import android.util.SparseArray; | 10 import android.util.SparseArray; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (mDelayedClearer != null) { | 170 if (mDelayedClearer != null) { |
| 171 LauncherThread.removeCallbacks(mDelayedClearer); | 171 LauncherThread.removeCallbacks(mDelayedClearer); |
| 172 mDelayedClearer = null; | 172 mDelayedClearer = null; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 private ModerateBindingPool mModerateBindingPool; | 177 private ModerateBindingPool mModerateBindingPool; |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * Wraps ManagedChildProcessConnection keeping track of additional informati
on needed to manage | 180 * Wraps ChildProcessConnection keeping track of additional information need
ed to manage the |
| 181 * the bindings of the connection. It goes away when the connection goes awa
y. | 181 * bindings of the connection. It goes away when the connection goes away. |
| 182 */ | 182 */ |
| 183 private class ManagedConnection { | 183 private class ManagedConnection { |
| 184 // The connection to the service. | 184 // The connection to the service. |
| 185 private final ManagedChildProcessConnection mConnection; | 185 private final ChildProcessConnection mConnection; |
| 186 | 186 |
| 187 // True iff there is a strong binding kept on the service because it is
working in | 187 // True iff there is a strong binding kept on the service because it is
working in |
| 188 // foreground. | 188 // foreground. |
| 189 private boolean mInForeground; | 189 private boolean mInForeground; |
| 190 | 190 |
| 191 // Indicates there's a pending view in this connection that's about to b
ecome foreground. | 191 // Indicates there's a pending view in this connection that's about to b
ecome foreground. |
| 192 // This currently maps exactly to the initial binding. | 192 // This currently maps exactly to the initial binding. |
| 193 private boolean mBoostPriorityForPendingViews = true; | 193 private boolean mBoostPriorityForPendingViews = true; |
| 194 | 194 |
| 195 // True iff there is a strong binding kept on the service because it was
bound for the | 195 // True iff there is a strong binding kept on the service because it was
bound for the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } else { | 227 } else { |
| 228 LauncherThread.postDelayed(doUnbind, DETACH_AS_ACTIVE_HIGH_END_D
ELAY_MILLIS); | 228 LauncherThread.postDelayed(doUnbind, DETACH_AS_ACTIVE_HIGH_END_D
ELAY_MILLIS); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * Adds connection to the moderate binding pool. No-op if the connection
has a strong | 233 * Adds connection to the moderate binding pool. No-op if the connection
has a strong |
| 234 * binding. | 234 * binding. |
| 235 * @param connection The ChildProcessConnection to add to the moderate b
inding pool. | 235 * @param connection The ChildProcessConnection to add to the moderate b
inding pool. |
| 236 */ | 236 */ |
| 237 private void addConnectionToModerateBindingPool(ManagedChildProcessConne
ction connection) { | 237 private void addConnectionToModerateBindingPool(ChildProcessConnection c
onnection) { |
| 238 if (mModerateBindingPool != null && !connection.isStrongBindingBound
()) { | 238 if (mModerateBindingPool != null && !connection.isStrongBindingBound
()) { |
| 239 mModerateBindingPool.addConnection(ManagedConnection.this); | 239 mModerateBindingPool.addConnection(ManagedConnection.this); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 /** Removes the moderate service binding. */ | 243 /** Removes the moderate service binding. */ |
| 244 private void removeModerateBinding() { | 244 private void removeModerateBinding() { |
| 245 if (!mConnection.isModerateBindingBound()) return; | 245 if (!mConnection.isModerateBindingBound()) return; |
| 246 mConnection.removeModerateBinding(); | 246 mConnection.removeModerateBinding(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 /** Adds the moderate service binding. */ | 249 /** Adds the moderate service binding. */ |
| 250 private void addModerateBinding() { | 250 private void addModerateBinding() { |
| 251 mConnection.addModerateBinding(); | 251 mConnection.addModerateBinding(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 /** | 254 /** |
| 255 * Drops the service bindings. This is used on low-end to drop bindings
of the current | 255 * Drops the service bindings. This is used on low-end to drop bindings
of the current |
| 256 * service when a new one is used in foreground. | 256 * service when a new one is used in foreground. |
| 257 */ | 257 */ |
| 258 private void dropBindings() { | 258 private void dropBindings() { |
| 259 assert mIsLowMemoryDevice; | 259 assert mIsLowMemoryDevice; |
| 260 mConnection.dropOomBindings(); | 260 mConnection.dropOomBindings(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 ManagedConnection(ManagedChildProcessConnection connection) { | 263 ManagedConnection(ChildProcessConnection connection) { |
| 264 mConnection = connection; | 264 mConnection = connection; |
| 265 } | 265 } |
| 266 | 266 |
| 267 /** | 267 /** |
| 268 * Sets the visibility of the service, adding or removing the strong bin
ding as needed. | 268 * Sets the visibility of the service, adding or removing the strong bin
ding as needed. |
| 269 */ | 269 */ |
| 270 void setPriority(boolean foreground, boolean boostForPendingViews) { | 270 void setPriority(boolean foreground, boolean boostForPendingViews) { |
| 271 // Always add bindings before removing them. | 271 // Always add bindings before removing them. |
| 272 if (!mInForeground && foreground) { | 272 if (!mInForeground && foreground) { |
| 273 addStrongBinding(); | 273 addStrongBinding(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 * Creates a testing instance of BindingManager. Testing instance will have
the unbinding delays | 338 * Creates a testing instance of BindingManager. Testing instance will have
the unbinding delays |
| 339 * set to 0, so that the tests don't need to deal with actual waiting. | 339 * set to 0, so that the tests don't need to deal with actual waiting. |
| 340 * @param isLowEndDevice true iff the created instance should apply low-end
binding policies | 340 * @param isLowEndDevice true iff the created instance should apply low-end
binding policies |
| 341 */ | 341 */ |
| 342 public static BindingManagerImpl createBindingManagerForTesting(boolean isLo
wEndDevice) { | 342 public static BindingManagerImpl createBindingManagerForTesting(boolean isLo
wEndDevice) { |
| 343 assert LauncherThread.runningOnLauncherThread(); | 343 assert LauncherThread.runningOnLauncherThread(); |
| 344 return new BindingManagerImpl(isLowEndDevice, true); | 344 return new BindingManagerImpl(isLowEndDevice, true); |
| 345 } | 345 } |
| 346 | 346 |
| 347 @Override | 347 @Override |
| 348 public void addNewConnection(int pid, ManagedChildProcessConnection connecti
on) { | 348 public void addNewConnection(int pid, ChildProcessConnection connection) { |
| 349 assert LauncherThread.runningOnLauncherThread(); | 349 assert LauncherThread.runningOnLauncherThread(); |
| 350 // This will reset the previous entry for the pid in the unlikely event
of the OS | 350 // This will reset the previous entry for the pid in the unlikely event
of the OS |
| 351 // reusing renderer pids. | 351 // reusing renderer pids. |
| 352 mManagedConnections.put(pid, new ManagedConnection(connection)); | 352 mManagedConnections.put(pid, new ManagedConnection(connection)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 @Override | 355 @Override |
| 356 public void setPriority(int pid, boolean foreground, boolean boostForPending
Views) { | 356 public void setPriority(int pid, boolean foreground, boolean boostForPending
Views) { |
| 357 assert LauncherThread.runningOnLauncherThread(); | 357 assert LauncherThread.runningOnLauncherThread(); |
| 358 ManagedConnection managedConnection = mManagedConnections.get(pid); | 358 ManagedConnection managedConnection = mManagedConnections.get(pid); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 @Override | 435 @Override |
| 436 public void releaseAllModerateBindings() { | 436 public void releaseAllModerateBindings() { |
| 437 assert LauncherThread.runningOnLauncherThread(); | 437 assert LauncherThread.runningOnLauncherThread(); |
| 438 if (mModerateBindingPool != null) { | 438 if (mModerateBindingPool != null) { |
| 439 Log.i(TAG, "Release all moderate bindings: %d", mModerateBindingPool
.size()); | 439 Log.i(TAG, "Release all moderate bindings: %d", mModerateBindingPool
.size()); |
| 440 mModerateBindingPool.removeAllConnections(); | 440 mModerateBindingPool.removeAllConnections(); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 } | 443 } |
| OLD | NEW |