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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java

Issue 2822803002: android: Post onServiceConnected to launcher thread (Closed)
Patch Set: comment Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
index ecbafeff7589a90e92d9dd9b02755b090328e1ae..710741b69c86a045512bf88f0459e6b9fd7934e7 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java
@@ -159,61 +159,15 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
}
@Override
- public void onServiceConnected(ComponentName className, IBinder service) {
- synchronized (mLock) {
- // A flag from the parent class ensures we run the post-connection logic only once
- // (instead of once per each ChildServiceConnection).
- if (mDidOnServiceConnected) {
- return;
- }
- try {
- TraceEvent.begin(
- "ChildProcessConnectionImpl.ChildServiceConnection.onServiceConnected");
- mDidOnServiceConnected = true;
- mService = IChildProcessService.Stub.asInterface(service);
-
- StartCallback startCallback = mStartCallback;
- mStartCallback = null;
-
- final boolean bindCheck =
- mCreationParams != null && mCreationParams.getBindToCallerCheck();
- boolean boundToUs = false;
- try {
- boundToUs = bindCheck ? mService.bindToCaller() : true;
- } catch (RemoteException ex) {
- // Do not trigger the StartCallback here, since the service is already
- // dead and the DeathCallback will run from onServiceDisconnected().
- Log.e(TAG, "Failed to bind service to connection.", ex);
- return;
- }
-
- if (startCallback != null) {
- if (boundToUs) {
- startCallback.onChildStarted();
- } else {
- startCallback.onChildStartFailed();
- }
- }
-
- if (!boundToUs) {
- return;
- }
-
- mServiceConnectComplete = true;
-
- // Run the setup if the connection parameters have already been provided. If
- // not, doConnectionSetupLocked() will be called from setupConnection().
- if (mConnectionParams != null) {
- doConnectionSetupLocked();
- }
- } finally {
- TraceEvent.end(
- "ChildProcessConnectionImpl.ChildServiceConnection.onServiceConnected");
+ public void onServiceConnected(ComponentName className, final IBinder service) {
+ LauncherThread.post(new Runnable() {
+ @Override
+ public void run() {
+ ChildProcessConnectionImpl.this.onServiceConnectedOnLauncherThread(service);
}
- }
+ });
}
-
// Called on the main thread to notify that the child service did not disconnect gracefully.
@Override
public void onServiceDisconnected(ComponentName className) {
@@ -339,6 +293,7 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
@Override
public void setupConnection(String[] commandLine, FileDescriptorInfo[] filesToBeMapped,
@Nullable IBinder callback, ConnectionCallback connectionCallback) {
+ assert LauncherThread.runningOnLauncherThread();
synchronized (mLock) {
assert mConnectionParams == null;
if (mServiceDisconnected) {
@@ -376,6 +331,61 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
}
}
+ private void onServiceConnectedOnLauncherThread(IBinder service) {
+ assert LauncherThread.runningOnLauncherThread();
+ synchronized (mLock) {
+ // A flag from the parent class ensures we run the post-connection logic only once
+ // (instead of once per each ChildServiceConnection).
+ if (mDidOnServiceConnected) {
+ return;
+ }
+ try {
+ TraceEvent.begin(
+ "ChildProcessConnectionImpl.ChildServiceConnection.onServiceConnected");
+ mDidOnServiceConnected = true;
+ mService = IChildProcessService.Stub.asInterface(service);
+
+ StartCallback startCallback = mStartCallback;
+ mStartCallback = null;
+
+ final boolean bindCheck =
+ mCreationParams != null && mCreationParams.getBindToCallerCheck();
+ boolean boundToUs = false;
+ try {
+ boundToUs = bindCheck ? mService.bindToCaller() : true;
+ } catch (RemoteException ex) {
+ // Do not trigger the StartCallback here, since the service is already
+ // dead and the DeathCallback will run from onServiceDisconnected().
+ Log.e(TAG, "Failed to bind service to connection.", ex);
+ return;
+ }
+
+ if (startCallback != null) {
+ if (boundToUs) {
+ startCallback.onChildStarted();
+ } else {
+ startCallback.onChildStartFailed();
+ }
+ }
+
+ if (!boundToUs) {
+ return;
+ }
+
+ mServiceConnectComplete = true;
+
+ // Run the setup if the connection parameters have already been provided. If
+ // not, doConnectionSetupLocked() will be called from setupConnection().
+ if (mConnectionParams != null) {
+ doConnectionSetupLocked();
+ }
+ } finally {
+ TraceEvent.end(
+ "ChildProcessConnectionImpl.ChildServiceConnection.onServiceConnected");
+ }
+ }
+ }
+
private void onServiceDisconnectedOnLauncherThread() {
assert LauncherThread.runningOnLauncherThread();
synchronized (mLock) {
« no previous file with comments | « no previous file | content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698