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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.ComponentName; 7 import android.content.ComponentName;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.ServiceConnection; 10 import android.content.ServiceConnection;
11 import android.os.Bundle; 11 import android.os.Bundle;
12 import android.os.DeadObjectException; 12 import android.os.DeadObjectException;
13 import android.os.IBinder; 13 import android.os.IBinder;
14 import android.os.RemoteException; 14 import android.os.RemoteException;
15 import android.util.Log;
16 15
17 import org.chromium.base.CpuFeatures; 16 import org.chromium.base.CpuFeatures;
17 import org.chromium.base.Log;
18 import org.chromium.base.ThreadUtils; 18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.TraceEvent; 19 import org.chromium.base.TraceEvent;
20 import org.chromium.base.VisibleForTesting; 20 import org.chromium.base.VisibleForTesting;
21 import org.chromium.base.library_loader.Linker; 21 import org.chromium.base.library_loader.Linker;
22 import org.chromium.content.app.ChildProcessService; 22 import org.chromium.content.app.ChildProcessService;
23 import org.chromium.content.app.ChromiumLinkerParams; 23 import org.chromium.content.app.ChromiumLinkerParams;
24 import org.chromium.content.common.IChildProcessCallback; 24 import org.chromium.content.common.IChildProcessCallback;
25 import org.chromium.content.common.IChildProcessService; 25 import org.chromium.content.common.IChildProcessService;
26 26
27 import java.io.IOException; 27 import java.io.IOException;
(...skipping 28 matching lines...) Expand all
56 // Strong binding will make the service priority equal to the priority of th e activity. We want 56 // Strong binding will make the service priority equal to the priority of th e activity. We want
57 // the OS to be able to kill background renderers as it kills other backgrou nd apps, so strong 57 // the OS to be able to kill background renderers as it kills other backgrou nd apps, so strong
58 // bindings are maintained only for services that are active at the moment ( between 58 // bindings are maintained only for services that are active at the moment ( between
59 // addStrongBinding() and removeStrongBinding()). 59 // addStrongBinding() and removeStrongBinding()).
60 private ChildServiceConnection mStrongBinding = null; 60 private ChildServiceConnection mStrongBinding = null;
61 // Low priority binding maintained in the entire lifetime of the connection, i.e. between calls 61 // Low priority binding maintained in the entire lifetime of the connection, i.e. between calls
62 // to start() and stop(). 62 // to start() and stop().
63 private ChildServiceConnection mWaivedBinding = null; 63 private ChildServiceConnection mWaivedBinding = null;
64 // Incremented on addStrongBinding(), decremented on removeStrongBinding(). 64 // Incremented on addStrongBinding(), decremented on removeStrongBinding().
65 private int mStrongBindingCount = 0; 65 private int mStrongBindingCount = 0;
66 // Moderate binding will make the service priority equal to the priority of a visible process
67 // while the app is in the foreground. It will stay bound only while the app is in the
68 // foreground to protect a background process from the system out-of-memory killer.
69 private ChildServiceConnection mModerateBinding = null;
66 70
67 // Linker-related parameters. 71 // Linker-related parameters.
68 private ChromiumLinkerParams mLinkerParams = null; 72 private ChromiumLinkerParams mLinkerParams = null;
69 73
70 private final boolean mAlwaysInForeground; 74 private final boolean mAlwaysInForeground;
71 75
72 private static final String TAG = "ChildProcessConnection"; 76 private static final String TAG = "cr.ChildProcessConnect";
73 77
74 private static class ConnectionParams { 78 private static class ConnectionParams {
75 final String[] mCommandLine; 79 final String[] mCommandLine;
76 final FileDescriptorInfo[] mFilesToBeMapped; 80 final FileDescriptorInfo[] mFilesToBeMapped;
77 final IChildProcessCallback mCallback; 81 final IChildProcessCallback mCallback;
78 final Bundle mSharedRelros; 82 final Bundle mSharedRelros;
79 83
80 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap ped, 84 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap ped,
81 IChildProcessCallback callback, Bundle sharedRelros) { 85 IChildProcessCallback callback, Bundle sharedRelros) {
82 mCommandLine = commandLine; 86 mCommandLine = commandLine;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 mServiceClass = serviceClass; 209 mServiceClass = serviceClass;
206 mLinkerParams = chromiumLinkerParams; 210 mLinkerParams = chromiumLinkerParams;
207 mAlwaysInForeground = alwaysInForeground; 211 mAlwaysInForeground = alwaysInForeground;
208 int initialFlags = Context.BIND_AUTO_CREATE; 212 int initialFlags = Context.BIND_AUTO_CREATE;
209 if (mAlwaysInForeground) initialFlags |= Context.BIND_IMPORTANT; 213 if (mAlwaysInForeground) initialFlags |= Context.BIND_IMPORTANT;
210 mInitialBinding = new ChildServiceConnection(initialFlags); 214 mInitialBinding = new ChildServiceConnection(initialFlags);
211 mStrongBinding = new ChildServiceConnection( 215 mStrongBinding = new ChildServiceConnection(
212 Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT); 216 Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT);
213 mWaivedBinding = new ChildServiceConnection( 217 mWaivedBinding = new ChildServiceConnection(
214 Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY); 218 Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY);
219 mModerateBinding = new ChildServiceConnection(Context.BIND_AUTO_CREATE);
215 } 220 }
216 221
217 @Override 222 @Override
218 public int getServiceNumber() { 223 public int getServiceNumber() {
219 return mServiceNumber; 224 return mServiceNumber;
220 } 225 }
221 226
222 @Override 227 @Override
223 public boolean isInSandbox() { 228 public boolean isInSandbox() {
224 return mInSandbox; 229 return mInSandbox;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 295 }
291 } 296 }
292 } 297 }
293 298
294 @Override 299 @Override
295 public void stop() { 300 public void stop() {
296 synchronized (mLock) { 301 synchronized (mLock) {
297 mInitialBinding.unbind(); 302 mInitialBinding.unbind();
298 mStrongBinding.unbind(); 303 mStrongBinding.unbind();
299 mWaivedBinding.unbind(); 304 mWaivedBinding.unbind();
305 mModerateBinding.unbind();
300 mStrongBindingCount = 0; 306 mStrongBindingCount = 0;
301 if (mService != null) { 307 if (mService != null) {
302 mService = null; 308 mService = null;
303 } 309 }
304 mConnectionParams = null; 310 mConnectionParams = null;
305 } 311 }
306 } 312 }
307 313
308 /** 314 /**
309 * Called after the connection parameters have been set (in setupConnection( )) *and* a 315 * Called after the connection parameters have been set (in setupConnection( )) *and* a
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 397 }
392 398
393 @Override 399 @Override
394 public void dropOomBindings() { 400 public void dropOomBindings() {
395 synchronized (mLock) { 401 synchronized (mLock) {
396 assert !mAlwaysInForeground; 402 assert !mAlwaysInForeground;
397 mInitialBinding.unbind(); 403 mInitialBinding.unbind();
398 404
399 mStrongBindingCount = 0; 405 mStrongBindingCount = 0;
400 mStrongBinding.unbind(); 406 mStrongBinding.unbind();
407
408 mModerateBinding.unbind();
401 } 409 }
402 } 410 }
403 411
404 @Override 412 @Override
405 public void addStrongBinding() { 413 public void addStrongBinding() {
406 synchronized (mLock) { 414 synchronized (mLock) {
407 if (mService == null) { 415 if (mService == null) {
408 Log.w(TAG, "The connection is not bound for " + mPid); 416 Log.w(TAG, "The connection is not bound for " + mPid);
409 return; 417 return;
410 } 418 }
(...skipping 12 matching lines...) Expand all
423 return; 431 return;
424 } 432 }
425 assert mStrongBindingCount > 0; 433 assert mStrongBindingCount > 0;
426 mStrongBindingCount--; 434 mStrongBindingCount--;
427 if (mStrongBindingCount == 0) { 435 if (mStrongBindingCount == 0) {
428 mStrongBinding.unbind(); 436 mStrongBinding.unbind();
429 } 437 }
430 } 438 }
431 } 439 }
432 440
441 @Override
442 public boolean isModerateBindingBound() {
443 synchronized (mLock) {
444 return mModerateBinding.isBound();
445 }
446 }
447
448 @Override
449 public void addModerateBinding() {
450 synchronized (mLock) {
451 if (mService == null) {
452 Log.w(TAG, "The connection is not bound for " + mPid);
453 return;
454 }
455 mModerateBinding.bind(null);
456 }
457 }
458
459 @Override
460 public void removeModerateBinding() {
461 synchronized (mLock) {
462 if (mService == null) {
463 Log.w(TAG, "The connection is not bound for " + mPid);
464 return;
465 }
466 mModerateBinding.unbind();
467 }
468 }
469
433 @VisibleForTesting 470 @VisibleForTesting
434 public boolean crashServiceForTesting() throws RemoteException { 471 public boolean crashServiceForTesting() throws RemoteException {
435 try { 472 try {
436 mService.crashIntentionallyForTesting(); 473 mService.crashIntentionallyForTesting();
437 } catch (DeadObjectException e) { 474 } catch (DeadObjectException e) {
438 return true; 475 return true;
439 } 476 }
440 return false; 477 return false;
441 } 478 }
442 479
443 @VisibleForTesting 480 @VisibleForTesting
444 public boolean isConnected() { 481 public boolean isConnected() {
445 return mService != null; 482 return mService != null;
446 } 483 }
447 } 484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698