Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1796)

Unified Diff: content/public/android/java/org/chromium/content/browser/BrowserProcessMain.java

Issue 10399129: Added browser_process_main. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Java file style Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_jni.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/org/chromium/content/browser/BrowserProcessMain.java
diff --git a/content/public/android/java/org/chromium/content/browser/BrowserProcessMain.java b/content/public/android/java/org/chromium/content/browser/BrowserProcessMain.java
new file mode 100644
index 0000000000000000000000000000000000000000..5877e52b9e103e1aadccfd4c6184108be512846d
--- /dev/null
+++ b/content/public/android/java/org/chromium/content/browser/BrowserProcessMain.java
@@ -0,0 +1,118 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.SurfaceTexture;
+import android.util.Log;
+import android.view.Surface;
+
+import org.chromium.base.CalledByNative;
+
+// NOTE: The un-upstreamed features have been removed from this file, please
+// don't merge this file to the downstream.
+class BrowserProcessMain {
+
+ private static final String TAG = "BrowserProcessMain";
+
+ // Prevents initializing the process more than once.
+ private static boolean sInitialized = false;
+
+ // Computes the actual max renderer processes used.
+ private static int normalizeMaxRendererProcesses(Context context, int maxRendererProcesses) {
+ if (maxRendererProcesses == MAX_RENDERERS_AUTOMATIC) {
+ // We use the device's memory class to decide the maximum renderer
+ // processes. For the baseline devices the memory class is 16 and we will
+ // limit it to one render process. For the devices with memory class 24,
+ // we allow two render processes.
+ ActivityManager am = (ActivityManager)context.getSystemService(
+ Context.ACTIVITY_SERVICE);
+ maxRendererProcesses = Math.max(((am.getMemoryClass() - 8) / 8), 1);
+ }
+ if (maxRendererProcesses > MAX_RENDERERS_LIMIT) {
+ Log.w(TAG, "Excessive maxRendererProcesses value: " + maxRendererProcesses);
+ return MAX_RENDERERS_LIMIT;
+ }
+ return Math.max(0, maxRendererProcesses);
+ }
+
+ // Automatically decide the number of renderer processes to use based on device memory class.
+ static final int MAX_RENDERERS_AUTOMATIC = -1;
+ // Use single-process mode that runs the renderer on a separate thread in the main application.
+ static final int MAX_RENDERERS_SINGLE_PROCESS = 0;
+ // Cap on the maximum number of renderer processes that can be requested.
+ static final int MAX_RENDERERS_LIMIT = 3; // TODO(tedbo): Raise limit
+
+ /**
+ * Initialize the process as a ContentView host. This must be called from the main UI thread.
+ * This should be called by the ContentView constructor to prepare this process for ContentView
+ * use outside of the browser. In the case where ContentView is used in the browser then
+ * initBrowserProcess() should already have been called and this is a no-op.
+ *
+ * @param context Context used to obtain the application context.
+ * @param maxRendererProcesses See ContentView.enableMultiProcess().
+ */
+ static void initContentViewProcess(Context context, int maxRendererProcesses) {
+ genericChromiumProcessInit(context, maxRendererProcesses);
+ }
+
+ /**
+ * Initialize the platform browser process. This must be called from the main UI thread before
+ * accessing ContentView in order to treat this as a browser process.
+ *
+ * @param context Context used to obtain the application context.
+ * @param maxRendererProcesses See ContentView.enableMultiProcess().
+ */
+ static void initChromiumBrowserProcess(Context context, int maxRendererProcesses) {
+ genericChromiumProcessInit(context, maxRendererProcesses);
+ }
+
+ /**
+ * Shared implementation for the initXxx methods.
+ * @param context Context used to obtain the application context
+ * @param maxRendererProcesses See ContentView.enableMultiProcess()
+ */
+ private static void genericChromiumProcessInit(Context context, int maxRendererProcesses) {
+ if (sInitialized) {
+ return;
+ }
+ sInitialized = true;
+
+ // Normally Main.java will have kicked this off asynchronously for Chrome. But
+ // other ContentView apps like tests also need them so we make sure we've
+ // extracted resources here. We can still make it a little async (wait until
+ // the library is loaded).
+ // TODO (michaelbai): Upstream ResourceExtractor.
+ // ResourceExtractor resourceExtractor = ResourceExtractor.get(context);
+ // resourceExtractor.startExtractingResources();
+
+ // Normally Main.java will have already loaded the library asynchronously, we only
+ // need to load it here if we arrived via another flow, e.g. bookmark access & sync setup.
+ LibraryLoader.loadAndInitSync();
+
+ Context appContext = context.getApplicationContext();
+
+ int maxRenderers = normalizeMaxRendererProcesses(appContext, maxRendererProcesses);
+ Log.i(TAG, "Initializing chromium process, renderers=" + maxRenderers);
+
+ nativeInitBrowserProcess(appContext, maxRenderers, getPlugins(context));
+ }
+
+ private static String getPlugins(final Context context) {
+ Log.i(TAG, "BrowserProcessMain.getPlugins() is NOT upstreamed.");
+ return "";
+ }
+
+ // Prepare the process for browser/ContentView use. See browser_process_main.{h,cc}.
+ private static native void nativeInitBrowserProcess(Context applicationContext,
+ int maxRenderProcesses, String plugin_descriptor);
+
+ // Is this an official build of Chrome? Only native code knows
+ // for sure. Official build knowledge is needed very early in
+ // process startup.
+ private static native boolean nativeIsOfficialBuild();
+}
« no previous file with comments | « content/content_jni.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698