| 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 24 matching lines...) Expand all Loading... |
| 35 private final int mServiceNumber; | 35 private final int mServiceNumber; |
| 36 private final boolean mInSandbox; | 36 private final boolean mInSandbox; |
| 37 private final ChildProcessConnection.DeathCallback mDeathCallback; | 37 private final ChildProcessConnection.DeathCallback mDeathCallback; |
| 38 private final ComponentName mServiceName; | 38 private final ComponentName mServiceName; |
| 39 | 39 |
| 40 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API | 40 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API |
| 41 // (specifically start and stop) may be called from any thread, hence all en
try point methods | 41 // (specifically start and stop) may be called from any thread, hence all en
try point methods |
| 42 // into the class are synchronized on the lock to protect access to these me
mbers. | 42 // into the class are synchronized on the lock to protect access to these me
mbers. |
| 43 private final Object mLock = new Object(); | 43 private final Object mLock = new Object(); |
| 44 private IChildProcessService mService; | 44 private IChildProcessService mService; |
| 45 // Set to true when the service connection callback runs. This differs from |
| 46 // mServiceConnectComplete, which tracks that the connection completed succe
ssfully. |
| 47 private boolean mDidOnServiceConnected; |
| 45 // Set to true when the service connected successfully. | 48 // Set to true when the service connected successfully. |
| 46 private boolean mServiceConnectComplete; | 49 private boolean mServiceConnectComplete; |
| 47 // Set to true when the service disconnects, as opposed to being properly cl
osed. This happens | 50 // Set to true when the service disconnects, as opposed to being properly cl
osed. This happens |
| 48 // when the process crashes or gets killed by the system out-of-memory kille
r. | 51 // when the process crashes or gets killed by the system out-of-memory kille
r. |
| 49 private boolean mServiceDisconnected; | 52 private boolean mServiceDisconnected; |
| 50 // When the service disconnects (i.e. mServiceDisconnected is set to true),
the status of the | 53 // When the service disconnects (i.e. mServiceDisconnected is set to true),
the status of the |
| 51 // oom bindings is stashed here for future inspection. | 54 // oom bindings is stashed here for future inspection. |
| 52 private boolean mWasOomProtected; | 55 private boolean mWasOomProtected; |
| 53 private int mPid; // Process ID of the corresponding child process. | 56 private int mPid; // Process ID of the corresponding child process. |
| 54 // Initial binding protects the newly spawned process from being killed befo
re it is put to use, | 57 // Initial binding protects the newly spawned process from being killed befo
re it is put to use, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 159 |
| 157 boolean isBound() { | 160 boolean isBound() { |
| 158 return mBound; | 161 return mBound; |
| 159 } | 162 } |
| 160 | 163 |
| 161 @Override | 164 @Override |
| 162 public void onServiceConnected(ComponentName className, IBinder service)
{ | 165 public void onServiceConnected(ComponentName className, IBinder service)
{ |
| 163 synchronized (mLock) { | 166 synchronized (mLock) { |
| 164 // A flag from the parent class ensures we run the post-connecti
on logic only once | 167 // A flag from the parent class ensures we run the post-connecti
on logic only once |
| 165 // (instead of once per each ChildServiceConnection). | 168 // (instead of once per each ChildServiceConnection). |
| 166 if (mServiceConnectComplete) { | 169 if (mDidOnServiceConnected) { |
| 167 return; | 170 return; |
| 168 } | 171 } |
| 169 try { | 172 try { |
| 170 TraceEvent.begin( | 173 TraceEvent.begin( |
| 171 "ChildProcessConnectionImpl.ChildServiceConnection.o
nServiceConnected"); | 174 "ChildProcessConnectionImpl.ChildServiceConnection.o
nServiceConnected"); |
| 172 mServiceConnectComplete = true; | 175 mDidOnServiceConnected = true; |
| 173 mService = IChildProcessService.Stub.asInterface(service); | 176 mService = IChildProcessService.Stub.asInterface(service); |
| 174 | 177 |
| 175 boolean boundToUs = false; | 178 boolean boundToUs = false; |
| 176 try { | 179 try { |
| 177 boundToUs = mService.bindToCaller(); | 180 boundToUs = mService.bindToCaller(); |
| 178 } catch (RemoteException ex) { | 181 } catch (RemoteException ex) { |
| 179 } | 182 } |
| 180 | 183 |
| 181 if (mStartCallback != null) { | 184 if (mStartCallback != null) { |
| 182 if (boundToUs) { | 185 if (boundToUs) { |
| 183 mStartCallback.onChildStarted(); | 186 mStartCallback.onChildStarted(); |
| 184 } else { | 187 } else { |
| 185 mStartCallback.onChildStartFailed(); | 188 mStartCallback.onChildStartFailed(); |
| 186 } | 189 } |
| 187 mStartCallback = null; | 190 mStartCallback = null; |
| 188 } | 191 } |
| 189 | 192 |
| 190 if (!boundToUs) { | 193 if (!boundToUs) { |
| 191 return; | 194 return; |
| 192 } | 195 } |
| 193 | 196 |
| 197 mServiceConnectComplete = true; |
| 198 |
| 194 // Run the setup if the connection parameters have already b
een provided. If | 199 // Run the setup if the connection parameters have already b
een provided. If |
| 195 // not, doConnectionSetupLocked() will be called from setupC
onnection(). | 200 // not, doConnectionSetupLocked() will be called from setupC
onnection(). |
| 196 if (mConnectionParams != null) { | 201 if (mConnectionParams != null) { |
| 197 doConnectionSetupLocked(); | 202 doConnectionSetupLocked(); |
| 198 } | 203 } |
| 199 } finally { | 204 } finally { |
| 200 TraceEvent.end( | 205 TraceEvent.end( |
| 201 "ChildProcessConnectionImpl.ChildServiceConnection.o
nServiceConnected"); | 206 "ChildProcessConnectionImpl.ChildServiceConnection.o
nServiceConnected"); |
| 202 } | 207 } |
| 203 } | 208 } |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 return true; | 545 return true; |
| 541 } | 546 } |
| 542 return false; | 547 return false; |
| 543 } | 548 } |
| 544 | 549 |
| 545 @VisibleForTesting | 550 @VisibleForTesting |
| 546 public boolean isConnected() { | 551 public boolean isConnected() { |
| 547 return mService != null; | 552 return mService != null; |
| 548 } | 553 } |
| 549 } | 554 } |
| OLD | NEW |