OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.content.browser; |
| 6 |
| 7 import android.app.ActivityManager; |
| 8 import android.content.Context; |
| 9 import android.content.res.Resources; |
| 10 import android.graphics.SurfaceTexture; |
| 11 import android.util.Log; |
| 12 import android.view.Surface; |
| 13 |
| 14 import org.chromium.base.CalledByNative; |
| 15 |
| 16 // NOTE: The un-upstreamed features have been removed from this file, please |
| 17 // don't merge this file to the downstream. |
| 18 class BrowserProcessMain { |
| 19 |
| 20 private static final String TAG = "BrowserProcessMain"; |
| 21 |
| 22 // Prevents initializing the process more than once. |
| 23 private static boolean sInitialized = false; |
| 24 |
| 25 // Computes the actual max renderer processes used. |
| 26 private static int normalizeMaxRendererProcesses(Context context, int maxRen
dererProcesses) { |
| 27 if (maxRendererProcesses == MAX_RENDERERS_AUTOMATIC) { |
| 28 // We use the device's memory class to decide the maximum renderer |
| 29 // processes. For the baseline devices the memory class is 16 and we
will |
| 30 // limit it to one render process. For the devices with memory class
24, |
| 31 // we allow two render processes. |
| 32 ActivityManager am = (ActivityManager)context.getSystemService( |
| 33 Context.ACTIVITY_SERVICE); |
| 34 maxRendererProcesses = Math.max(((am.getMemoryClass() - 8) / 8), 1); |
| 35 } |
| 36 if (maxRendererProcesses > MAX_RENDERERS_LIMIT) { |
| 37 Log.w(TAG, "Excessive maxRendererProcesses value: " + maxRendererPro
cesses); |
| 38 return MAX_RENDERERS_LIMIT; |
| 39 } |
| 40 return Math.max(0, maxRendererProcesses); |
| 41 } |
| 42 |
| 43 // Automatically decide the number of renderer processes to use based on dev
ice memory class. |
| 44 static final int MAX_RENDERERS_AUTOMATIC = -1; |
| 45 // Use single-process mode that runs the renderer on a separate thread in th
e main application. |
| 46 static final int MAX_RENDERERS_SINGLE_PROCESS = 0; |
| 47 // Cap on the maximum number of renderer processes that can be requested. |
| 48 static final int MAX_RENDERERS_LIMIT = 3; // TODO(tedbo): Raise limit |
| 49 |
| 50 /** |
| 51 * Initialize the process as a ContentView host. This must be called from th
e main UI thread. |
| 52 * This should be called by the ContentView constructor to prepare this proc
ess for ContentView |
| 53 * use outside of the browser. In the case where ContentView is used in the
browser then |
| 54 * initBrowserProcess() should already have been called and this is a no-op. |
| 55 * |
| 56 * @param context Context used to obtain the application context. |
| 57 * @param maxRendererProcesses See ContentView.enableMultiProcess(). |
| 58 */ |
| 59 static void initContentViewProcess(Context context, int maxRendererProcesses
) { |
| 60 genericChromiumProcessInit(context, maxRendererProcesses); |
| 61 } |
| 62 |
| 63 /** |
| 64 * Initialize the platform browser process. This must be called from the mai
n UI thread before |
| 65 * accessing ContentView in order to treat this as a browser process. |
| 66 * |
| 67 * @param context Context used to obtain the application context. |
| 68 * @param maxRendererProcesses See ContentView.enableMultiProcess(). |
| 69 */ |
| 70 static void initChromiumBrowserProcess(Context context, int maxRendererProce
sses) { |
| 71 genericChromiumProcessInit(context, maxRendererProcesses); |
| 72 } |
| 73 |
| 74 /** |
| 75 * Shared implementation for the initXxx methods. |
| 76 * @param context Context used to obtain the application context |
| 77 * @param maxRendererProcesses See ContentView.enableMultiProcess() |
| 78 */ |
| 79 private static void genericChromiumProcessInit(Context context, int maxRende
rerProcesses) { |
| 80 if (sInitialized) { |
| 81 return; |
| 82 } |
| 83 sInitialized = true; |
| 84 |
| 85 // Normally Main.java will have kicked this off asynchronously for Chrom
e. But |
| 86 // other ContentView apps like tests also need them so we make sure we'v
e |
| 87 // extracted resources here. We can still make it a little async (wait u
ntil |
| 88 // the library is loaded). |
| 89 // TODO (michaelbai): Upstream ResourceExtractor. |
| 90 // ResourceExtractor resourceExtractor = ResourceExtractor.get(context); |
| 91 // resourceExtractor.startExtractingResources(); |
| 92 |
| 93 // Normally Main.java will have already loaded the library asynchronousl
y, we only |
| 94 // need to load it here if we arrived via another flow, e.g. bookmark ac
cess & sync setup. |
| 95 LibraryLoader.loadAndInitSync(); |
| 96 |
| 97 Context appContext = context.getApplicationContext(); |
| 98 |
| 99 int maxRenderers = normalizeMaxRendererProcesses(appContext, maxRenderer
Processes); |
| 100 Log.i(TAG, "Initializing chromium process, renderers=" + maxRenderers); |
| 101 |
| 102 nativeInitBrowserProcess(appContext, maxRenderers, getPlugins(context)); |
| 103 } |
| 104 |
| 105 private static String getPlugins(final Context context) { |
| 106 Log.i(TAG, "BrowserProcessMain.getPlugins() is NOT upstreamed."); |
| 107 return ""; |
| 108 } |
| 109 |
| 110 // Prepare the process for browser/ContentView use. See browser_process_main
.{h,cc}. |
| 111 private static native void nativeInitBrowserProcess(Context applicationConte
xt, |
| 112 int maxRenderProcesses, String plugin_descriptor); |
| 113 |
| 114 // Is this an official build of Chrome? Only native code knows |
| 115 // for sure. Official build knowledge is needed very early in |
| 116 // process startup. |
| 117 private static native boolean nativeIsOfficialBuild(); |
| 118 } |
OLD | NEW |