| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // call. | 107 // call. |
| 108 private ChildProcessConnection.ConnectionCallback mConnectionCallback; | 108 private ChildProcessConnection.ConnectionCallback mConnectionCallback; |
| 109 | 109 |
| 110 private class ChildServiceConnection implements ServiceConnection { | 110 private class ChildServiceConnection implements ServiceConnection { |
| 111 private boolean mBound = false; | 111 private boolean mBound = false; |
| 112 | 112 |
| 113 private final int mBindFlags; | 113 private final int mBindFlags; |
| 114 | 114 |
| 115 private Intent createServiceBindIntent() { | 115 private Intent createServiceBindIntent() { |
| 116 Intent intent = new Intent(); | 116 Intent intent = new Intent(); |
| 117 if (mCreationParams != null) { | 117 mCreationParams.addIntentExtras(intent); |
| 118 mCreationParams.addIntentExtras(intent); | 118 |
| 119 } | |
| 120 intent.setComponent(mServiceName); | 119 intent.setComponent(mServiceName); |
| 121 return intent; | 120 return intent; |
| 122 } | 121 } |
| 123 | 122 |
| 124 public ChildServiceConnection(int bindFlags, boolean needsExtraBindFlags
) { | 123 public ChildServiceConnection(int bindFlags, boolean needsExtraBindFlags
) { |
| 125 if (needsExtraBindFlags && mCreationParams != null) { | 124 if (needsExtraBindFlags) { |
| 126 bindFlags = mCreationParams.addExtraBindFlags(bindFlags); | 125 bindFlags = mCreationParams.addExtraBindFlags(bindFlags); |
| 127 } | 126 } |
| 128 mBindFlags = bindFlags; | 127 mBindFlags = bindFlags; |
| 129 } | 128 } |
| 130 | 129 |
| 131 boolean bind(String[] commandLine) { | 130 boolean bind(String[] commandLine) { |
| 132 if (!mBound) { | 131 if (!mBound) { |
| 133 try { | 132 try { |
| 134 TraceEvent.begin("ChildProcessConnectionImpl.ChildServiceCon
nection.bind"); | 133 TraceEvent.begin("ChildProcessConnectionImpl.ChildServiceCon
nection.bind"); |
| 135 final Intent intent = createServiceBindIntent(); | 134 final Intent intent = createServiceBindIntent(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 ChildProcessConnection.DeathCallback deathCallback, | 212 ChildProcessConnection.DeathCallback deathCallback, |
| 214 Class<? extends ChildProcessService> serviceClass, | 213 Class<? extends ChildProcessService> serviceClass, |
| 215 ChromiumLinkerParams chromiumLinkerParams, | 214 ChromiumLinkerParams chromiumLinkerParams, |
| 216 boolean alwaysInForeground, | 215 boolean alwaysInForeground, |
| 217 ChildProcessCreationParams creationParams) { | 216 ChildProcessCreationParams creationParams) { |
| 218 mContext = context; | 217 mContext = context; |
| 219 mServiceNumber = number; | 218 mServiceNumber = number; |
| 220 mInSandbox = inSandbox; | 219 mInSandbox = inSandbox; |
| 221 mDeathCallback = deathCallback; | 220 mDeathCallback = deathCallback; |
| 222 mServiceClass = serviceClass; | 221 mServiceClass = serviceClass; |
| 223 String packageName = | 222 mServiceName = new ComponentName( |
| 224 creationParams != null ? creationParams.getPackageName() : conte
xt.getPackageName(); | 223 creationParams.getPackageName(), mServiceClass.getName() + mServ
iceNumber); |
| 225 mServiceName = new ComponentName(packageName, mServiceClass.getName() +
mServiceNumber); | |
| 226 mLinkerParams = chromiumLinkerParams; | 224 mLinkerParams = chromiumLinkerParams; |
| 227 mAlwaysInForeground = alwaysInForeground; | 225 mAlwaysInForeground = alwaysInForeground; |
| 228 mCreationParams = creationParams; | 226 mCreationParams = creationParams; |
| 229 int initialFlags = Context.BIND_AUTO_CREATE; | 227 int initialFlags = Context.BIND_AUTO_CREATE; |
| 230 if (mAlwaysInForeground) initialFlags |= Context.BIND_IMPORTANT; | 228 if (mAlwaysInForeground) initialFlags |= Context.BIND_IMPORTANT; |
| 231 // "external service" attribute is approximated by "exported" attribute. | 229 // "external service" attribute is approximated by "exported" attribute. |
| 232 // TODO(mnaganov): Update after the release of the next Android SDK. | 230 // TODO(mnaganov): Update after the release of the next Android SDK. |
| 233 final boolean needsExtraBindFlags = isExportedService(inSandbox, mContex
t, mServiceName); | 231 final boolean needsExtraBindFlags = isExportedService(inSandbox, mContex
t, mServiceName); |
| 234 mInitialBinding = new ChildServiceConnection(initialFlags, needsExtraBin
dFlags); | 232 mInitialBinding = new ChildServiceConnection(initialFlags, needsExtraBin
dFlags); |
| 235 mStrongBinding = new ChildServiceConnection( | 233 mStrongBinding = new ChildServiceConnection( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 264 public int getServiceNumber() { | 262 public int getServiceNumber() { |
| 265 return mServiceNumber; | 263 return mServiceNumber; |
| 266 } | 264 } |
| 267 | 265 |
| 268 @Override | 266 @Override |
| 269 public boolean isInSandbox() { | 267 public boolean isInSandbox() { |
| 270 return mInSandbox; | 268 return mInSandbox; |
| 271 } | 269 } |
| 272 | 270 |
| 273 @Override | 271 @Override |
| 272 public ChildProcessCreationParams getCreationParams() { |
| 273 return mCreationParams; |
| 274 } |
| 275 |
| 276 @Override |
| 274 public IChildProcessService getService() { | 277 public IChildProcessService getService() { |
| 275 synchronized (mLock) { | 278 synchronized (mLock) { |
| 276 return mService; | 279 return mService; |
| 277 } | 280 } |
| 278 } | 281 } |
| 279 | 282 |
| 280 @Override | 283 @Override |
| 281 public int getPid() { | 284 public int getPid() { |
| 282 synchronized (mLock) { | 285 synchronized (mLock) { |
| 283 return mPid; | 286 return mPid; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 return true; | 514 return true; |
| 512 } | 515 } |
| 513 return false; | 516 return false; |
| 514 } | 517 } |
| 515 | 518 |
| 516 @VisibleForTesting | 519 @VisibleForTesting |
| 517 public boolean isConnected() { | 520 public boolean isConnected() { |
| 518 return mService != null; | 521 return mService != null; |
| 519 } | 522 } |
| 520 } | 523 } |
| OLD | NEW |