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" |
21 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" | 23 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
22 #include "gpu/ipc/common/android/surface_texture_peer.h" | 24 #include "gpu/ipc/common/android/surface_texture_peer.h" |
23 #include "gpu/ipc/common/gpu_surface_lookup.h" | 25 #include "gpu/ipc/common/gpu_surface_lookup.h" |
24 #include "ipc/ipc_descriptors.h" | 26 #include "ipc/ipc_descriptors.h" |
25 #include "jni/ChildProcessServiceImpl_jni.h" | 27 #include "jni/ChildProcessServiceImpl_jni.h" |
| 28 #include "services/service_manager/public/cpp/shared_file_util.h" |
26 #include "ui/gl/android/scoped_java_surface.h" | 29 #include "ui/gl/android/scoped_java_surface.h" |
27 | 30 |
28 using base::android::AttachCurrentThread; | 31 using base::android::AttachCurrentThread; |
29 using base::android::CheckException; | 32 using base::android::CheckException; |
30 using base::android::JavaIntArrayToIntVector; | 33 using base::android::JavaIntArrayToIntVector; |
31 using base::android::JavaParamRef; | 34 using base::android::JavaParamRef; |
32 | 35 |
33 namespace content { | 36 namespace content { |
34 | 37 |
35 namespace { | 38 namespace { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 gpu::GpuSurfaceLookup::InitInstance( | 132 gpu::GpuSurfaceLookup::InitInstance( |
130 g_child_process_surface_manager.Pointer()); | 133 g_child_process_surface_manager.Pointer()); |
131 gpu::ScopedSurfaceRequestConduit::SetInstance( | 134 gpu::ScopedSurfaceRequestConduit::SetInstance( |
132 g_child_process_surface_manager.Pointer()); | 135 g_child_process_surface_manager.Pointer()); |
133 | 136 |
134 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 137 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
135 } | 138 } |
136 | 139 |
137 } // namespace <anonymous> | 140 } // namespace <anonymous> |
138 | 141 |
| 142 jlong CreateFileDescriptorStoreRegistrationContext( |
| 143 JNIEnv* env, |
| 144 const JavaParamRef<jclass>& clazz, |
| 145 const JavaParamRef<jstring>& shared_param) { |
| 146 if (shared_param.obj() == nullptr) |
| 147 return 0L; |
| 148 |
| 149 std::string param = base::android::ConvertJavaStringToUTF8(env, shared_param); |
| 150 std::unique_ptr<std::map<int, std::string>> values = |
| 151 base::MakeUnique<std::map<int, std::string>>(); |
| 152 if (!service_manager::ParseSharedFileSwitchValue(param, values.get())) |
| 153 return 0L; |
| 154 return reinterpret_cast<jlong>(values.release()); |
| 155 } |
| 156 |
| 157 void ReleaseFileDescriptorStoreRegistrationContext( |
| 158 JNIEnv* env, |
| 159 const JavaParamRef<jclass>& clazz, |
| 160 jlong context) { |
| 161 delete reinterpret_cast<std::map<int, std::string>*>(context); |
| 162 } |
| 163 |
| 164 jboolean RegisterInFileDescriptorStore(JNIEnv* env, |
| 165 const JavaParamRef<jclass>& clazz, |
| 166 jlong store_context, |
| 167 jint id, |
| 168 jint fd, |
| 169 jlong offset, |
| 170 jlong size) { |
| 171 if (!store_context) |
| 172 return false; |
| 173 |
| 174 std::map<int, std::string>* id_to_keys = |
| 175 reinterpret_cast<std::map<int, std::string>*>(store_context); |
| 176 const auto& iter = id_to_keys->find(id); |
| 177 if (iter == id_to_keys->end()) |
| 178 return false; |
| 179 |
| 180 base::MemoryMappedFile::Region region = {offset, size}; |
| 181 base::FileDescriptorStore::GetInstance()->Set(iter->second, fd, region); |
| 182 return true; |
| 183 } |
| 184 |
139 void RegisterGlobalFileDescriptor(JNIEnv* env, | 185 void RegisterGlobalFileDescriptor(JNIEnv* env, |
140 const JavaParamRef<jclass>& clazz, | 186 const JavaParamRef<jclass>& clazz, |
141 jint id, | 187 jint id, |
142 jint fd, | 188 jint fd, |
143 jlong offset, | 189 jlong offset, |
144 jlong size) { | 190 jlong size) { |
145 base::MemoryMappedFile::Region region = {offset, size}; | 191 base::MemoryMappedFile::Region region = {offset, size}; |
146 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); | 192 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); |
147 } | 193 } |
148 | 194 |
(...skipping 13 matching lines...) Expand all Loading... |
162 | 208 |
163 bool RegisterChildProcessServiceImpl(JNIEnv* env) { | 209 bool RegisterChildProcessServiceImpl(JNIEnv* env) { |
164 return RegisterNativesImpl(env); | 210 return RegisterNativesImpl(env); |
165 } | 211 } |
166 | 212 |
167 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 213 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
168 ChildThreadImpl::ShutdownThread(); | 214 ChildThreadImpl::ShutdownThread(); |
169 } | 215 } |
170 | 216 |
171 } // namespace content | 217 } // namespace content |
OLD | NEW |