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