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 SurfaceTextureTarget type, | 39 SurfaceTextureTarget type, |
40 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, | 40 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, |
41 int primary_id, | 41 int primary_id, |
42 int secondary_id) { | 42 int secondary_id) { |
43 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
44 content::Java_SandboxedProcessService_establishSurfaceTexturePeer( | 44 content::Java_ChildProcessService_establishSurfaceTexturePeer( |
45 env, service_, pid, type, | 45 env, service_, pid, type, |
46 surface_texture_bridge->j_surface_texture().obj(), primary_id, | 46 surface_texture_bridge->j_surface_texture().obj(), primary_id, |
47 secondary_id); | 47 secondary_id); |
48 CheckException(env); | 48 CheckException(env); |
49 } | 49 } |
50 | 50 |
51 private: | 51 private: |
52 // The instance of org.chromium.content.app.SandboxedProcessService. | 52 // The instance of org.chromium.content.app.ChildProcessService. |
53 jobject service_; | 53 jobject service_; |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); | 55 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); |
56 }; | 56 }; |
57 | 57 |
58 // 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 |
59 // processes such as renderers, plugins, etc. | 59 // processes such as renderers, plugins, etc. |
60 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, | 60 void InternalInitChildProcess(const std::vector<int>& file_ids, |
61 const std::vector<int>& file_fds, | 61 const std::vector<int>& file_fds, |
62 JNIEnv* env, | 62 JNIEnv* env, |
63 jclass clazz, | 63 jclass clazz, |
64 jobject context, | 64 jobject context, |
65 jobject service, | 65 jobject service, |
66 jint cpu_count, | 66 jint cpu_count, |
67 jlong cpu_features) { | 67 jlong cpu_features) { |
68 // Set the CPU properties. | 68 // Set the CPU properties. |
69 android_setCpu(cpu_count, cpu_features); | 69 android_setCpu(cpu_count, cpu_features); |
70 // Register the file descriptors. | 70 // Register the file descriptors. |
71 // 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 |
72 // files. | 72 // files. |
73 DCHECK(file_fds.size() == file_ids.size()); | 73 DCHECK(file_fds.size() == file_ids.size()); |
74 for (size_t i = 0; i < file_ids.size(); ++i) | 74 for (size_t i = 0; i < file_ids.size(); ++i) |
75 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 75 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
76 | 76 |
77 content::SurfaceTexturePeer::InitInstance( | 77 content::SurfaceTexturePeer::InitInstance( |
78 new SurfaceTexturePeerSandboxedImpl(service)); | 78 new SurfaceTexturePeerChildImpl(service)); |
79 | 79 |
80 } | 80 } |
81 | 81 |
82 void QuitSandboxMainThreadMessageLoop() { | 82 void QuitSandboxMainThreadMessageLoop() { |
83 MessageLoop::current()->Quit(); | 83 MessageLoop::current()->Quit(); |
84 } | 84 } |
85 | 85 |
86 } // namespace <anonymous> | 86 } // namespace <anonymous> |
87 | 87 |
88 namespace content { | 88 namespace content { |
89 | 89 |
90 void InitSandboxedProcess(JNIEnv* env, | 90 void InitChildProcess(JNIEnv* env, |
91 jclass clazz, | 91 jclass clazz, |
92 jobject context, | 92 jobject context, |
93 jobject service, | 93 jobject service, |
94 jintArray j_file_ids, | 94 jintArray j_file_ids, |
95 jintArray j_file_fds, | 95 jintArray j_file_fds, |
96 jint cpu_count, | 96 jint cpu_count, |
97 jlong cpu_features) { | 97 jlong cpu_features) { |
98 std::vector<int> file_ids; | 98 std::vector<int> file_ids; |
99 std::vector<int> file_fds; | 99 std::vector<int> file_fds; |
100 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); | 100 JavaIntArrayToIntVector(env, j_file_ids, &file_ids); |
101 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); | 101 JavaIntArrayToIntVector(env, j_file_fds, &file_fds); |
102 | 102 |
103 InternalInitSandboxedProcess( | 103 InternalInitChildProcess( |
104 file_ids, file_fds, env, clazz, context, service, | 104 file_ids, file_fds, env, clazz, context, service, |
105 cpu_count, cpu_features); | 105 cpu_count, cpu_features); |
106 } | 106 } |
107 | 107 |
108 void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { | 108 void ExitChildProcess(JNIEnv* env, jclass clazz) { |
109 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; | 109 LOG(INFO) << "ChildProcessService: Exiting child process."; |
110 LibraryLoaderExitHook(); | 110 LibraryLoaderExitHook(); |
111 _exit(0); | 111 _exit(0); |
112 } | 112 } |
113 | 113 |
114 bool RegisterSandboxedProcessService(JNIEnv* env) { | 114 bool RegisterChildProcessService(JNIEnv* env) { |
115 return RegisterNativesImpl(env); | 115 return RegisterNativesImpl(env); |
116 } | 116 } |
117 | 117 |
118 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { | 118 void ShutdownSandboxMainThread(JNIEnv* env, jobject obj) { |
119 ChildProcess* current_process = ChildProcess::current(); | 119 ChildProcess* current_process = ChildProcess::current(); |
120 if (!current_process) | 120 if (!current_process) |
121 return; | 121 return; |
122 ChildThread* main_child_thread = current_process->main_thread(); | 122 ChildThread* main_child_thread = current_process->main_thread(); |
123 if (main_child_thread && main_child_thread->message_loop()) | 123 if (main_child_thread && main_child_thread->message_loop()) |
124 main_child_thread->message_loop()->PostTask(FROM_HERE, | 124 main_child_thread->message_loop()->PostTask(FROM_HERE, |
125 base::Bind(&QuitSandboxMainThreadMessageLoop)); | 125 base::Bind(&QuitSandboxMainThreadMessageLoop)); |
126 } | 126 } |
127 | 127 |
128 } // namespace content | 128 } // namespace content |
OLD | NEW |