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 #include "content/browser/android/browser_process_main.h" |
| 6 |
| 7 #include "base/android/jni_string.h" |
| 8 #include "base/base_switches.h" |
| 9 #include "base/command_line.h" |
| 10 #include "base/debug/debugger.h" |
| 11 #include "base/logging.h" |
| 12 #include "content/browser/android/command_line.h" |
| 13 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 14 #include "content/browser/android/content_startup_flags.h" |
| 15 #endif |
| 16 #include "content/browser/device_orientation/data_fetcher_impl_android.h" |
| 17 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 18 #include "content/browser/geolocation/android_location_api_adapter.h" |
| 19 #endif |
| 20 #include "content/common/android/process_main.h" |
| 21 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 22 #include "content/common/android/surface_texture_peer.h" |
| 23 #endif |
| 24 #include "content/public/app/content_main_runner.h" |
| 25 #include "content/public/common/content_constants.h" |
| 26 #include "jni/browser_process_main_jni.h" |
| 27 |
| 28 using base::android::ConvertJavaStringToUTF8; |
| 29 |
| 30 namespace { |
| 31 |
| 32 content::ContentMainRunner* g_content_runner = NULL; |
| 33 |
| 34 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 35 |
| 36 class SurfaceTexturePeerBrowserImpl : public SurfaceTexturePeer { |
| 37 public: |
| 38 SurfaceTexturePeerBrowserImpl() { |
| 39 } |
| 40 |
| 41 virtual ~SurfaceTexturePeerBrowserImpl() { |
| 42 } |
| 43 |
| 44 virtual void EstablishSurfaceTexturePeer(base::ProcessHandle pid, |
| 45 SurfaceTextureTarget type, |
| 46 jobject j_surface_texture, |
| 47 int primary_id, |
| 48 int secondary_id) { |
| 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 50 DCHECK(env); |
| 51 Java_BrowserProcessMain_establishSurfaceTexturePeer(env, pid, type, |
| 52 j_surface_texture, primary_id, secondary_id); |
| 53 } |
| 54 |
| 55 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerBrowserImpl); |
| 57 }; |
| 58 |
| 59 #endif // !defined(ANDROID_UPSTREAM_BRINGUP) |
| 60 |
| 61 } // namespace <anonymous> |
| 62 |
| 63 static void InitBrowserProcess(JNIEnv* env, jclass /* clazz */, |
| 64 jobject context, |
| 65 jint max_render_process_count, |
| 66 jstring plugin_descriptor) { |
| 67 if (g_content_runner) { |
| 68 LOG(WARNING) << "InitBrowserProcess has been called before"; |
| 69 return; |
| 70 } |
| 71 |
| 72 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 73 if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) { |
| 74 LOG(ERROR) << "Browser waiting for GDB because flag " |
| 75 << switches::kWaitForDebugger << " was supplied."; |
| 76 base::debug::WaitForDebugger(24*60*60, false); |
| 77 } |
| 78 |
| 79 std::string plugin_str = ConvertJavaStringToUTF8(env, plugin_descriptor); |
| 80 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 81 SetContentCommandLineFlags(max_render_process_count, plugin_str); |
| 82 #endif |
| 83 if (!InitProcess(env, context)) |
| 84 return; |
| 85 |
| 86 // common initialization. |
| 87 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 88 SurfaceTexturePeer::InitInstance(new SurfaceTexturePeerBrowserImpl()); |
| 89 device_orientation::DataFetcherImplAndroid::Init(env); |
| 90 AndroidLocationApiAdapter::RegisterGeolocationService(env); |
| 91 #endif |
| 92 // start ContentMainRunner |
| 93 g_content_runner = content::ContentMainRunner::Create(); |
| 94 DCHECK(g_content_runner); |
| 95 |
| 96 g_content_runner->Initialize(0, NULL, g_content_main_delegate); |
| 97 |
| 98 g_content_runner->Run(); |
| 99 |
| 100 return; |
| 101 } |
| 102 |
| 103 static jboolean IsOfficialBuild(JNIEnv* env, jclass /* clazz */) { |
| 104 #if defined(OFFICIAL_BUILD) |
| 105 return true; |
| 106 #else |
| 107 return false; |
| 108 #endif |
| 109 } |
| 110 |
| 111 bool RegisterBrowserProcessMain(JNIEnv* env) { |
| 112 return RegisterNativesImpl(env); |
| 113 } |
OLD | NEW |