| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.pm.ApplicationInfo; | 9 import android.content.pm.ApplicationInfo; |
| 10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.os.IBinder; | 12 import android.os.IBinder; |
| 13 import android.os.RemoteException; | 13 import android.os.RemoteException; |
| 14 import android.text.TextUtils; | 14 import android.text.TextUtils; |
| 15 | 15 |
| 16 import org.chromium.base.CommandLine; | |
| 17 import org.chromium.base.CpuFeatures; | 16 import org.chromium.base.CpuFeatures; |
| 18 import org.chromium.base.Log; | 17 import org.chromium.base.Log; |
| 19 import org.chromium.base.ThreadUtils; | 18 import org.chromium.base.ThreadUtils; |
| 20 import org.chromium.base.TraceEvent; | 19 import org.chromium.base.TraceEvent; |
| 21 import org.chromium.base.VisibleForTesting; | 20 import org.chromium.base.VisibleForTesting; |
| 22 import org.chromium.base.library_loader.Linker; | 21 import org.chromium.base.library_loader.Linker; |
| 23 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 22 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
| 24 import org.chromium.base.process_launcher.FileDescriptorInfo; | 23 import org.chromium.base.process_launcher.FileDescriptorInfo; |
| 25 import org.chromium.content.app.ChromiumLinkerParams; | 24 import org.chromium.content.app.ChromiumLinkerParams; |
| 26 import org.chromium.content.app.PrivilegedProcessService; | 25 import org.chromium.content.app.PrivilegedProcessService; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 private static ChildConnectionAllocator sPrivilegedChildConnectionAllocator; | 219 private static ChildConnectionAllocator sPrivilegedChildConnectionAllocator; |
| 221 | 220 |
| 222 private static final boolean SPARE_CONNECTION_ALWAYS_IN_FOREGROUND = false; | 221 private static final boolean SPARE_CONNECTION_ALWAYS_IN_FOREGROUND = false; |
| 223 | 222 |
| 224 private static final String NUM_SANDBOXED_SERVICES_KEY = | 223 private static final String NUM_SANDBOXED_SERVICES_KEY = |
| 225 "org.chromium.content.browser.NUM_SANDBOXED_SERVICES"; | 224 "org.chromium.content.browser.NUM_SANDBOXED_SERVICES"; |
| 226 private static final String NUM_PRIVILEGED_SERVICES_KEY = | 225 private static final String NUM_PRIVILEGED_SERVICES_KEY = |
| 227 "org.chromium.content.browser.NUM_PRIVILEGED_SERVICES"; | 226 "org.chromium.content.browser.NUM_PRIVILEGED_SERVICES"; |
| 228 private static final String SANDBOXED_SERVICES_NAME_KEY = | 227 private static final String SANDBOXED_SERVICES_NAME_KEY = |
| 229 "org.chromium.content.browser.SANDBOXED_SERVICES_NAME"; | 228 "org.chromium.content.browser.SANDBOXED_SERVICES_NAME"; |
| 230 // Overrides the number of available sandboxed services. | 229 |
| 230 // Used by tests to override the default sandboxed service settings. |
| 231 private static int sSandboxedServicesCountForTesting = -1; |
| 232 private static String sSandboxedServicesNameForTesting; |
| 233 |
| 231 @VisibleForTesting | 234 @VisibleForTesting |
| 232 public static final String SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING = "num-
sandboxed-services"; | 235 public static void setSanboxServicesSettingsForTesting(int serviceCount, Str
ing serviceName) { |
| 233 public static final String SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING = | 236 sSandboxedServicesCountForTesting = serviceCount; |
| 234 "sandboxed-services-name"; | 237 sSandboxedServicesNameForTesting = serviceName; |
| 238 } |
| 235 | 239 |
| 236 static int getNumberOfServices(Context context, boolean inSandbox, String pa
ckageName) { | 240 static int getNumberOfServices(Context context, boolean inSandbox, String pa
ckageName) { |
| 237 int numServices = -1; | 241 int numServices = -1; |
| 238 if (inSandbox | 242 if (inSandbox && sSandboxedServicesCountForTesting != -1) { |
| 239 && CommandLine.getInstance().hasSwitch( | 243 numServices = sSandboxedServicesCountForTesting; |
| 240 SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING)) { | |
| 241 String value = CommandLine.getInstance().getSwitchValue( | |
| 242 SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING); | |
| 243 if (!TextUtils.isEmpty(value)) { | |
| 244 try { | |
| 245 numServices = Integer.parseInt(value); | |
| 246 } catch (NumberFormatException e) { | |
| 247 Log.w(TAG, "The value of --num-sandboxed-services is formatt
ed wrongly: " | |
| 248 + value); | |
| 249 } | |
| 250 } | |
| 251 } else { | 244 } else { |
| 252 try { | 245 try { |
| 253 PackageManager packageManager = context.getPackageManager(); | 246 PackageManager packageManager = context.getPackageManager(); |
| 254 ApplicationInfo appInfo = packageManager.getApplicationInfo(pack
ageName, | 247 ApplicationInfo appInfo = packageManager.getApplicationInfo(pack
ageName, |
| 255 PackageManager.GET_META_DATA); | 248 PackageManager.GET_META_DATA); |
| 256 if (appInfo.metaData != null) { | 249 if (appInfo.metaData != null) { |
| 257 numServices = appInfo.metaData.getInt(inSandbox | 250 numServices = appInfo.metaData.getInt(inSandbox |
| 258 ? NUM_SANDBOXED_SERVICES_KEY : NUM_PRIVILEGED_SERVIC
ES_KEY, -1); | 251 ? NUM_SANDBOXED_SERVICES_KEY : NUM_PRIVILEGED_SERVIC
ES_KEY, -1); |
| 259 } | 252 } |
| 260 } catch (PackageManager.NameNotFoundException e) { | 253 } catch (PackageManager.NameNotFoundException e) { |
| 261 throw new RuntimeException("Could not get application info"); | 254 throw new RuntimeException("Could not get application info"); |
| 262 } | 255 } |
| 263 } | 256 } |
| 264 if (numServices < 0) { | 257 if (numServices < 0) { |
| 265 throw new RuntimeException("Illegal meta data value for number of ch
ild services"); | 258 throw new RuntimeException("Illegal meta data value for number of ch
ild services"); |
| 266 } | 259 } |
| 267 return numServices; | 260 return numServices; |
| 268 } | 261 } |
| 269 | 262 |
| 270 private static String getClassNameOfService(Context context, boolean inSandb
ox, | 263 private static String getClassNameOfService(Context context, boolean inSandb
ox, |
| 271 String packageName) { | 264 String packageName) { |
| 272 if (!inSandbox) { | 265 if (!inSandbox) { |
| 273 return PrivilegedProcessService.class.getName(); | 266 return PrivilegedProcessService.class.getName(); |
| 274 } | 267 } |
| 275 if (CommandLine.getInstance().hasSwitch(SWITCH_SANDBOXED_SERVICES_NAME_F
OR_TESTING)) { | 268 |
| 276 return CommandLine.getInstance().getSwitchValue( | 269 if (!TextUtils.isEmpty(sSandboxedServicesNameForTesting)) { |
| 277 SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING); | 270 return sSandboxedServicesNameForTesting; |
| 278 } | 271 } |
| 279 | 272 |
| 280 String serviceName = null; | 273 String serviceName = null; |
| 281 try { | 274 try { |
| 282 PackageManager packageManager = context.getPackageManager(); | 275 PackageManager packageManager = context.getPackageManager(); |
| 283 ApplicationInfo appInfo = | 276 ApplicationInfo appInfo = |
| 284 packageManager.getApplicationInfo(packageName, PackageManage
r.GET_META_DATA); | 277 packageManager.getApplicationInfo(packageName, PackageManage
r.GET_META_DATA); |
| 285 if (appInfo.metaData != null) { | 278 if (appInfo.metaData != null) { |
| 286 serviceName = appInfo.metaData.getString(SANDBOXED_SERVICES_NAME
_KEY); | 279 serviceName = appInfo.metaData.getString(SANDBOXED_SERVICES_NAME
_KEY); |
| 287 } | 280 } |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 | 881 |
| 889 try { | 882 try { |
| 890 ((ChildProcessConnectionImpl) sServiceMap.get(pid)).crashServiceForT
esting(); | 883 ((ChildProcessConnectionImpl) sServiceMap.get(pid)).crashServiceForT
esting(); |
| 891 } catch (RemoteException ex) { | 884 } catch (RemoteException ex) { |
| 892 return false; | 885 return false; |
| 893 } | 886 } |
| 894 | 887 |
| 895 return true; | 888 return true; |
| 896 } | 889 } |
| 897 } | 890 } |
| OLD | NEW |