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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 // Called on the main thread to notify that the child service did not di
sconnect gracefully. | 171 // Called on the main thread to notify that the child service did not di
sconnect gracefully. |
172 @Override | 172 @Override |
173 public void onServiceDisconnected(ComponentName className) { | 173 public void onServiceDisconnected(ComponentName className) { |
174 synchronized (mLock) { | 174 synchronized (mLock) { |
175 // Ensure that the disconnection logic runs only once (instead o
f once per each | 175 // Ensure that the disconnection logic runs only once (instead o
f once per each |
176 // ChildServiceConnection). | 176 // ChildServiceConnection). |
177 if (mServiceDisconnected) { | 177 if (mServiceDisconnected) { |
178 return; | 178 return; |
179 } | 179 } |
| 180 // Stash the status of the oom bindings, since stop() will relea
se all bindings. |
| 181 mWasOomProtected = isCurrentlyOomProtected(); |
180 mServiceDisconnected = true; | 182 mServiceDisconnected = true; |
181 // Stash the status of the oom bindings, since stop() will relea
se all bindings. | |
182 mWasOomProtected = mInitialBinding.isBound() || mStrongBinding.i
sBound(); | |
183 Log.w(TAG, "onServiceDisconnected (crash or killed by oom): pid=
" + mPid); | 183 Log.w(TAG, "onServiceDisconnected (crash or killed by oom): pid=
" + mPid); |
184 stop(); // We don't want to auto-restart on crash. Let the brow
ser do that. | 184 stop(); // We don't want to auto-restart on crash. Let the brow
ser do that. |
185 mDeathCallback.onChildProcessDied(ChildProcessConnectionImpl.thi
s); | 185 mDeathCallback.onChildProcessDied(ChildProcessConnectionImpl.thi
s); |
186 // If we have a pending connection callback, we need to communic
ate the failure to | 186 // If we have a pending connection callback, we need to communic
ate the failure to |
187 // the caller. | 187 // the caller. |
188 if (mConnectionCallback != null) { | 188 if (mConnectionCallback != null) { |
189 mConnectionCallback.onConnected(0); | 189 mConnectionCallback.onConnected(0); |
190 } | 190 } |
191 mConnectionCallback = null; | 191 mConnectionCallback = null; |
192 } | 192 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 mInitialBinding.unbind(); | 400 mInitialBinding.unbind(); |
401 } | 401 } |
402 } | 402 } |
403 | 403 |
404 @Override | 404 @Override |
405 public boolean isOomProtectedOrWasWhenDied() { | 405 public boolean isOomProtectedOrWasWhenDied() { |
406 synchronized (mLock) { | 406 synchronized (mLock) { |
407 if (mServiceDisconnected) { | 407 if (mServiceDisconnected) { |
408 return mWasOomProtected; | 408 return mWasOomProtected; |
409 } else { | 409 } else { |
410 return mInitialBinding.isBound() || mStrongBinding.isBound(); | 410 return isCurrentlyOomProtected(); |
411 } | 411 } |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
| 415 private boolean isCurrentlyOomProtected() { |
| 416 synchronized (mLock) { |
| 417 assert !mServiceDisconnected; |
| 418 if (mAlwaysInForeground) return ChildProcessLauncher.isApplicationIn
Foreground(); |
| 419 return mInitialBinding.isBound() || mStrongBinding.isBound(); |
| 420 } |
| 421 } |
| 422 |
415 @Override | 423 @Override |
416 public void dropOomBindings() { | 424 public void dropOomBindings() { |
417 synchronized (mLock) { | 425 synchronized (mLock) { |
418 assert !mAlwaysInForeground; | 426 assert !mAlwaysInForeground; |
419 mInitialBinding.unbind(); | 427 mInitialBinding.unbind(); |
420 | 428 |
421 mStrongBindingCount = 0; | 429 mStrongBindingCount = 0; |
422 mStrongBinding.unbind(); | 430 mStrongBinding.unbind(); |
423 } | 431 } |
424 } | 432 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 return true; | 468 return true; |
461 } | 469 } |
462 return false; | 470 return false; |
463 } | 471 } |
464 | 472 |
465 @VisibleForTesting | 473 @VisibleForTesting |
466 public boolean isConnected() { | 474 public boolean isConnected() { |
467 return mService != null; | 475 return mService != null; |
468 } | 476 } |
469 } | 477 } |
OLD | NEW |