Chromium Code Reviews| 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.app.Service; | |
| 7 import android.content.Intent; | 8 import android.content.Intent; |
| 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 { |
| 18 private final String mPackageName; | 19 private final String mPackageName; |
| 19 private final int mExtraBindFlags; | 20 private final int mExtraBindFlags; |
| 20 private final int mLibraryProcessType; | 21 private final int mLibraryProcessType; |
| 22 private final Class<? extends Service> mServiceClass; | |
| 21 private static final String EXTRA_LIBRARY_PROCESS_TYPE = | 23 private static final String EXTRA_LIBRARY_PROCESS_TYPE = |
| 22 "org.chromium.content.common.child_service_params.library_process_ty pe"; | 24 "org.chromium.content.common.child_service_params.library_process_ty pe"; |
| 23 | 25 |
| 24 private static volatile ChildProcessCreationParams sChildProcessCreationPara ms; | 26 private static volatile ChildProcessCreationParams sChildProcessCreationPara ms; |
| 25 | 27 |
| 26 public static void set(ChildProcessCreationParams params) { | 28 public static void set(ChildProcessCreationParams params) { |
| 27 sChildProcessCreationParams = params; | 29 sChildProcessCreationParams = params; |
| 28 } | 30 } |
| 29 | 31 |
| 30 public static ChildProcessCreationParams get() { | 32 public static ChildProcessCreationParams get() { |
| 31 return sChildProcessCreationParams; | 33 return sChildProcessCreationParams; |
| 32 } | 34 } |
| 33 | 35 |
| 34 public ChildProcessCreationParams(String packageName, int extraBindFlags, | 36 public ChildProcessCreationParams(String packageName, int extraBindFlags, |
| 35 int libraryProcessType) { | 37 int libraryProcessType) { |
| 38 this(packageName, extraBindFlags, libraryProcessType, null); | |
| 39 } | |
| 40 | |
| 41 public ChildProcessCreationParams(String packageName, int extraBindFlags, | |
| 42 int libraryProcessType, Class<? extends Service> servicClass) { | |
|
Maria
2016/06/17 17:09:24
servic -> service
Xi Han
2016/06/17 18:35:20
Done.
| |
| 36 mPackageName = packageName; | 43 mPackageName = packageName; |
| 37 mExtraBindFlags = extraBindFlags; | 44 mExtraBindFlags = extraBindFlags; |
| 38 mLibraryProcessType = libraryProcessType; | 45 mLibraryProcessType = libraryProcessType; |
| 46 mServiceClass = servicClass; | |
| 39 } | 47 } |
| 40 | 48 |
| 41 public ChildProcessCreationParams copy() { | 49 public ChildProcessCreationParams copy() { |
| 42 return new ChildProcessCreationParams(mPackageName, mExtraBindFlags, mLi braryProcessType); | 50 return new ChildProcessCreationParams(mPackageName, mExtraBindFlags, mLi braryProcessType, |
| 51 mServiceClass); | |
| 43 } | 52 } |
| 44 | 53 |
| 45 public String getPackageName() { | 54 public String getPackageName() { |
| 46 return mPackageName; | 55 return mPackageName; |
| 47 } | 56 } |
| 48 | 57 |
| 49 public int getExtraBindFlags() { | 58 public int getExtraBindFlags() { |
| 50 return mExtraBindFlags; | 59 return mExtraBindFlags; |
| 51 } | 60 } |
| 52 | 61 |
| 53 public int getLibraryProcessType() { | 62 public int getLibraryProcessType() { |
| 54 return mLibraryProcessType; | 63 return mLibraryProcessType; |
| 55 } | 64 } |
| 56 | 65 |
| 66 public Class<? extends Service> getServiceClass() { | |
| 67 return mServiceClass; | |
| 68 } | |
| 69 | |
| 57 /** | 70 /** |
| 58 * Adds required extra flags to the given child service binding flags and re turns them. | 71 * Adds required extra flags to the given child service binding flags and re turns them. |
| 59 * Does not modify the state of the ChildProcessCreationParams instance. | 72 * Does not modify the state of the ChildProcessCreationParams instance. |
| 60 * | 73 * |
| 61 * @param bindFlags Source bind flags to modify. | 74 * @param bindFlags Source bind flags to modify. |
| 62 * @return Bind flags with extra flags added. | 75 * @return Bind flags with extra flags added. |
| 63 */ | 76 */ |
| 64 public int addExtraBindFlags(int bindFlags) { | 77 public int addExtraBindFlags(int bindFlags) { |
| 65 return bindFlags | mExtraBindFlags; | 78 return bindFlags | mExtraBindFlags; |
| 66 } | 79 } |
| 67 | 80 |
| 68 public void addIntentExtras(Intent intent) { | 81 public void addIntentExtras(Intent intent) { |
| 69 intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); | 82 intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); |
| 70 } | 83 } |
| 71 | 84 |
| 72 public static int getLibraryProcessType(Intent intent) { | 85 public static int getLibraryProcessType(Intent intent) { |
| 73 return intent.getIntExtra(EXTRA_LIBRARY_PROCESS_TYPE, | 86 return intent.getIntExtra(EXTRA_LIBRARY_PROCESS_TYPE, |
| 74 LibraryProcessType.PROCESS_CHILD); | 87 LibraryProcessType.PROCESS_CHILD); |
| 75 } | 88 } |
| 76 } | 89 } |
| OLD | NEW |