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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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(Conte xt.ACTIVITY_SERVICE);
33 maxRendererProcesses = Math.max(((am.getMemoryClass() - 8) / 8), 1);
34 }
35 if (maxRendererProcesses > MAX_RENDERERS_LIMIT) {
36 Log.w(TAG, "Excessive maxRendererProcesses value: " + maxRendererPro cesses);
37 return MAX_RENDERERS_LIMIT;
38 }
39 return Math.max(0, maxRendererProcesses);
40 }
41
42 // Automatically decide the number of renderer processes to use based on dev ice memory class.
43 static final int MAX_RENDERERS_AUTOMATIC = -1;
44 // Use single-process mode that runs the renderer on a separate thread in th e main application.
45 static final int MAX_RENDERERS_SINGLE_PROCESS = 0;
46 // Cap on the maximum number of renderer processes that can be requested.
47 static final int MAX_RENDERERS_LIMIT = 3; // TODO(tedbo): Raise limit
48
49 /**
50 * Initialize the process as a ContentView host. This must be called from th e main UI thread.
51 * This should be called by the ContentView constructor to prepare this proc ess for ContentView
52 * use outside of the browser. In the case where ContentView is used in the browser then
53 * initBrowserProcess() should already have been called and this is a no-op.
54 *
55 * @param context Context used to obtain the application context.
56 * @param maxRendererProcesses See ContentView.enableMultiProcess().
57 */
58 static void initContentViewProcess(Context context, int maxRendererProcesses ) {
59 Log.i(TAG, "initContentViewProcess");
60 genericChromiumProcessInit(context, maxRendererProcesses, false);
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 Log.i(TAG, "initChromiumBrowserProcess");
72 genericChromiumProcessInit(context, maxRendererProcesses, true);
73 }
74
75 /**
76 * Shared implementation for the initXxx methods.
77 * @param context Context used to obtain the application context
78 * @param maxRendererProcesses See ContentView.enableMultiProcess()
79 * @param hostIsChrome pass true if running as the system browser process.
80 */
81 private static void genericChromiumProcessInit(Context context, int maxRende rerProcesses,
82 boolean hostIsChrome) {
83 if (sInitialized) {
84 return;
85 }
86 sInitialized = true;
87
88 // Normally Main.java will have kicked this off asynchronously for Chrom e. But
89 // other ContentView apps like tests also need them so we make sure we'v e
90 // extracted resources here. We can still make it a little async (wait u ntil
91 // the library is loaded).
92 // ResourceExtractor resourceExtractor = ResourceExtractor.get(context);
Yaron 2012/05/22 20:07:13 Add a TODO(michaelbai): Upstream this.
michaelbai 2012/05/22 20:39:56 Done.
93 // resourceExtractor.startExtractingResources();
94
95 // Normally Main.java will have already loaded the library asynchronousl y, we only
96 // need to load it here if we arrived via another flow, e.g. bookmark ac cess & sync setup.
97 LibraryLoader.loadAndInitSync();
98
99 Context appContext = context.getApplicationContext();
100
101 int maxRenderers = normalizeMaxRendererProcesses(appContext, maxRenderer Processes);
102 Log.i(TAG, "Initializing chromium process, renderers=" + maxRenderers +
103 " hostIsChrome=" + hostIsChrome);
104
105 nativeInitBrowserProcess(appContext, maxRenderers, getPlugins(context));
106 }
107
108 private static String getPlugins(final Context context) {
109 Log.i(TAG, "BrowserProcessMain.getPlugins() is NOT upstreamed."
110 return "";
111 }
112
113 // Prepare the process for browser/ContentView use. See browser_process_main .{h,cc}.
114 private static native void nativeInitBrowserProcess(Context applicationConte xt,
115 int maxRenderProcesses, String plugin_descriptor);
116
117 // Is this an official build of Chrome? Only native code knows
118 // for sure. Official build knowledge is needed very early in
119 // process startup.
120 private static native boolean nativeIsOfficialBuild();
121 }
OLDNEW
« content/browser/android/browser_process_main.cc ('K') | « content/content_jni.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698