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 <cpu-features.h> |
| 8 |
7 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/posix/global_descriptors.h" | 11 #include "base/posix/global_descriptors.h" |
10 #include "content/common/android/surface_texture_peer.h" | 12 #include "content/common/android/surface_texture_peer.h" |
11 #include "content/common/child_process.h" | 13 #include "content/common/child_process.h" |
12 #include "content/common/child_thread.h" | 14 #include "content/common/child_thread.h" |
13 #include "content/public/app/android_library_loader_hooks.h" | 15 #include "content/public/app/android_library_loader_hooks.h" |
14 #include "content/public/common/content_descriptors.h" | 16 #include "content/public/common/content_descriptors.h" |
15 #include "ipc/ipc_descriptors.h" | 17 #include "ipc/ipc_descriptors.h" |
16 #include "jni/SandboxedProcessService_jni.h" | 18 #include "jni/SandboxedProcessService_jni.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); | 55 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); |
54 }; | 56 }; |
55 | 57 |
56 // Chrome actually uses the renderer code path for all of its sandboxed | 58 // Chrome actually uses the renderer code path for all of its sandboxed |
57 // processes such as renderers, plugins, etc. | 59 // processes such as renderers, plugins, etc. |
58 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, | 60 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, |
59 const std::vector<int>& file_fds, | 61 const std::vector<int>& file_fds, |
60 JNIEnv* env, | 62 JNIEnv* env, |
61 jclass clazz, | 63 jclass clazz, |
62 jobject context, | 64 jobject context, |
63 jobject service) { | 65 jobject service, |
| 66 jint cpu_count, |
| 67 jlong cpu_features) { |
| 68 // Set the CPU properties. |
| 69 android_setCpu(cpu_count, cpu_features); |
64 // Register the file descriptors. | 70 // Register the file descriptors. |
65 // This includes the IPC channel, the crash dump signals and resource related | 71 // This includes the IPC channel, the crash dump signals and resource related |
66 // files. | 72 // files. |
67 DCHECK(file_fds.size() == file_ids.size()); | 73 DCHECK(file_fds.size() == file_ids.size()); |
68 for (size_t i = 0; i < file_ids.size(); ++i) | 74 for (size_t i = 0; i < file_ids.size(); ++i) |
69 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 75 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
70 | 76 |
71 content::SurfaceTexturePeer::InitInstance( | 77 content::SurfaceTexturePeer::InitInstance( |
72 new SurfaceTexturePeerSandboxedImpl(service)); | 78 new SurfaceTexturePeerSandboxedImpl(service)); |
73 | 79 |
74 } | 80 } |
75 | 81 |
76 void QuitSandboxMainThreadMessageLoop() { | 82 void QuitSandboxMainThreadMessageLoop() { |
77 MessageLoop::current()->Quit(); | 83 MessageLoop::current()->Quit(); |
78 } | 84 } |
79 | 85 |
80 } // namespace <anonymous> | 86 } // namespace <anonymous> |
81 | 87 |
82 namespace content { | 88 namespace content { |
83 | 89 |
84 void InitSandboxedProcess(JNIEnv* env, | 90 void InitSandboxedProcess(JNIEnv* env, |
85 jclass clazz, | 91 jclass clazz, |
86 jobject context, | 92 jobject context, |
87 jobject service, | 93 jobject service, |
88 jintArray j_file_ids, | 94 jintArray j_file_ids, |
89 jintArray j_file_fds) { | 95 jintArray j_file_fds, |
| 96 jint cpu_count, |
| 97 jlong cpu_features) { |
90 std::vector<int> file_ids; | 98 std::vector<int> file_ids; |
91 std::vector<int> file_fds; | 99 std::vector<int> file_fds; |
92 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); | 100 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); |
93 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); | 101 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); |
94 | 102 |
95 InternalInitSandboxedProcess( | 103 InternalInitSandboxedProcess( |
96 file_ids, file_fds, env, clazz, context, service); | 104 file_ids, file_fds, env, clazz, context, service, |
| 105 cpu_count, cpu_features); |
97 } | 106 } |
98 | 107 |
99 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { | 108 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { |
100 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; | 109 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; |
101 LibraryLoaderExitHook(); | 110 LibraryLoaderExitHook(); |
102 _exit(0); | 111 _exit(0); |
103 } | 112 } |
104 | 113 |
105 bool RegisterSandboxedProcessService(JNIEnv* env) { | 114 bool RegisterSandboxedProcessService(JNIEnv* env) { |
106 return RegisterNativesImpl(env); | 115 return RegisterNativesImpl(env); |
107 } | 116 } |
108 | 117 |
109 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { | 118 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { |
110 ChildProcess* current_process = ChildProcess::current(); | 119 ChildProcess* current_process = ChildProcess::current(); |
111 if (!current_process) | 120 if (!current_process) |
112 return; | 121 return; |
113 ChildThread* main_child_thread = current_process->main_thread(); | 122 ChildThread* main_child_thread = current_process->main_thread(); |
114 if (main_child_thread && main_child_thread->message_loop()) | 123 if (main_child_thread && main_child_thread->message_loop()) |
115 main_child_thread->message_loop()->PostTask(FROM_HERE, | 124 main_child_thread->message_loop()->PostTask(FROM_HERE, |
116 base::Bind(&QuitSandboxMainThreadMessageLoop)); | 125 base::Bind(&QuitSandboxMainThreadMessageLoop)); |
117 } | 126 } |
118 | 127 |
119 } // namespace content | 128 } // namespace content |
OLD | NEW |