| OLD | NEW |
| 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; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 mCreationParams.addIntentExtras(intent); | 124 mCreationParams.addIntentExtras(intent); |
| 125 } | 125 } |
| 126 intent.setComponent(mServiceName); | 126 intent.setComponent(mServiceName); |
| 127 return intent; | 127 return intent; |
| 128 } | 128 } |
| 129 | 129 |
| 130 public ChildServiceConnection(int bindFlags) { | 130 public ChildServiceConnection(int bindFlags) { |
| 131 mBindFlags = bindFlags; | 131 mBindFlags = bindFlags; |
| 132 } | 132 } |
| 133 | 133 |
| 134 boolean bind(String[] commandLine) { | 134 boolean bind() { |
| 135 if (!mBound) { | 135 if (!mBound) { |
| 136 try { | 136 try { |
| 137 TraceEvent.begin("ChildProcessConnectionImpl.ChildServiceCon
nection.bind"); | 137 TraceEvent.begin("ChildProcessConnectionImpl.ChildServiceCon
nection.bind"); |
| 138 final Intent intent = createServiceBindIntent(); | 138 final Intent intent = createServiceBindIntent(); |
| 139 // Note, the intent may be saved and re-used by Android for
re-launching the | 139 // Note, the intent may be saved and re-used by Android for
re-launching the |
| 140 // child service. Do not pass data that is different for eac
h child; command | 140 // child service. Do not pass data that is different for eac
h child; command |
| 141 // line arguments for example. | 141 // line arguments for example. |
| 142 if (mLinkerParams != null) { | 142 if (mLinkerParams != null) { |
| 143 mLinkerParams.addIntentExtras(intent); | 143 mLinkerParams.addIntentExtras(intent); |
| 144 } | 144 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 316 } |
| 317 | 317 |
| 318 @Override | 318 @Override |
| 319 public int getPid() { | 319 public int getPid() { |
| 320 synchronized (mLock) { | 320 synchronized (mLock) { |
| 321 return mPid; | 321 return mPid; |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 @Override | 325 @Override |
| 326 public void start(String[] commandLine, ChildProcessConnection.StartCallback
startCallback) { | 326 public void start(ChildProcessConnection.StartCallback startCallback) { |
| 327 try { | 327 try { |
| 328 TraceEvent.begin("ChildProcessConnectionImpl.start"); | 328 TraceEvent.begin("ChildProcessConnectionImpl.start"); |
| 329 synchronized (mLock) { | 329 synchronized (mLock) { |
| 330 assert !ThreadUtils.runningOnUiThread(); | 330 assert !ThreadUtils.runningOnUiThread(); |
| 331 assert mConnectionParams == null : | 331 assert mConnectionParams == null : |
| 332 "setupConnection() called before start() in ChildProcess
ConnectionImpl."; | 332 "setupConnection() called before start() in ChildProcess
ConnectionImpl."; |
| 333 | 333 |
| 334 mStartCallback = startCallback; | 334 mStartCallback = startCallback; |
| 335 | 335 |
| 336 if (!mInitialBinding.bind(commandLine)) { | 336 if (!mInitialBinding.bind()) { |
| 337 Log.e(TAG, "Failed to establish the service connection."); | 337 Log.e(TAG, "Failed to establish the service connection."); |
| 338 // We have to notify the caller so that they can free-up ass
ociated resources. | 338 // We have to notify the caller so that they can free-up ass
ociated resources. |
| 339 // TODO(ppi): Can we hard-fail here? | 339 // TODO(ppi): Can we hard-fail here? |
| 340 mDeathCallback.onChildProcessDied(ChildProcessConnectionImpl
.this); | 340 mDeathCallback.onChildProcessDied(ChildProcessConnectionImpl
.this); |
| 341 } else { | 341 } else { |
| 342 mWaivedBinding.bind(null); | 342 mWaivedBinding.bind(); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 } finally { | 345 } finally { |
| 346 TraceEvent.end("ChildProcessConnectionImpl.start"); | 346 TraceEvent.end("ChildProcessConnectionImpl.start"); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 @Override | 350 @Override |
| 351 public void setupConnection( | 351 public void setupConnection( |
| 352 String[] commandLine, | 352 String[] commandLine, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } | 486 } |
| 487 | 487 |
| 488 @Override | 488 @Override |
| 489 public void addStrongBinding() { | 489 public void addStrongBinding() { |
| 490 synchronized (mLock) { | 490 synchronized (mLock) { |
| 491 if (mService == null) { | 491 if (mService == null) { |
| 492 Log.w(TAG, "The connection is not bound for %d", mPid); | 492 Log.w(TAG, "The connection is not bound for %d", mPid); |
| 493 return; | 493 return; |
| 494 } | 494 } |
| 495 if (mStrongBindingCount == 0) { | 495 if (mStrongBindingCount == 0) { |
| 496 mStrongBinding.bind(null); | 496 mStrongBinding.bind(); |
| 497 } | 497 } |
| 498 mStrongBindingCount++; | 498 mStrongBindingCount++; |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 @Override | 502 @Override |
| 503 public void removeStrongBinding() { | 503 public void removeStrongBinding() { |
| 504 synchronized (mLock) { | 504 synchronized (mLock) { |
| 505 if (mService == null) { | 505 if (mService == null) { |
| 506 Log.w(TAG, "The connection is not bound for %d", mPid); | 506 Log.w(TAG, "The connection is not bound for %d", mPid); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 521 } | 521 } |
| 522 } | 522 } |
| 523 | 523 |
| 524 @Override | 524 @Override |
| 525 public void addModerateBinding() { | 525 public void addModerateBinding() { |
| 526 synchronized (mLock) { | 526 synchronized (mLock) { |
| 527 if (mService == null) { | 527 if (mService == null) { |
| 528 Log.w(TAG, "The connection is not bound for %d", mPid); | 528 Log.w(TAG, "The connection is not bound for %d", mPid); |
| 529 return; | 529 return; |
| 530 } | 530 } |
| 531 mModerateBinding.bind(null); | 531 mModerateBinding.bind(); |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 | 534 |
| 535 @Override | 535 @Override |
| 536 public void removeModerateBinding() { | 536 public void removeModerateBinding() { |
| 537 synchronized (mLock) { | 537 synchronized (mLock) { |
| 538 if (mService == null) { | 538 if (mService == null) { |
| 539 Log.w(TAG, "The connection is not bound for %d", mPid); | 539 Log.w(TAG, "The connection is not bound for %d", mPid); |
| 540 return; | 540 return; |
| 541 } | 541 } |
| 542 mModerateBinding.unbind(); | 542 mModerateBinding.unbind(); |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 @VisibleForTesting | 546 @VisibleForTesting |
| 547 public boolean crashServiceForTesting() throws RemoteException { | 547 public boolean crashServiceForTesting() throws RemoteException { |
| 548 try { | 548 try { |
| 549 mService.crashIntentionallyForTesting(); | 549 mService.crashIntentionallyForTesting(); |
| 550 } catch (DeadObjectException e) { | 550 } catch (DeadObjectException e) { |
| 551 return true; | 551 return true; |
| 552 } | 552 } |
| 553 return false; | 553 return false; |
| 554 } | 554 } |
| 555 | 555 |
| 556 @VisibleForTesting | 556 @VisibleForTesting |
| 557 public boolean isConnected() { | 557 public boolean isConnected() { |
| 558 return mService != null; | 558 return mService != null; |
| 559 } | 559 } |
| 560 } | 560 } |
| OLD | NEW |