| 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/sandboxed_process_service.h" |
| 6 | 6 |
| 7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/posix/global_descriptors.h" | 9 #include "base/posix/global_descriptors.h" |
| 10 #include "content/common/android/surface_texture_peer.h" | 10 #include "content/common/android/surface_texture_peer.h" |
| 11 #include "content/common/child_process.h" |
| 12 #include "content/common/child_thread.h" |
| 11 #include "content/public/app/android_library_loader_hooks.h" | 13 #include "content/public/app/android_library_loader_hooks.h" |
| 12 #include "content/public/common/content_descriptors.h" | 14 #include "content/public/common/content_descriptors.h" |
| 13 #include "ipc/ipc_descriptors.h" | 15 #include "ipc/ipc_descriptors.h" |
| 14 #include "jni/SandboxedProcessService_jni.h" | 16 #include "jni/SandboxedProcessService_jni.h" |
| 15 | 17 |
| 16 using base::android::AttachCurrentThread; | 18 using base::android::AttachCurrentThread; |
| 17 using base::android::CheckException; | 19 using base::android::CheckException; |
| 18 using base::android::JavaIntArrayToIntVector; | 20 using base::android::JavaIntArrayToIntVector; |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // files. | 66 // files. |
| 65 DCHECK(file_fds.size() == file_ids.size()); | 67 DCHECK(file_fds.size() == file_ids.size()); |
| 66 for (size_t i = 0; i < file_ids.size(); ++i) | 68 for (size_t i = 0; i < file_ids.size(); ++i) |
| 67 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 69 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
| 68 | 70 |
| 69 content::SurfaceTexturePeer::InitInstance( | 71 content::SurfaceTexturePeer::InitInstance( |
| 70 new SurfaceTexturePeerSandboxedImpl(service)); | 72 new SurfaceTexturePeerSandboxedImpl(service)); |
| 71 | 73 |
| 72 } | 74 } |
| 73 | 75 |
| 76 void QuitSandboxMainThreadMessageLoop() { |
| 77 MessageLoop::current()->Quit(); |
| 78 } |
| 79 |
| 74 } // namespace <anonymous> | 80 } // namespace <anonymous> |
| 75 | 81 |
| 76 namespace content { | 82 namespace content { |
| 77 | 83 |
| 78 void InitSandboxedProcess(JNIEnv* env, | 84 void InitSandboxedProcess(JNIEnv* env, |
| 79 jclass clazz, | 85 jclass clazz, |
| 80 jobject context, | 86 jobject context, |
| 81 jobject service, | 87 jobject service, |
| 82 jintArray j_file_ids, | 88 jintArray j_file_ids, |
| 83 jintArray j_file_fds) { | 89 jintArray j_file_fds) { |
| 84 std::vector<int> file_ids; | 90 std::vector<int> file_ids; |
| 85 std::vector<int> file_fds; | 91 std::vector<int> file_fds; |
| 86 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); | 92 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); |
| 87 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); | 93 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); |
| 88 | 94 |
| 89 InternalInitSandboxedProcess( | 95 InternalInitSandboxedProcess( |
| 90 file_ids, file_fds, env, clazz, context, service); | 96 file_ids, file_fds, env, clazz, context, service); |
| 91 } | 97 } |
| 92 | 98 |
| 93 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { | 99 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { |
| 94 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; | 100 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; |
| 95 LibraryLoaderExitHook(); | 101 LibraryLoaderExitHook(); |
| 96 _exit(0); | 102 _exit(0); |
| 97 } | 103 } |
| 98 | 104 |
| 99 bool RegisterSandboxedProcessService(JNIEnv* env) { | 105 bool RegisterSandboxedProcessService(JNIEnv* env) { |
| 100 return RegisterNativesImpl(env); | 106 return RegisterNativesImpl(env); |
| 101 } | 107 } |
| 102 | 108 |
| 109 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { |
| 110 ChildProcess* current_process = ChildProcess::current(); |
| 111 if (!current_process) |
| 112 return; |
| 113 ChildThread* main_child_thread = current_process->main_thread(); |
| 114 if (main_child_thread && main_child_thread->message_loop()) |
| 115 main_child_thread->message_loop()->PostTask(FROM_HERE, |
| 116 base::Bind(&QuitSandboxMainThreadMessageLoop)); |
| 117 } |
| 118 |
| 103 } // namespace content | 119 } // namespace content |
| OLD | NEW |