OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.Intent; | 7 import android.content.Intent; |
8 import android.util.SparseArray; | |
8 | 9 |
9 import org.chromium.base.library_loader.LibraryProcessType; | 10 import org.chromium.base.library_loader.LibraryProcessType; |
10 | 11 |
11 /** | 12 /** |
12 * Allows specifying the package name for looking up child services | 13 * Allows specifying the package name for looking up child services |
13 * configuration and classes into (if it differs from the application | 14 * configuration and classes into (if it differs from the application |
14 * package name, like in the case of Android WebView). Also allows | 15 * package name, like in the case of Android WebView). Also allows |
15 * specifying additional child service binging flags. | 16 * specifying additional child service binging flags. |
16 */ | 17 */ |
17 public class ChildProcessCreationParams { | 18 public class ChildProcessCreationParams { |
19 private static final String EXTRA_LIBRARY_PROCESS_TYPE = | |
20 "org.chromium.content.common.child_service_params.library_process_ty pe"; | |
21 | |
22 public static final int DEFAULT_ID = 0; | |
23 private static final Object sLock = new Object(); | |
24 private static int sNextId = 1; // 0 is reserved for DEFAULT_ID. | |
25 private static final SparseArray<ChildProcessCreationParams> sParamMap = new SparseArray<>(); | |
26 | |
27 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
| |
28 synchronized (sLock) { | |
29 sParamMap.append(DEFAULT_ID, params); | |
30 } | |
31 } | |
32 | |
33 public static ChildProcessCreationParams getDefault() { | |
34 return get(DEFAULT_ID); | |
35 } | |
36 | |
37 public static int register(ChildProcessCreationParams params) { | |
38 assert params != null; | |
39 int id = -1; | |
40 synchronized (sLock) { | |
41 id = sNextId++; | |
42 sParamMap.append(id, params); | |
43 } | |
44 assert id > 0; | |
45 return id; | |
46 } | |
47 | |
48 public static ChildProcessCreationParams get(int id) { | |
49 assert id >= 0; | |
50 synchronized (sLock) { | |
51 return sParamMap.get(id); | |
52 } | |
53 } | |
54 | |
55 public static void unregister(int id) { | |
56 synchronized (sLock) { | |
57 sParamMap.delete(id); | |
58 } | |
59 } | |
60 | |
61 // Members should all be immutable to avoid worrying about thread safety. | |
18 private final String mPackageName; | 62 private final String mPackageName; |
19 private final boolean mIsExternalService; | 63 private final boolean mIsExternalService; |
20 private final int mLibraryProcessType; | 64 private final int mLibraryProcessType; |
21 private static final String EXTRA_LIBRARY_PROCESS_TYPE = | |
22 "org.chromium.content.common.child_service_params.library_process_ty pe"; | |
23 | |
24 private static volatile ChildProcessCreationParams sChildProcessCreationPara ms; | |
25 | |
26 public static void set(ChildProcessCreationParams params) { | |
27 sChildProcessCreationParams = params; | |
28 } | |
29 | |
30 public static ChildProcessCreationParams get() { | |
31 return sChildProcessCreationParams; | |
32 } | |
33 | 65 |
34 public ChildProcessCreationParams(String packageName, boolean isExternalServ ice, | 66 public ChildProcessCreationParams(String packageName, boolean isExternalServ ice, |
35 int libraryProcessType) { | 67 int libraryProcessType) { |
36 mPackageName = packageName; | 68 mPackageName = packageName; |
37 mIsExternalService = isExternalService; | 69 mIsExternalService = isExternalService; |
38 mLibraryProcessType = libraryProcessType; | 70 mLibraryProcessType = libraryProcessType; |
39 } | 71 } |
40 | 72 |
41 public ChildProcessCreationParams copy() { | 73 String getPackageName() { |
42 return new ChildProcessCreationParams(mPackageName, mIsExternalService, | |
43 mLibraryProcessType); | |
44 } | |
45 | |
46 public String getPackageName() { | |
47 return mPackageName; | 74 return mPackageName; |
48 } | 75 } |
49 | 76 |
50 public boolean getIsExternalService() { | 77 boolean getIsExternalService() { |
51 return mIsExternalService; | 78 return mIsExternalService; |
52 } | 79 } |
53 | 80 |
54 public int getLibraryProcessType() { | 81 int getLibraryProcessType() { |
55 return mLibraryProcessType; | 82 return mLibraryProcessType; |
56 } | 83 } |
57 | 84 |
58 public void addIntentExtras(Intent intent) { | 85 void addIntentExtras(Intent intent) { |
59 intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); | 86 intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); |
60 } | 87 } |
61 | 88 |
62 public static int getLibraryProcessType(Intent intent) { | 89 public static int getLibraryProcessType(Intent intent) { |
63 return intent.getIntExtra(EXTRA_LIBRARY_PROCESS_TYPE, | 90 return intent.getIntExtra(EXTRA_LIBRARY_PROCESS_TYPE, |
64 LibraryProcessType.PROCESS_CHILD); | 91 LibraryProcessType.PROCESS_CHILD); |
65 } | 92 } |
66 } | 93 } |
OLD | NEW |