Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ChildProcessCreationParams.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessCreationParams.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessCreationParams.java |
| index a8fd972bb4d0cf249b8c33f0fdb5934c514ba76b..ac1c4aeced8287a895feeafc67c7e374347a1bda 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessCreationParams.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessCreationParams.java |
| @@ -5,6 +5,7 @@ |
| package org.chromium.content.browser; |
| import android.content.Intent; |
| +import android.util.SparseArray; |
| import org.chromium.base.library_loader.LibraryProcessType; |
| @@ -15,22 +16,53 @@ import org.chromium.base.library_loader.LibraryProcessType; |
| * specifying additional child service binging flags. |
| */ |
| public class ChildProcessCreationParams { |
| - private final String mPackageName; |
| - private final boolean mIsExternalService; |
| - private final int mLibraryProcessType; |
| private static final String EXTRA_LIBRARY_PROCESS_TYPE = |
| "org.chromium.content.common.child_service_params.library_process_type"; |
| - private static volatile ChildProcessCreationParams sChildProcessCreationParams; |
| + public static final int DEFAULT_ID = 0; |
| + private static final Object sLock = new Object(); |
| + private static int sNextId = 1; // 0 is reserved for DEFAULT_ID. |
| + private static final SparseArray<ChildProcessCreationParams> sParamMap = new SparseArray<>(); |
| + |
| + public static void registerDefault(ChildProcessCreationParams params) { |
|
Maria
2017/02/24 05:32:42
public methods should have javadoc here and below
boliu
2017/02/25 00:49:45
Added one line javadoc to methods that are meant t
|
| + synchronized (sLock) { |
| + sParamMap.append(DEFAULT_ID, params); |
| + } |
| + } |
| + |
| + public static ChildProcessCreationParams getDefault() { |
| + return get(DEFAULT_ID); |
| + } |
| - public static void set(ChildProcessCreationParams params) { |
| - sChildProcessCreationParams = params; |
| + public static int register(ChildProcessCreationParams params) { |
| + assert params != null; |
| + int id = -1; |
| + synchronized (sLock) { |
| + id = sNextId++; |
| + sParamMap.append(id, params); |
| + } |
| + assert id > 0; |
| + return id; |
| } |
| - public static ChildProcessCreationParams get() { |
| - return sChildProcessCreationParams; |
| + public static ChildProcessCreationParams get(int id) { |
| + assert id >= 0; |
| + synchronized (sLock) { |
| + return sParamMap.get(id); |
| + } |
| } |
| + public static void unregister(int id) { |
| + synchronized (sLock) { |
| + sParamMap.delete(id); |
| + } |
| + } |
| + |
| + // Members should all be immutable to avoid worrying about thread safety. |
| + private final String mPackageName; |
| + private final boolean mIsExternalService; |
| + private final int mLibraryProcessType; |
| + |
| public ChildProcessCreationParams(String packageName, boolean isExternalService, |
| int libraryProcessType) { |
| mPackageName = packageName; |
| @@ -38,24 +70,19 @@ public class ChildProcessCreationParams { |
| mLibraryProcessType = libraryProcessType; |
| } |
| - public ChildProcessCreationParams copy() { |
| - return new ChildProcessCreationParams(mPackageName, mIsExternalService, |
| - mLibraryProcessType); |
| - } |
| - |
| - public String getPackageName() { |
| + String getPackageName() { |
| return mPackageName; |
| } |
| - public boolean getIsExternalService() { |
| + boolean getIsExternalService() { |
| return mIsExternalService; |
| } |
| - public int getLibraryProcessType() { |
| + int getLibraryProcessType() { |
| return mLibraryProcessType; |
| } |
| - public void addIntentExtras(Intent intent) { |
| + void addIntentExtras(Intent intent) { |
| intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); |
| } |