| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/app/android/sandboxed_process_service.h" | 5 #include "content/app/android/child_process_service.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 #include <cpu-features.h> | 8 #include <cpu-features.h> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/posix/global_descriptors.h" | 12 #include "base/posix/global_descriptors.h" |
| 13 #include "content/common/android/scoped_java_surface.h" | 13 #include "content/common/android/scoped_java_surface.h" |
| 14 #include "content/common/android/surface_texture_peer.h" | 14 #include "content/common/android/surface_texture_peer.h" |
| 15 #include "content/common/child_process.h" | 15 #include "content/common/child_process.h" |
| 16 #include "content/common/child_thread.h" | 16 #include "content/common/child_thread.h" |
| 17 #include "content/common/gpu/gpu_surface_lookup.h" | 17 #include "content/common/gpu/gpu_surface_lookup.h" |
| 18 #include "content/public/app/android_library_loader_hooks.h" | 18 #include "content/public/app/android_library_loader_hooks.h" |
| 19 #include "content/public/common/content_descriptors.h" | 19 #include "content/public/common/content_descriptors.h" |
| 20 #include "ipc/ipc_descriptors.h" | 20 #include "ipc/ipc_descriptors.h" |
| 21 #include "jni/SandboxedProcessService_jni.h" | 21 #include "jni/ChildProcessService_jni.h" |
| 22 | 22 |
| 23 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
| 24 using base::android::CheckException; | 24 using base::android::CheckException; |
| 25 using base::android::JavaIntArrayToIntVector; | 25 using base::android::JavaIntArrayToIntVector; |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer, | 31 class SurfaceTexturePeerChildImpl : public content::SurfaceTexturePeer, |
| 32 public content::GpuSurfaceLookup { | 32 public content::GpuSurfaceLookup { |
| 33 public: | 33 public: |
| 34 // |service| is the instance of | 34 // |service| is the instance of |
| 35 // org.chromium.content.app.SandboxedProcessService. | 35 // org.chromium.content.app.ChildProcessService. |
| 36 explicit SurfaceTexturePeerSandboxedImpl( | 36 explicit SurfaceTexturePeerChildImpl( |
| 37 const base::android::ScopedJavaLocalRef<jobject>& service) | 37 const base::android::ScopedJavaLocalRef<jobject>& service) |
| 38 : service_(service) { | 38 : service_(service) { |
| 39 GpuSurfaceLookup::InitInstance(this); | 39 GpuSurfaceLookup::InitInstance(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual ~SurfaceTexturePeerSandboxedImpl() { | 42 virtual ~SurfaceTexturePeerChildImpl() { |
| 43 GpuSurfaceLookup::InitInstance(NULL); | 43 GpuSurfaceLookup::InitInstance(NULL); |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual void EstablishSurfaceTexturePeer( | 46 virtual void EstablishSurfaceTexturePeer( |
| 47 base::ProcessHandle pid, | 47 base::ProcessHandle pid, |
| 48 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, | 48 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, |
| 49 int primary_id, | 49 int primary_id, |
| 50 int secondary_id) { | 50 int secondary_id) { |
| 51 JNIEnv* env = base::android::AttachCurrentThread(); | 51 JNIEnv* env = base::android::AttachCurrentThread(); |
| 52 content::Java_SandboxedProcessService_establishSurfaceTexturePeer( | 52 content::Java_ChildProcessService_establishSurfaceTexturePeer( |
| 53 env, service_.obj(), pid, | 53 env, service_.obj(), pid, |
| 54 surface_texture_bridge->j_surface_texture().obj(), primary_id, | 54 surface_texture_bridge->j_surface_texture().obj(), primary_id, |
| 55 secondary_id); | 55 secondary_id); |
| 56 CheckException(env); | 56 CheckException(env); |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE { | 59 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE { |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); | 60 JNIEnv* env = base::android::AttachCurrentThread(); |
| 61 ScopedJavaSurface surface( | 61 ScopedJavaSurface surface( |
| 62 content::Java_SandboxedProcessService_getViewSurface( | 62 content::Java_ChildProcessService_getViewSurface( |
| 63 env, service_.obj(), surface_id)); | 63 env, service_.obj(), surface_id)); |
| 64 | 64 |
| 65 if (surface.j_surface().is_null()) | 65 if (surface.j_surface().is_null()) |
| 66 return NULL; | 66 return NULL; |
| 67 | 67 |
| 68 ANativeWindow* native_window = ANativeWindow_fromSurface( | 68 ANativeWindow* native_window = ANativeWindow_fromSurface( |
| 69 env, surface.j_surface().obj()); | 69 env, surface.j_surface().obj()); |
| 70 | 70 |
| 71 return native_window; | 71 return native_window; |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 // The instance of org.chromium.content.app.SandboxedProcessService. | 75 // The instance of org.chromium.content.app.ChildProcessService. |
| 76 base::android::ScopedJavaGlobalRef<jobject> service_; | 76 base::android::ScopedJavaGlobalRef<jobject> service_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); | 78 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Chrome actually uses the renderer code path for all of its sandboxed | 81 // Chrome actually uses the renderer code path for all of its child |
| 82 // processes such as renderers, plugins, etc. | 82 // processes such as renderers, plugins, etc. |
| 83 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, | 83 void InternalInitChildProcess(const std::vector<int>& file_ids, |
| 84 const std::vector<int>& file_fds, | 84 const std::vector<int>& file_fds, |
| 85 JNIEnv* env, | 85 JNIEnv* env, |
| 86 jclass clazz, | 86 jclass clazz, |
| 87 jobject context, | 87 jobject context, |
| 88 jobject service_in, | 88 jobject service_in, |
| 89 jint cpu_count, | 89 jint cpu_count, |
| 90 jlong cpu_features) { | 90 jlong cpu_features) { |
| 91 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); | 91 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); |
| 92 | 92 |
| 93 // Set the CPU properties. | 93 // Set the CPU properties. |
| 94 android_setCpu(cpu_count, cpu_features); | 94 android_setCpu(cpu_count, cpu_features); |
| 95 // Register the file descriptors. | 95 // Register the file descriptors. |
| 96 // This includes the IPC channel, the crash dump signals and resource related | 96 // This includes the IPC channel, the crash dump signals and resource related |
| 97 // files. | 97 // files. |
| 98 DCHECK(file_fds.size() == file_ids.size()); | 98 DCHECK(file_fds.size() == file_ids.size()); |
| 99 for (size_t i = 0; i < file_ids.size(); ++i) | 99 for (size_t i = 0; i < file_ids.size(); ++i) |
| 100 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 100 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
| 101 | 101 |
| 102 content::SurfaceTexturePeer::InitInstance( | 102 content::SurfaceTexturePeer::InitInstance( |
| 103 new SurfaceTexturePeerSandboxedImpl(service)); | 103 new SurfaceTexturePeerChildImpl(service)); |
| 104 | 104 |
| 105 } | 105 } |
| 106 | 106 |
| 107 void QuitSandboxMainThreadMessageLoop() { | 107 void QuitMainThreadMessageLoop() { |
| 108 MessageLoop::current()->Quit(); | 108 MessageLoop::current()->Quit(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace <anonymous> | 111 } // namespace <anonymous> |
| 112 | 112 |
| 113 void InitSandboxedProcess(JNIEnv* env, | 113 void InitChildProcess(JNIEnv* env, |
| 114 jclass clazz, | 114 jclass clazz, |
| 115 jobject context, | 115 jobject context, |
| 116 jobject service, | 116 jobject service, |
| 117 jintArray j_file_ids, | 117 jintArray j_file_ids, |
| 118 jintArray j_file_fds, | 118 jintArray j_file_fds, |
| 119 jint cpu_count, | 119 jint cpu_count, |
| 120 jlong cpu_features) { | 120 jlong cpu_features) { |
| 121 std::vector<int> file_ids; | 121 std::vector<int> file_ids; |
| 122 std::vector<int> file_fds; | 122 std::vector<int> file_fds; |
| 123 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); | 123 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); |
| 124 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); | 124 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); |
| 125 | 125 |
| 126 InternalInitSandboxedProcess( | 126 InternalInitChildProcess( |
| 127 file_ids, file_fds, env, clazz, context, service, | 127 file_ids, file_fds, env, clazz, context, service, |
| 128 cpu_count, cpu_features); | 128 cpu_count, cpu_features); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { | 131 void ExitChildProcess(JNIEnv* env, jclass clazz) { |
| 132 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; | 132 LOG(INFO) << "ChildProcessService: Exiting child process."; |
| 133 LibraryLoaderExitHook(); | 133 LibraryLoaderExitHook(); |
| 134 _exit(0); | 134 _exit(0); |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool RegisterSandboxedProcessService(JNIEnv* env) { | 137 bool RegisterChildProcessService(JNIEnv* env) { |
| 138 return RegisterNativesImpl(env); | 138 return RegisterNativesImpl(env); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { | 141 void ShutdownMainThread(JNIEnv* env, jobject obj) { |
| 142 ChildProcess* current_process = ChildProcess::current(); | 142 ChildProcess* current_process = ChildProcess::current(); |
| 143 if (!current_process) | 143 if (!current_process) |
| 144 return; | 144 return; |
| 145 ChildThread* main_child_thread = current_process->main_thread(); | 145 ChildThread* main_child_thread = current_process->main_thread(); |
| 146 if (main_child_thread && main_child_thread->message_loop()) | 146 if (main_child_thread && main_child_thread->message_loop()) |
| 147 main_child_thread->message_loop()->PostTask(FROM_HERE, | 147 main_child_thread->message_loop()->PostTask(FROM_HERE, |
| 148 base::Bind(&QuitSandboxMainThreadMessageLoop)); | 148 base::Bind(&QuitMainThreadMessageLoop)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace content | 151 } // namespace content |
| OLD | NEW |