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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ChildProcessConnection.java

Issue 19803003: Introduce a delay before a high priority binding is unbound (reland). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 261
262 /** 262 /**
263 * Terminates the connection to IChildProcessService, closing all bindings. It is safe to call 263 * Terminates the connection to IChildProcessService, closing all bindings. It is safe to call
264 * this multiple times. 264 * this multiple times.
265 */ 265 */
266 void stop() { 266 void stop() {
267 synchronized(mUiThreadLock) { 267 synchronized(mUiThreadLock) {
268 mInitialBinding.unbind(); 268 mInitialBinding.unbind();
269 mStrongBinding.unbind(); 269 mStrongBinding.unbind();
270 mWaivedBinding.unbind(); 270 mWaivedBinding.unbind();
271 mAttachAsActiveCount = 0;
272 if (mService != null) { 271 if (mService != null) {
273 mService = null; 272 mService = null;
274 mPID = 0; 273 mPID = 0;
275 } 274 }
276 mConnectionParams = null; 275 mConnectionParams = null;
277 mServiceConnectComplete = false; 276 mServiceConnectComplete = false;
278 } 277 }
279 } 278 }
280 279
281 // Called on the main thread to notify that the bindService() call failed (r eturned false). 280 // Called on the main thread to notify that the bindService() call failed (r eturned false).
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 Log.w(TAG, "Failed to close FD.", ioe); 347 Log.w(TAG, "Failed to close FD.", ioe);
349 } 348 }
350 } 349 }
351 mConnectionParams = null; 350 mConnectionParams = null;
352 if (onConnectionCallback != null) { 351 if (onConnectionCallback != null) {
353 onConnectionCallback.run(); 352 onConnectionCallback.run();
354 } 353 }
355 TraceEvent.end(); 354 TraceEvent.end();
356 } 355 }
357 356
357 private static final long REMOVE_INITIAL_BINDING_DELAY_MILLIS = 1 * 1000; / / One second.
358
358 /** 359 /**
359 * Called to remove the strong binding estabilished when the connection was started. It is safe 360 * Called to remove the strong binding estabilished when the connection was started. It is safe
360 * to call this multiple times. 361 * to call this multiple times. The binding is removed after a fixed delay p eriod so that the
362 * renderer will not be killed immediately after the call.
361 */ 363 */
362 void removeInitialBinding() { 364 void removeInitialBinding() {
363 synchronized(mUiThreadLock) { 365 ThreadUtils.postOnUiThreadDelayed(new Runnable() {
klobag.chromium 2013/07/19 16:19:55 why need this?
klobag.chromium 2013/07/19 18:19:05 Just saw the comment in the other CL, thanks. Thi
ppi 2013/07/22 13:50:38 Done.
364 mInitialBinding.unbind(); 366 @Override
365 } 367 public void run() {
368 synchronized(mUiThreadLock) {
369 mInitialBinding.unbind();
370 }
371 }
372 }, REMOVE_INITIAL_BINDING_DELAY_MILLIS);
366 } 373 }
367 374
368 /** 375 /**
369 * Called when the service becomes active, ie important to the caller. This is handled by 376 * Called when the service becomes active, ie important to the caller. This is handled by
370 * setting up a binding that will make the service as important as the main process. We allow 377 * setting up a binding that will make the service as important as the main process. We allow
371 * callers to indicate the same connection as active multiple times. Instead of maintaining 378 * callers to indicate the same connection as active multiple times. Instead of maintaining
372 * multiple bindings, we count the requests and unbind when the count drops to zero. 379 * multiple bindings, we count the requests and unbind when the count drops to zero.
373 */ 380 */
374 void attachAsActive() { 381 void attachAsActive() {
375 synchronized(mUiThreadLock) { 382 synchronized(mUiThreadLock) {
376 if (mService == null) { 383 if (mService == null) {
377 Log.w(TAG, "The connection is not bound for " + mPID); 384 Log.w(TAG, "The connection is not bound for " + mPID);
378 return; 385 return;
379 } 386 }
380 if (mAttachAsActiveCount == 0) { 387 if (mAttachAsActiveCount == 0) {
381 mStrongBinding.bind(null); 388 mStrongBinding.bind(null);
382 } 389 }
383 mAttachAsActiveCount++; 390 mAttachAsActiveCount++;
384 } 391 }
385 } 392 }
386 393
394 private static final long DETACH_AS_ACTIVE_DELAY_MILLIS = 5 * 1000; // Five seconds.
395
387 /** 396 /**
388 * Called when the service is no longer considered active. 397 * Called when the service is no longer considered active. Actual binding is removed after a
398 * fixed delay period so that the renderer will not be killed immediately af ter the call.
389 */ 399 */
390 void detachAsActive() { 400 void detachAsActive() {
391 synchronized(mUiThreadLock) { 401 ThreadUtils.postOnUiThreadDelayed(new Runnable() {
392 assert mAttachAsActiveCount > 0; 402 @Override
393 if (mService == null) { 403 public void run() {
394 Log.w(TAG, "The connection is not bound for " + mPID); 404 synchronized(mUiThreadLock) {
395 return; 405 assert mAttachAsActiveCount > 0;
406 if (mService == null) {
klobag.chromium 2013/07/19 16:19:55 If you move line 405 to above 410, you can leave s
ppi 2013/07/22 13:50:38 Thanks, done (moved).
407 Log.w(TAG, "The connection is not bound for " + mPID);
408 return;
409 }
410 mAttachAsActiveCount--;
411 if (mAttachAsActiveCount == 0) {
412 mStrongBinding.unbind();
413 }
414 }
396 } 415 }
397 mAttachAsActiveCount--; 416 }, DETACH_AS_ACTIVE_DELAY_MILLIS);
398 if (mAttachAsActiveCount == 0) {
399 mStrongBinding.unbind();
400 }
401 }
402 } 417 }
403 418
404 419
405 /** 420 /**
406 * @return The connection PID, or 0 if not yet connected. 421 * @return The connection PID, or 0 if not yet connected.
407 */ 422 */
408 public int getPid() { 423 public int getPid() {
409 synchronized(mUiThreadLock) { 424 synchronized(mUiThreadLock) {
410 return mPID; 425 return mPID;
411 } 426 }
412 } 427 }
413 } 428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698