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/child_process_service_impl.h" | 5 #include "content/app/android/child_process_service_impl.h" |
6 | 6 |
7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
8 #include <cpu-features.h> | 8 #include <cpu-features.h> |
9 | 9 |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" |
11 #include "base/android/library_loader/library_loader_hooks.h" | 12 #include "base/android/library_loader/library_loader_hooks.h" |
12 #include "base/android/memory_pressure_listener_android.h" | 13 #include "base/android/memory_pressure_listener_android.h" |
13 #include "base/android/unguessable_token_android.h" | 14 #include "base/android/unguessable_token_android.h" |
| 15 #include "base/file_descriptor_store.h" |
14 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 17 #include "base/logging.h" |
16 #include "base/macros.h" | 18 #include "base/macros.h" |
17 #include "base/posix/global_descriptors.h" | 19 #include "base/posix/global_descriptors.h" |
18 #include "base/unguessable_token.h" | 20 #include "base/unguessable_token.h" |
19 #include "content/child/child_thread_impl.h" | 21 #include "content/child/child_thread_impl.h" |
20 #include "content/public/common/content_descriptors.h" | 22 #include "content/public/common/content_descriptors.h" |
| 23 #include "content/public/common/content_switches.h" |
21 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" | 24 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
22 #include "gpu/ipc/common/gpu_surface_lookup.h" | 25 #include "gpu/ipc/common/gpu_surface_lookup.h" |
23 #include "ipc/ipc_descriptors.h" | 26 #include "ipc/ipc_descriptors.h" |
24 #include "jni/ChildProcessServiceImpl_jni.h" | 27 #include "jni/ChildProcessServiceImpl_jni.h" |
| 28 #include "services/service_manager/public/cpp/shared_file_util.h" |
25 #include "ui/gl/android/scoped_java_surface.h" | 29 #include "ui/gl/android/scoped_java_surface.h" |
26 #include "ui/gl/android/surface_texture.h" | 30 #include "ui/gl/android/surface_texture.h" |
27 | 31 |
28 using base::android::AttachCurrentThread; | 32 using base::android::AttachCurrentThread; |
29 using base::android::CheckException; | 33 using base::android::CheckException; |
30 using base::android::JavaIntArrayToIntVector; | 34 using base::android::JavaIntArrayToIntVector; |
31 using base::android::JavaParamRef; | 35 using base::android::JavaParamRef; |
32 | 36 |
33 namespace content { | 37 namespace content { |
34 | 38 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 gpu::GpuSurfaceLookup::InitInstance( | 118 gpu::GpuSurfaceLookup::InitInstance( |
115 g_child_process_surface_manager.Pointer()); | 119 g_child_process_surface_manager.Pointer()); |
116 gpu::ScopedSurfaceRequestConduit::SetInstance( | 120 gpu::ScopedSurfaceRequestConduit::SetInstance( |
117 g_child_process_surface_manager.Pointer()); | 121 g_child_process_surface_manager.Pointer()); |
118 | 122 |
119 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 123 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
120 } | 124 } |
121 | 125 |
122 } // namespace <anonymous> | 126 } // namespace <anonymous> |
123 | 127 |
124 void RegisterGlobalFileDescriptor(JNIEnv* env, | 128 void RegisterFileDescriptors(JNIEnv* env, |
125 const JavaParamRef<jclass>& clazz, | 129 const JavaParamRef<jclass>& clazz, |
126 jint id, | 130 const JavaParamRef<jintArray>& j_ids, |
127 jint fd, | 131 const JavaParamRef<jintArray>& j_fds, |
128 jlong offset, | 132 const JavaParamRef<jlongArray>& j_offsets, |
129 jlong size) { | 133 const JavaParamRef<jlongArray>& j_sizes) { |
130 base::MemoryMappedFile::Region region = {offset, size}; | 134 std::vector<int> ids; |
131 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); | 135 base::android::JavaIntArrayToIntVector(env, j_ids, &ids); |
| 136 std::vector<int> fds; |
| 137 base::android::JavaIntArrayToIntVector(env, j_fds, &fds); |
| 138 std::vector<int64_t> offsets; |
| 139 base::android::JavaLongArrayToInt64Vector(env, j_offsets, &offsets); |
| 140 std::vector<int64_t> sizes; |
| 141 base::android::JavaLongArrayToInt64Vector(env, j_sizes, &sizes); |
| 142 |
| 143 DCHECK_EQ(ids.size(), fds.size()); |
| 144 DCHECK_EQ(fds.size(), offsets.size()); |
| 145 DCHECK_EQ(offsets.size(), sizes.size()); |
| 146 |
| 147 std::map<int, std::string> ids_to_keys; |
| 148 std::string file_switch_value = |
| 149 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 150 switches::kSharedFiles); |
| 151 if (!file_switch_value.empty()) { |
| 152 service_manager::ParseSharedFileSwitchValue(file_switch_value, |
| 153 &ids_to_keys); |
| 154 } |
| 155 |
| 156 for (size_t i = 0; i < ids.size(); i++) { |
| 157 base::MemoryMappedFile::Region region = {offsets.at(i), sizes.at(i)}; |
| 158 int id = ids.at(i); |
| 159 int fd = fds.at(i); |
| 160 auto iter = ids_to_keys.find(id); |
| 161 if (iter != ids_to_keys.end()) { |
| 162 base::FileDescriptorStore::GetInstance().Set(iter->second, |
| 163 base::ScopedFD(fd), region); |
| 164 } else { |
| 165 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); |
| 166 } |
| 167 } |
132 } | 168 } |
133 | 169 |
134 void InitChildProcessImpl(JNIEnv* env, | 170 void InitChildProcessImpl(JNIEnv* env, |
135 const JavaParamRef<jclass>& clazz, | 171 const JavaParamRef<jclass>& clazz, |
136 const JavaParamRef<jobject>& service_impl, | 172 const JavaParamRef<jobject>& service_impl, |
137 jint cpu_count, | 173 jint cpu_count, |
138 jlong cpu_features) { | 174 jlong cpu_features) { |
139 InternalInitChildProcessImpl(env, service_impl, cpu_count, cpu_features); | 175 InternalInitChildProcessImpl(env, service_impl, cpu_count, cpu_features); |
140 } | 176 } |
141 | 177 |
142 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 178 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
143 VLOG(0) << "ChildProcessServiceImpl: Exiting child process."; | 179 VLOG(0) << "ChildProcessServiceImpl: Exiting child process."; |
144 base::android::LibraryLoaderExitHook(); | 180 base::android::LibraryLoaderExitHook(); |
145 _exit(0); | 181 _exit(0); |
146 } | 182 } |
147 | 183 |
148 bool RegisterChildProcessServiceImpl(JNIEnv* env) { | 184 bool RegisterChildProcessServiceImpl(JNIEnv* env) { |
149 return RegisterNativesImpl(env); | 185 return RegisterNativesImpl(env); |
150 } | 186 } |
151 | 187 |
152 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 188 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
153 ChildThreadImpl::ShutdownThread(); | 189 ChildThreadImpl::ShutdownThread(); |
154 } | 190 } |
155 | 191 |
156 } // namespace content | 192 } // namespace content |
OLD | NEW |