Chromium Code Reviews| 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 <cpu-features.h> | 7 #include <cpu-features.h> |
| 8 | 8 |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/posix/global_descriptors.h" | 11 #include "base/posix/global_descriptors.h" |
| 12 #include "content/common/android/surface_texture_peer.h" | 12 #include "content/common/android/surface_texture_peer.h" |
| 13 #include "content/common/child_process.h" | 13 #include "content/common/child_process.h" |
| 14 #include "content/common/child_thread.h" | 14 #include "content/common/child_thread.h" |
| 15 #include "content/public/app/android_library_loader_hooks.h" | 15 #include "content/public/app/android_library_loader_hooks.h" |
| 16 #include "content/public/common/content_descriptors.h" | 16 #include "content/public/common/content_descriptors.h" |
| 17 #include "ipc/ipc_descriptors.h" | 17 #include "ipc/ipc_descriptors.h" |
| 18 #include "jni/SandboxedProcessService_jni.h" | 18 #include "jni/ChildProcessService_jni.h" |
| 19 | 19 |
| 20 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
| 21 using base::android::CheckException; | 21 using base::android::CheckException; |
| 22 using base::android::JavaIntArrayToIntVector; | 22 using base::android::JavaIntArrayToIntVector; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer { | 26 class SurfaceTexturePeerChildImpl : public content::SurfaceTexturePeer { |
| 27 public: | 27 public: |
| 28 // |service| is the instance of | 28 // |service| is the instance of |
| 29 // org.chromium.content.app.SandboxedProcessService. | 29 // org.chromium.content.app.ChildProcessService. |
| 30 SurfaceTexturePeerSandboxedImpl(jobject service) | 30 SurfaceTexturePeerChildImpl(jobject service) |
| 31 : service_(service) { | 31 : service_(service) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 virtual ~SurfaceTexturePeerSandboxedImpl() { | 34 virtual ~SurfaceTexturePeerChildImpl() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual void EstablishSurfaceTexturePeer( | 37 virtual void EstablishSurfaceTexturePeer( |
| 38 base::ProcessHandle pid, | 38 base::ProcessHandle pid, |
| 39 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, | 39 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, |
| 40 int primary_id, | 40 int primary_id, |
| 41 int secondary_id) { | 41 int secondary_id) { |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | 42 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 content::Java_SandboxedProcessService_establishSurfaceTexturePeer( | 43 content::Java_ChildProcessService_establishSurfaceTexturePeer( |
| 44 env, service_, pid, | 44 env, service_, pid, |
| 45 surface_texture_bridge->j_surface_texture().obj(), primary_id, | 45 surface_texture_bridge->j_surface_texture().obj(), primary_id, |
| 46 secondary_id); | 46 secondary_id); |
| 47 CheckException(env); | 47 CheckException(env); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // The instance of org.chromium.content.app.SandboxedProcessService. | 51 // The instance of org.chromium.content.app.ChildProcessService. |
| 52 jobject service_; | 52 jobject service_; |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); | 54 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Chrome actually uses the renderer code path for all of its sandboxed | 57 // Chrome actually uses the renderer code path for all of its sandboxed |
| 58 // processes such as renderers, plugins, etc. | 58 // processes such as renderers, plugins, etc. |
| 59 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, | 59 void InternalInitChildProcess(const std::vector<int>& file_ids, |
| 60 const std::vector<int>& file_fds, | 60 const std::vector<int>& file_fds, |
| 61 JNIEnv* env, | 61 JNIEnv* env, |
| 62 jclass clazz, | 62 jclass clazz, |
| 63 jobject context, | 63 jobject context, |
| 64 jobject service, | 64 jobject service, |
| 65 jint cpu_count, | 65 jint cpu_count, |
| 66 jlong cpu_features) { | 66 jlong cpu_features) { |
| 67 // Set the CPU properties. | 67 // Set the CPU properties. |
| 68 android_setCpu(cpu_count, cpu_features); | 68 android_setCpu(cpu_count, cpu_features); |
| 69 // Register the file descriptors. | 69 // Register the file descriptors. |
| 70 // This includes the IPC channel, the crash dump signals and resource related | 70 // This includes the IPC channel, the crash dump signals and resource related |
| 71 // files. | 71 // files. |
| 72 DCHECK(file_fds.size() == file_ids.size()); | 72 DCHECK(file_fds.size() == file_ids.size()); |
| 73 for (size_t i = 0; i < file_ids.size(); ++i) | 73 for (size_t i = 0; i < file_ids.size(); ++i) |
| 74 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 74 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
| 75 | 75 |
| 76 content::SurfaceTexturePeer::InitInstance( | 76 content::SurfaceTexturePeer::InitInstance( |
| 77 new SurfaceTexturePeerSandboxedImpl(service)); | 77 new SurfaceTexturePeerChildImpl(service)); |
| 78 | 78 |
| 79 } | 79 } |
| 80 | 80 |
| 81 void QuitSandboxMainThreadMessageLoop() { | 81 void QuitSandboxMainThreadMessageLoop() { |
|
Yaron
2013/03/08 03:10:31
QuitMainThreadMessageLoop
kjyoun
2013/03/11 14:17:43
Done.
| |
| 82 MessageLoop::current()->Quit(); | 82 MessageLoop::current()->Quit(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace <anonymous> | 85 } // namespace <anonymous> |
| 86 | 86 |
| 87 namespace content { | 87 namespace content { |
| 88 | 88 |
| 89 void InitSandboxedProcess(JNIEnv* env, | 89 void InitChildProcess(JNIEnv* env, |
| 90 jclass clazz, | 90 jclass clazz, |
| 91 jobject context, | 91 jobject context, |
| 92 jobject service, | 92 jobject service, |
| 93 jintArray j_file_ids, | 93 jintArray j_file_ids, |
| 94 jintArray j_file_fds, | 94 jintArray j_file_fds, |
| 95 jint cpu_count, | 95 jint cpu_count, |
| 96 jlong cpu_features) { | 96 jlong cpu_features) { |
| 97 std::vector<int> file_ids; | 97 std::vector<int> file_ids; |
| 98 std::vector<int> file_fds; | 98 std::vector<int> file_fds; |
| 99 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); | 99 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); |
| 100 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); | 100 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); |
| 101 | 101 |
| 102 InternalInitSandboxedProcess( | 102 InternalInitChildProcess( |
| 103 file_ids, file_fds, env, clazz, context, service, | 103 file_ids, file_fds, env, clazz, context, service, |
| 104 cpu_count, cpu_features); | 104 cpu_count, cpu_features); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { | 107 void ExitChildProcess(JNIEnv* env, jclass clazz) { |
| 108 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; | 108 LOG(INFO) << "ChildProcessService: Exiting child process."; |
| 109 LibraryLoaderExitHook(); | 109 LibraryLoaderExitHook(); |
| 110 _exit(0); | 110 _exit(0); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool RegisterSandboxedProcessService(JNIEnv* env) { | 113 bool RegisterChildProcessService(JNIEnv* env) { |
| 114 return RegisterNativesImpl(env); | 114 return RegisterNativesImpl(env); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { | 117 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { |
|
Yaron
2013/03/08 03:10:31
ShutdownMainThread
kjyoun
2013/03/11 14:17:43
Done.
| |
| 118 ChildProcess* current_process = ChildProcess::current(); | 118 ChildProcess* current_process = ChildProcess::current(); |
| 119 if (!current_process) | 119 if (!current_process) |
| 120 return; | 120 return; |
| 121 ChildThread* main_child_thread = current_process->main_thread(); | 121 ChildThread* main_child_thread = current_process->main_thread(); |
| 122 if (main_child_thread && main_child_thread->message_loop()) | 122 if (main_child_thread && main_child_thread->message_loop()) |
| 123 main_child_thread->message_loop()->PostTask(FROM_HERE, | 123 main_child_thread->message_loop()->PostTask(FROM_HERE, |
| 124 base::Bind(&QuitSandboxMainThreadMessageLoop)); | 124 base::Bind(&QuitSandboxMainThreadMessageLoop)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace content | 127 } // namespace content |
| OLD | NEW |