Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java |
| index db717bfcc52f6f32ea769d49eec437c164d70f8c..fd1bc630ff4ceef496c1dd886bc182805b1c72c2 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java |
| @@ -232,7 +232,7 @@ public class ChildProcessLauncher { |
| private static String sSandboxedServicesNameForTesting; |
| @VisibleForTesting |
| - public static void setSanboxServicesSettingsForTesting(int serviceCount, String serviceName) { |
| + public static void setSandboxServicesSettingsForTesting(int serviceCount, String serviceName) { |
| sSandboxedServicesCountForTesting = serviceCount; |
| sSandboxedServicesNameForTesting = serviceName; |
| } |
| @@ -424,7 +424,7 @@ public class ChildProcessLauncher { |
| // Proactively releases all the moderate bindings once all the sandboxed services |
| // are allocated, which will be very likely to have some of them killed by OOM |
| // killer. |
| - sBindingManager.releaseAllModerateBindings(); |
| + getBindingManager().releaseAllModerateBindings(); |
| } |
| } |
| return connection; |
| @@ -491,14 +491,24 @@ public class ChildProcessLauncher { |
| // }}} |
| // Manages oom bindings used to bind chind services. |
| - private static BindingManager sBindingManager = BindingManagerImpl.createBindingManager(); |
| + private static volatile BindingManager sBindingManager; |
| // Whether the main application is currently brought to the foreground. |
| private static boolean sApplicationInForeground = true; |
| + // Lazy initialize sBindingManager |
| // TODO(boliu): This should be internal to content. |
| public static BindingManager getBindingManager() { |
| - return sBindingManager; |
| + BindingManager manager = sBindingManager; |
| + if (manager == null) { |
| + synchronized (ChildProcessLauncher.class) { |
|
boliu
2017/04/13 01:05:54
no need to be fancy and prematurely optmize this,
the real yoland
2017/04/13 01:15:58
hmm, I wouldn't call this prematurely though, but
boliu
2017/04/13 01:33:34
don't know is exactly premature optmization... And
the real yoland
2017/04/13 02:03:06
alright
done
|
| + manager = sBindingManager; |
| + if (manager == null) { |
| + sBindingManager = manager = BindingManagerImpl.createBindingManager(); |
| + } |
| + } |
| + } |
| + return manager; |
| } |
| @VisibleForTesting |
| @@ -511,7 +521,7 @@ public class ChildProcessLauncher { |
| * rely on renderer visibility signalled through setInForeground. See http://crbug.com/421041. |
| */ |
| public static void determinedVisibility(int pid) { |
| - sBindingManager.determinedVisibility(pid); |
| + getBindingManager().determinedVisibility(pid); |
| } |
| /** |
| @@ -519,7 +529,7 @@ public class ChildProcessLauncher { |
| */ |
| public static void onSentToBackground() { |
| sApplicationInForeground = false; |
| - sBindingManager.onSentToBackground(); |
| + getBindingManager().onSentToBackground(); |
| } |
| /** |
| @@ -533,7 +543,7 @@ public class ChildProcessLauncher { |
| * sent to the background. |
| */ |
| public static void startModerateBindingManagement(Context context) { |
| - sBindingManager.startModerateBindingManagement( |
| + getBindingManager().startModerateBindingManagement( |
| context, getNumberOfServices(context, true, context.getPackageName())); |
| } |
| @@ -542,7 +552,7 @@ public class ChildProcessLauncher { |
| */ |
| public static void onBroughtToForeground() { |
| sApplicationInForeground = true; |
| - sBindingManager.onBroughtToForeground(); |
| + getBindingManager().onBroughtToForeground(); |
| } |
| /** |
| @@ -753,7 +763,7 @@ public class ChildProcessLauncher { |
| public void onConnected(int pid) { |
| Log.d(TAG, "on connect callback, pid=%d", pid); |
| if (pid != NULL_PROCESS_HANDLE) { |
| - sBindingManager.addNewConnection(pid, connection); |
| + getBindingManager().addNewConnection(pid, connection); |
| sServiceMap.put(pid, connection); |
| } |
| // If the connection fails and pid == 0, the Java-side cleanup was already |
| @@ -781,7 +791,7 @@ public class ChildProcessLauncher { |
| // Can happen for single process. |
| return; |
| } |
| - sBindingManager.clearConnection(pid); |
| + getBindingManager().clearConnection(pid); |
| connection.stop(); |
| freeConnection(connection); |
| } |