| 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> mServiceName; |
| 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) { |
| 36 mPackageName = packageName; | 38 mPackageName = packageName; |
| 37 mExtraBindFlags = extraBindFlags; | 39 mExtraBindFlags = extraBindFlags; |
| 38 mLibraryProcessType = libraryProcessType; | 40 mLibraryProcessType = libraryProcessType; |
| 41 mServiceName = null; |
| 42 } |
| 43 |
| 44 public ChildProcessCreationParams(String packageName, int extraBindFlags, |
| 45 int libraryProcessType, Class<? extends Service> serviceName) { |
| 46 mPackageName = packageName; |
| 47 mExtraBindFlags = extraBindFlags; |
| 48 mLibraryProcessType = libraryProcessType; |
| 49 mServiceName = serviceName; |
| 39 } | 50 } |
| 40 | 51 |
| 41 public ChildProcessCreationParams copy() { | 52 public ChildProcessCreationParams copy() { |
| 42 return new ChildProcessCreationParams(mPackageName, mExtraBindFlags, mLi
braryProcessType); | 53 return new ChildProcessCreationParams(mPackageName, mExtraBindFlags, mLi
braryProcessType, |
| 54 mServiceName); |
| 43 } | 55 } |
| 44 | 56 |
| 45 public String getPackageName() { | 57 public String getPackageName() { |
| 46 return mPackageName; | 58 return mPackageName; |
| 47 } | 59 } |
| 48 | 60 |
| 49 public int getExtraBindFlags() { | 61 public int getExtraBindFlags() { |
| 50 return mExtraBindFlags; | 62 return mExtraBindFlags; |
| 51 } | 63 } |
| 52 | 64 |
| 65 public Class<? extends Service> getServiceName() { |
| 66 return mServiceName; |
| 67 } |
| 68 |
| 53 /** | 69 /** |
| 54 * Adds required extra flags to the given child service binding flags and re
turns them. | 70 * Adds required extra flags to the given child service binding flags and re
turns them. |
| 55 * Does not modify the state of the ChildProcessCreationParams instance. | 71 * Does not modify the state of the ChildProcessCreationParams instance. |
| 56 * | 72 * |
| 57 * @param bindFlags Source bind flags to modify. | 73 * @param bindFlags Source bind flags to modify. |
| 58 * @return Bind flags with extra flags added. | 74 * @return Bind flags with extra flags added. |
| 59 */ | 75 */ |
| 60 public int addExtraBindFlags(int bindFlags) { | 76 public int addExtraBindFlags(int bindFlags) { |
| 61 return bindFlags | mExtraBindFlags; | 77 return bindFlags | mExtraBindFlags; |
| 62 } | 78 } |
| 63 | 79 |
| 64 public void addIntentExtras(Intent intent) { | 80 public void addIntentExtras(Intent intent) { |
| 65 intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); | 81 intent.putExtra(EXTRA_LIBRARY_PROCESS_TYPE, mLibraryProcessType); |
| 66 } | 82 } |
| 67 | 83 |
| 68 public static int getLibraryProcessType(Intent intent) { | 84 public static int getLibraryProcessType(Intent intent) { |
| 69 return intent.getIntExtra(EXTRA_LIBRARY_PROCESS_TYPE, | 85 return intent.getIntExtra(EXTRA_LIBRARY_PROCESS_TYPE, |
| 70 LibraryProcessType.PROCESS_CHILD); | 86 LibraryProcessType.PROCESS_CHILD); |
| 71 } | 87 } |
| 72 } | 88 } |
| OLD | NEW |