summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authormichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-04 21:48:12 +0000
committermichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-04 21:48:12 +0000
commit7bd891779b56530e58baa770aff55b7c65956eb6 (patch)
tree8a2d8ce25bac8f57d5faa3f56e84805dfa492431 /content
parente135f7e496a18a6e40e87086c79c2932b3954528 (diff)
downloadchromium_src-7bd891779b56530e58baa770aff55b7c65956eb6.zip
chromium_src-7bd891779b56530e58baa770aff55b7c65956eb6.tar.gz
chromium_src-7bd891779b56530e58baa770aff55b7c65956eb6.tar.bz2
As part of the content_shell bring up, some un-upstreamed features
have been disabled in browser process main related c++ and Java file. The disabled features are guarded by !defined(ANDROID_UPSTREAM_BRINGUP). For Java file, the code was removed. Fixed the dependency. - Moved the content_jni_registrar.{h|cc} and library_loader_hooks.cc content/app/android/ - Moved the android_library_loader_hooks.h to content/public/app/ BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10444121 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/app/DEPS1
-rw-r--r--content/app/android/content_jni_registrar.cc4
-rw-r--r--content/app/android/content_main.cc76
-rw-r--r--content/app/android/content_main.h17
-rw-r--r--content/browser/android/android_browser_process.cc43
-rw-r--r--content/browser/android/android_browser_process.h17
-rw-r--r--content/content_app.gypi13
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/content_jni.gypi4
-rw-r--r--content/public/android/java/org/chromium/content/app/ContentMain.java36
-rw-r--r--content/public/android/java/org/chromium/content/browser/AndroidBrowserProcess.java112
-rw-r--r--content/public/android/java/org/chromium/content/browser/ContentView.java4
-rw-r--r--content/public/app/content_main.h9
-rw-r--r--content/shell/android/shell_library_loader.cc29
14 files changed, 340 insertions, 27 deletions
diff --git a/content/app/DEPS b/content/app/DEPS
index 321c9ff..7ed77a8 100644
--- a/content/app/DEPS
+++ b/content/app/DEPS
@@ -1,4 +1,5 @@
include_rules = [
"+content",
"+media/base", # For initializing media library.
+ "+jni", # For generated JNI includes
]
diff --git a/content/app/android/content_jni_registrar.cc b/content/app/android/content_jni_registrar.cc
index e9c8e00..d894f71 100644
--- a/content/app/android/content_jni_registrar.cc
+++ b/content/app/android/content_jni_registrar.cc
@@ -6,6 +6,8 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
+#include "content/app/android/content_main.h"
+#include "content/browser/android/android_browser_process.h"
#include "content/browser/android/command_line.h"
#include "content/browser/android/download_controller.h"
#include "content/browser/android/trace_event_binding.h"
@@ -14,7 +16,9 @@ namespace content {
namespace android {
base::android::RegistrationMethod kContentRegisteredMethods[] = {
+ { "AndroidBrowserProcess", content::RegisterAndroidBrowserProcess },
{ "CommandLine", RegisterCommandLine },
+ { "ContentMain", content::RegisterContentMain },
{ "DownloadController", DownloadController::RegisterDownloadController },
{ "TraceEvent", RegisterTraceEvent },
};
diff --git a/content/app/android/content_main.cc b/content/app/android/content_main.cc
new file mode 100644
index 0000000..c517778
--- /dev/null
+++ b/content/app/android/content_main.cc
@@ -0,0 +1,76 @@
+// 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.
+
+#include "content/app/android/content_main.h"
+
+#include "base/base_switches.h"
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#if !defined(ANDROID_UPSTREAM_BRINGUP)
+#include "content/common/android/user_agent.h"
+#endif
+#include "content/public/app/content_main_delegate.h"
+#include "content/public/app/content_main_runner.h"
+#include "content/public/common/content_switches.h"
+#include "jni/content_main_jni.h"
+#if !defined(ANDROID_UPSTREAM_BRINGUP)
+#include "webkit/glue/user_agent.h"
+#endif
+
+using base::LazyInstance;
+using content::ContentMainRunner;
+using content::ContentMainDelegate;
+
+namespace {
+LazyInstance<scoped_ptr<ContentMainRunner> > g_content_runner =
+ LAZY_INSTANCE_INITIALIZER;
+
+LazyInstance<scoped_ptr<ContentMainDelegate> > g_content_main_delegate =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+static void InitApplicationContext(JNIEnv* env,
+ _jclass* clazz,
+ _jobject* context) {
+ base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
+ base::android::InitApplicationContext(scoped_context);
+}
+
+static jint Start(JNIEnv* env, jclass clazz) {
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
+
+ // This is only for browser process. We want to start waiting as early as
+ // possible though here is the common initialization code.
+ if (parsed_command_line.HasSwitch(switches::kWaitForDebugger) &&
+ "" == parsed_command_line.GetSwitchValueASCII(switches::kProcessType)) {
+ LOG(ERROR) << "Browser waiting for GDB because flag "
+ << switches::kWaitForDebugger << " was supplied.";
+ base::debug::WaitForDebugger(24*60*60, false);
+ }
+
+#if !defined(ANDROID_UPSTREAM_BRINGUP)
+ webkit_glue::InitUserAgent(GetUserAgentOSInfo());
+#endif
+
+ DCHECK(!g_content_runner.Get().get());
+ g_content_runner.Get().reset(ContentMainRunner::Create());
+ g_content_runner.Get()->Initialize(0, NULL,
+ g_content_main_delegate.Get().get());
+ return g_content_runner.Get()->Run();
+}
+
+namespace content {
+
+void SetContentMainDelegate(ContentMainDelegate* delegate) {
+ DCHECK(!g_content_main_delegate.Get().get());
+ g_content_main_delegate.Get().reset(delegate);
+}
+
+bool RegisterContentMain(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace content
diff --git a/content/app/android/content_main.h b/content/app/android/content_main.h
new file mode 100644
index 0000000..cc48cd7
--- /dev/null
+++ b/content/app/android/content_main.h
@@ -0,0 +1,17 @@
+// 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.
+
+#ifndef CONTENT_APP_ANDROID_CONTENT_MAIN_H_
+#define CONTENT_APP_ANDROID_CONTENT_MAIN_H_
+#pragma once
+
+#include <jni.h>
+
+namespace content {
+
+bool RegisterContentMain(JNIEnv* env);
+
+} // namespace content
+
+#endif // CONTENT_APP_ANDROID_CONTENT_MAIN_H_
diff --git a/content/browser/android/android_browser_process.cc b/content/browser/android/android_browser_process.cc
new file mode 100644
index 0000000..2ac511b
--- /dev/null
+++ b/content/browser/android/android_browser_process.cc
@@ -0,0 +1,43 @@
+// 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.
+
+#include "content/browser/android/android_browser_process.h"
+
+#include "base/android/jni_string.h"
+#include "base/debug/debugger.h"
+#include "base/logging.h"
+#if !defined(ANDROID_UPSTREAM_BRINGUP)
+#include "content/browser/android/content_startup_flags.h"
+#include "content/common/android/command_line.h"
+#endif
+#include "content/public/common/content_constants.h"
+#include "jni/android_browser_process_jni.h"
+
+using base::android::ConvertJavaStringToUTF8;
+
+static void SetCommandLineFlags(JNIEnv*env,
+ jclass clazz,
+ jint max_render_process_count,
+ jstring plugin_descriptor) {
+ std::string plugin_str = ConvertJavaStringToUTF8(env, plugin_descriptor);
+#if !defined(ANDROID_UPSTREAM_BRINGUP)
+ SetContentCommandLineFlags(max_render_process_count, plugin_str);
+#endif
+}
+
+static jboolean IsOfficialBuild(JNIEnv* env, jclass clazz) {
+#if defined(OFFICIAL_BUILD)
+ return true;
+#else
+ return false;
+#endif
+}
+
+namespace content {
+
+bool RegisterAndroidBrowserProcess(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace
diff --git a/content/browser/android/android_browser_process.h b/content/browser/android/android_browser_process.h
new file mode 100644
index 0000000..df1b365
--- /dev/null
+++ b/content/browser/android/android_browser_process.h
@@ -0,0 +1,17 @@
+// 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.
+
+#ifndef CONTENT_APP_ANDROID_ANDROID_BROWSER_PROCESS_H_
+#define CONTENT_APP_ANDROID_ANDROID_BROWSER_PROCESS_H_
+#pragma once
+
+#include <jni.h>
+
+namespace content {
+
+bool RegisterAndroidBrowserProcess(JNIEnv* env);
+
+} // namespace content
+
+#endif // CONTENT_APP_ANDROID_ANDROID_BROWSER_PROCESS_H_
diff --git a/content/content_app.gypi b/content/content_app.gypi
index 07f7b5a..ec457ff 100644
--- a/content/content_app.gypi
+++ b/content/content_app.gypi
@@ -15,6 +15,8 @@
'sources': [
'app/android/content_jni_registrar.cc',
'app/android/content_jni_registrar.h',
+ 'app/android/content_main.cc',
+ 'app/android/content_main.h',
'app/android/library_loader_hooks.cc',
'app/content_main.cc',
'app/content_main_runner.cc',
@@ -32,5 +34,16 @@
'../sandbox/sandbox.gyp:sandbox',
],
}],
+ ['OS=="android"', {
+ 'source!': [
+ 'app/content_main.cc',
+ ],
+ 'include_dirs': [
+ '<(SHARED_INTERMEDIATE_DIR)/content',
+ ],
+ 'dependencies': [
+ 'content.gyp:content_jni_headers',
+ ],
+ }],
],
}
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 010110a..6839c94 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -184,6 +184,8 @@
'browser/accessibility/browser_accessibility_state_impl.h',
'browser/accessibility/browser_accessibility_win.cc',
'browser/accessibility/browser_accessibility_win.h',
+ 'browser/android/android_browser_process.cc',
+ 'browser/android/android_browser_process.h',
'browser/android/command_line.cc',
'browser/android/command_line.h',
'browser/android/download_controller.cc',
diff --git a/content/content_jni.gypi b/content/content_jni.gypi
index 230a0e9..42d2acc 100644
--- a/content/content_jni.gypi
+++ b/content/content_jni.gypi
@@ -9,6 +9,8 @@
# output directories (e.g. browser/jni and common/jni if needed).
'variables': {
'java_sources': [
+ 'public/android/java/org/chromium/content/app/ContentMain.java',
+ 'public/android/java/org/chromium/content/browser/AndroidBrowserProcess.java',
'public/android/java/org/chromium/content/browser/CommandLine.java',
'public/android/java/org/chromium/content/browser/DeviceOrientation.java',
'public/android/java/org/chromium/content/browser/DownloadController.java',
@@ -18,6 +20,8 @@
'public/android/java/org/chromium/content/browser/TraceEvent.java',
],
'jni_headers': [
+ '<(SHARED_INTERMEDIATE_DIR)/content/jni/content_main_jni.h',
+ '<(SHARED_INTERMEDIATE_DIR)/content/jni/android_browser_process_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/command_line_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/device_orientation_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/content/jni/download_controller_jni.h',
diff --git a/content/public/android/java/org/chromium/content/app/ContentMain.java b/content/public/android/java/org/chromium/content/app/ContentMain.java
new file mode 100644
index 0000000..a97d12b
--- /dev/null
+++ b/content/public/android/java/org/chromium/content/app/ContentMain.java
@@ -0,0 +1,36 @@
+// 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.app;
+
+import android.content.Context;
+
+/**
+ * This class is used to initialize all types of process. It corresponds to
+ * content/public/app/content_main.h which is not used in Android as it has
+ * the different initialization process.
+ *
+ * TODO (michaelbai): Refactorying the BrowserProcessMain.java and the
+ * SandboxedProcessService.java to start ContentMain, and run the process
+ * specific initialization code in ContentMainRunner::Initialize.
+ *
+ **/
+public class ContentMain {
+ /**
+ * Initialize application context in native side.
+ **/
+ public static void initApplicationContext(Context context) {
+ nativeInitApplicationContext(context);
+ }
+
+ /**
+ * Start the ContentMainRunner in native side.
+ **/
+ public static int start() {
+ return nativeStart();
+ }
+
+ private static native void nativeInitApplicationContext(Context context);
+ private static native int nativeStart();
+};
diff --git a/content/public/android/java/org/chromium/content/browser/AndroidBrowserProcess.java b/content/public/android/java/org/chromium/content/browser/AndroidBrowserProcess.java
new file mode 100644
index 0000000..166627a
--- /dev/null
+++ b/content/public/android/java/org/chromium/content/browser/AndroidBrowserProcess.java
@@ -0,0 +1,112 @@
+// 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.util.Log;
+
+import org.chromium.content.app.ContentMain;
+import org.chromium.content.browser.ContentView;
+import org.chromium.content.browser.LibraryLoader;
+
+// NOTE: This file hasn't been fully upstreamed, please don't merge to downstream.
+public class AndroidBrowserProcess {
+
+ 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.
+ public static final int MAX_RENDERERS_AUTOMATIC = -1;
+ // Use single-process mode that runs the renderer on a separate thread in the main application.
+ public static final int MAX_RENDERERS_SINGLE_PROCESS = 0;
+ // Cap on the maximum number of renderer processes that can be requested.
+ public 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().
+ */
+ public static void initContentViewProcess(Context context, int maxRendererProcesses) {
+ genericChromiumProcessInit(context, maxRendererProcesses, false);
+ }
+
+ /**
+ * 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().
+ */
+ public static void initChromiumBrowserProcess(Context context, int maxRendererProcesses) {
+ genericChromiumProcessInit(context, maxRendererProcesses, true);
+ }
+
+ /**
+ * Shared implementation for the initXxx methods.
+ * @param context Context used to obtain the application context
+ * @param maxRendererProcesses See ContentView.enableMultiProcess()
+ * @param hostIsChrome pass true if running as the system browser process.
+ */
+ private static void genericChromiumProcessInit(Context context, int maxRendererProcesses,
+ boolean hostIsChrome) {
+ if (sInitialized) {
+ return;
+ }
+ sInitialized = true;
+
+ // 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 +
+ " hostIsChrome=" + hostIsChrome);
+
+ nativeSetCommandLineFlags(maxRenderers, getPlugins(context));
+ ContentMain.initApplicationContext(appContext);
+ ContentMain.start();
+ }
+
+ private static String getPlugins(final Context context) {
+ return "";
+ }
+
+ private static native void nativeSetCommandLineFlags(
+ 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();
+}
diff --git a/content/public/android/java/org/chromium/content/browser/ContentView.java b/content/public/android/java/org/chromium/content/browser/ContentView.java
index b0c7f59..299d31b 100644
--- a/content/public/android/java/org/chromium/content/browser/ContentView.java
+++ b/content/public/android/java/org/chromium/content/browser/ContentView.java
@@ -7,6 +7,8 @@ package org.chromium.content.browser;
import android.content.Context;
import android.widget.FrameLayout;
+import org.chromium.content.browser.AndroidBrowserProcess;
+
public class ContentView extends FrameLayout {
/**
@@ -30,7 +32,7 @@ public class ContentView extends FrameLayout {
* maximum number of allowed renderers is capped by MAX_RENDERERS_LIMIT.
*/
public static void enableMultiProcess(Context context, int maxRendererProcesses) {
- // TODO(tedchoc): Implement.
+ AndroidBrowserProcess.initContentViewProcess(context, maxRendererProcesses);
}
/**
diff --git a/content/public/app/content_main.h b/content/public/app/content_main.h
index 6c58a8a..341712d8 100644
--- a/content/public/app/content_main.h
+++ b/content/public/app/content_main.h
@@ -32,11 +32,18 @@ class ContentMainDelegate;
CONTENT_EXPORT int ContentMain(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info,
ContentMainDelegate* delegate);
+#elif defined(OS_ANDROID)
+// In the Android, the content main starts from ContentMain.java, This function
+// provides a way to set the |delegate| as ContentMainDelegate for
+// ContentMainRunner.
+// This should only be called once before ContentMainRunner actually running.
+// The ownership of |delegate| is transferred.
+void SetContentMainDelegate(ContentMainDelegate* delegate);
#else
CONTENT_EXPORT int ContentMain(int argc,
const char** argv,
ContentMainDelegate* delegate);
-#endif
+#endif // defined(OS_WIN)
} // namespace content
diff --git a/content/shell/android/shell_library_loader.cc b/content/shell/android/shell_library_loader.cc
index 39a84ce..e520073 100644
--- a/content/shell/android/shell_library_loader.cc
+++ b/content/shell/android/shell_library_loader.cc
@@ -8,34 +8,18 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "content/public/app/android_library_loader_hooks.h"
-#include "content/public/app/content_main_runner.h"
-#include "content/shell/shell_main_delegate.h"
+#include "content/public/app/content_main.h"
#include "content/shell/android/shell_manager.h"
#include "content/shell/android/shell_view.h"
+#include "content/shell/shell_main_delegate.h"
static base::android::RegistrationMethod kRegistrationMethods[] = {
{ "ShellManager", content::RegisterShellManager },
{ "ShellView", content::ShellView::Register },
};
-namespace {
- content::ContentMainRunner* g_content_main_runner = NULL;
-}
-
// This is called by the VM when the shared library is first loaded.
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
-
- // Don't call anything in base without initializing it.
- // ContentMainRunner will do what we need.
- g_content_main_runner = content::ContentMainRunner::Create();
-
- // TODO(tedchoc): Set this to the main delegate once the Android specific
- // browser process initialization gets checked in.
- ShellMainDelegate* delegate = new ShellMainDelegate();
-
- // TODO(jrg): find command line info from java; pass down in here.
- g_content_main_runner->Initialize(0, NULL, delegate);
-
base::android::InitVM(vm);
JNIEnv* env = base::android::AttachCurrentThread();
if (!content::RegisterLibraryLoaderEntryHook(env)) {
@@ -48,12 +32,7 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
arraysize(kRegistrationMethods)))
return -1;
- return JNI_VERSION_1_4;
-}
-
+ content::SetContentMainDelegate(new ShellMainDelegate());
-JNI_EXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) {
- delete g_content_main_runner;
- g_content_main_runner = NULL;
+ return JNI_VERSION_1_4;
}
-