Chromium Code Reviews| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap ped, | 91 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap ped, |
| 92 IChildProcessCallback callback, Bundle sharedRelros) { | 92 IChildProcessCallback callback, Bundle sharedRelros) { |
| 93 mCommandLine = commandLine; | 93 mCommandLine = commandLine; |
| 94 mFilesToBeMapped = filesToBeMapped; | 94 mFilesToBeMapped = filesToBeMapped; |
| 95 mCallback = callback; | 95 mCallback = callback; |
| 96 mSharedRelros = sharedRelros; | 96 mSharedRelros = sharedRelros; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 // This is set in start() and is used in onServiceConnected(). | |
| 101 private ChildProcessConnection.StartCallback mStartCallback; | |
| 102 | |
| 100 // This is set in setupConnection() and is later used in doConnectionSetupLo cked(), after which | 103 // This is set in setupConnection() and is later used in doConnectionSetupLo cked(), after which |
| 101 // the variable is cleared. Therefore this is only valid while the connectio n is being set up. | 104 // the variable is cleared. Therefore this is only valid while the connectio n is being set up. |
| 102 private ConnectionParams mConnectionParams; | 105 private ConnectionParams mConnectionParams; |
| 103 | 106 |
| 104 // Callback provided in setupConnection() that will communicate the result t o the caller. This | 107 // Callback provided in setupConnection() that will communicate the result t o the caller. This |
| 105 // has to be called exactly once after setupConnection(), even if setup fail s, so that the | 108 // has to be called exactly once after setupConnection(), even if setup fail s, so that the |
| 106 // caller can free up resources associated with the setup attempt. This is s et to null after the | 109 // caller can free up resources associated with the setup attempt. This is s et to null after the |
| 107 // call. | 110 // call. |
| 108 private ChildProcessConnection.ConnectionCallback mConnectionCallback; | 111 private ChildProcessConnection.ConnectionCallback mConnectionCallback; |
| 109 | 112 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 // A flag from the parent class ensures we run the post-connecti on logic only once | 164 // A flag from the parent class ensures we run the post-connecti on logic only once |
| 162 // (instead of once per each ChildServiceConnection). | 165 // (instead of once per each ChildServiceConnection). |
| 163 if (mServiceConnectComplete) { | 166 if (mServiceConnectComplete) { |
| 164 return; | 167 return; |
| 165 } | 168 } |
| 166 try { | 169 try { |
| 167 TraceEvent.begin( | 170 TraceEvent.begin( |
| 168 "ChildProcessConnectionImpl.ChildServiceConnection.o nServiceConnected"); | 171 "ChildProcessConnectionImpl.ChildServiceConnection.o nServiceConnected"); |
| 169 mServiceConnectComplete = true; | 172 mServiceConnectComplete = true; |
| 170 mService = IChildProcessService.Stub.asInterface(service); | 173 mService = IChildProcessService.Stub.asInterface(service); |
| 174 | |
| 175 boolean boundToUs = false; | |
| 176 try { | |
| 177 boundToUs = mService.bindToCaller(); | |
| 178 } catch (RemoteException ex) { | |
| 179 } finally { | |
|
Torne
2017/01/16 12:44:43
Unless there's another exception type that can hap
Robert Sesek
2017/01/17 19:51:22
Done.
| |
| 180 if (!boundToUs) { | |
| 181 if (mStartCallback != null) { | |
| 182 mStartCallback.onChildStartFailed(); | |
| 183 } | |
| 184 return; | |
| 185 } else if (mStartCallback != null) { | |
| 186 mStartCallback.onChildStarted(); | |
| 187 } | |
| 188 } | |
| 189 | |
| 171 // Run the setup if the connection parameters have already b een provided. If | 190 // Run the setup if the connection parameters have already b een provided. If |
| 172 // not, doConnectionSetupLocked() will be called from setupC onnection(). | 191 // not, doConnectionSetupLocked() will be called from setupC onnection(). |
| 173 if (mConnectionParams != null) { | 192 if (mConnectionParams != null) { |
| 174 doConnectionSetupLocked(); | 193 doConnectionSetupLocked(); |
| 175 } | 194 } |
| 176 } finally { | 195 } finally { |
| 177 TraceEvent.end( | 196 TraceEvent.end( |
| 178 "ChildProcessConnectionImpl.ChildServiceConnection.o nServiceConnected"); | 197 "ChildProcessConnectionImpl.ChildServiceConnection.o nServiceConnected"); |
| 179 } | 198 } |
| 180 } | 199 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 } | 301 } |
| 283 | 302 |
| 284 @Override | 303 @Override |
| 285 public int getPid() { | 304 public int getPid() { |
| 286 synchronized (mLock) { | 305 synchronized (mLock) { |
| 287 return mPid; | 306 return mPid; |
| 288 } | 307 } |
| 289 } | 308 } |
| 290 | 309 |
| 291 @Override | 310 @Override |
| 292 public void start(String[] commandLine) { | 311 public void start(String[] commandLine, ChildProcessConnection.StartCallback startCallback) { |
| 293 try { | 312 try { |
| 294 TraceEvent.begin("ChildProcessConnectionImpl.start"); | 313 TraceEvent.begin("ChildProcessConnectionImpl.start"); |
| 295 synchronized (mLock) { | 314 synchronized (mLock) { |
| 296 assert !ThreadUtils.runningOnUiThread(); | 315 assert !ThreadUtils.runningOnUiThread(); |
| 297 assert mConnectionParams == null : | 316 assert mConnectionParams == null : |
| 298 "setupConnection() called before start() in ChildProcess ConnectionImpl."; | 317 "setupConnection() called before start() in ChildProcess ConnectionImpl."; |
| 299 | 318 |
| 319 mStartCallback = startCallback; | |
| 320 | |
| 300 if (!mInitialBinding.bind(commandLine)) { | 321 if (!mInitialBinding.bind(commandLine)) { |
| 301 Log.e(TAG, "Failed to establish the service connection."); | 322 Log.e(TAG, "Failed to establish the service connection."); |
| 302 // We have to notify the caller so that they can free-up ass ociated resources. | 323 // We have to notify the caller so that they can free-up ass ociated resources. |
| 303 // TODO(ppi): Can we hard-fail here? | 324 // TODO(ppi): Can we hard-fail here? |
| 304 mDeathCallback.onChildProcessDied(ChildProcessConnectionImpl .this); | 325 mDeathCallback.onChildProcessDied(ChildProcessConnectionImpl .this); |
| 305 } else { | 326 } else { |
| 306 mWaivedBinding.bind(null); | 327 mWaivedBinding.bind(null); |
| 307 } | 328 } |
| 308 } | 329 } |
| 309 } finally { | 330 } finally { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 return true; | 536 return true; |
| 516 } | 537 } |
| 517 return false; | 538 return false; |
| 518 } | 539 } |
| 519 | 540 |
| 520 @VisibleForTesting | 541 @VisibleForTesting |
| 521 public boolean isConnected() { | 542 public boolean isConnected() { |
| 522 return mService != null; | 543 return mService != null; |
| 523 } | 544 } |
| 524 } | 545 } |
| OLD | NEW |