Chromium Code Reviews| Index: content/app/android/child_process_service_impl.cc |
| diff --git a/content/app/android/child_process_service_impl.cc b/content/app/android/child_process_service_impl.cc |
| index ef6f171beee881cd9fc576659735e426230ad00b..18607cda24e592af7de8d796160fc9888e770eb8 100644 |
| --- a/content/app/android/child_process_service_impl.cc |
| +++ b/content/app/android/child_process_service_impl.cc |
| @@ -8,9 +8,11 @@ |
| #include <cpu-features.h> |
| #include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| #include "base/android/library_loader/library_loader_hooks.h" |
| #include "base/android/memory_pressure_listener_android.h" |
| #include "base/android/unguessable_token_android.h" |
| +#include "base/file_descriptor_store.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| @@ -18,10 +20,12 @@ |
| #include "base/unguessable_token.h" |
| #include "content/child/child_thread_impl.h" |
| #include "content/public/common/content_descriptors.h" |
| +#include "content/public/common/content_switches.h" |
| #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
| #include "gpu/ipc/common/gpu_surface_lookup.h" |
| #include "ipc/ipc_descriptors.h" |
| #include "jni/ChildProcessServiceImpl_jni.h" |
| +#include "services/service_manager/public/cpp/shared_file_util.h" |
| #include "ui/gl/android/scoped_java_surface.h" |
| #include "ui/gl/android/surface_texture.h" |
| @@ -121,14 +125,66 @@ void InternalInitChildProcessImpl(JNIEnv* env, |
| } // namespace <anonymous> |
| -void RegisterGlobalFileDescriptor(JNIEnv* env, |
| - const JavaParamRef<jclass>& clazz, |
| - jint id, |
| - jint fd, |
| - jlong offset, |
| - jlong size) { |
| - base::MemoryMappedFile::Region region = {offset, size}; |
| - base::GlobalDescriptors::GetInstance()->Set(id, fd, region); |
| +jlong CreateFileDescriptorStoreRegistrationContext( |
|
boliu
2017/02/10 21:33:03
delete this
Jay Civelli
2017/02/13 18:48:25
Oh, yeah.
|
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + const JavaParamRef<jstring>& shared_param) { |
| + if (shared_param.is_null()) |
| + return 0L; |
| + |
| + std::string param = base::android::ConvertJavaStringToUTF8(env, shared_param); |
| + auto values = base::MakeUnique<std::map<int, std::string>>(); |
| + if (!service_manager::ParseSharedFileSwitchValue(param, values.get())) |
| + return 0L; |
| + return reinterpret_cast<jlong>(values.release()); |
| +} |
| + |
| +void ReleaseFileDescriptorStoreRegistrationContext( |
|
boliu
2017/02/10 21:33:03
and this
Jay Civelli
2017/02/13 18:48:25
Oh yeah (continued).
|
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + jlong context) { |
| + delete reinterpret_cast<std::map<int, std::string>*>(context); |
| +} |
| + |
| +void RegisterFileDescriptors(JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + const JavaParamRef<jintArray>& j_ids, |
| + const JavaParamRef<jintArray>& j_fds, |
| + const JavaParamRef<jlongArray>& j_offsets, |
| + const JavaParamRef<jlongArray>& j_sizes) { |
| + std::vector<int> ids; |
| + base::android::JavaIntArrayToIntVector(env, j_ids, &ids); |
| + std::vector<int> fds; |
| + base::android::JavaIntArrayToIntVector(env, j_fds, &fds); |
| + std::vector<int64_t> offsets; |
| + base::android::JavaLongArrayToInt64Vector(env, j_offsets, &offsets); |
| + std::vector<int64_t> sizes; |
| + base::android::JavaLongArrayToInt64Vector(env, j_sizes, &sizes); |
| + |
| + DCHECK(ids.size() == fds.size() && fds.size() == offsets.size() && |
|
boliu
2017/02/10 21:33:03
nit: separate DCHECKs, and use DCHECK_EQ
Jay Civelli
2017/02/13 18:48:25
Sure.
|
| + offsets.size() == sizes.size()); |
| + |
| + std::map<int, std::string> ids_to_keys; |
| + std::string file_switch_value = |
| + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| + switches::kSharedFiles); |
| + if (!file_switch_value.empty()) { |
| + service_manager::ParseSharedFileSwitchValue(file_switch_value, |
| + &ids_to_keys); |
| + } |
| + |
| + for (size_t i = 0; i < ids.size(); i++) { |
| + base::MemoryMappedFile::Region region = {offsets.at(i), sizes.at(i)}; |
| + int id = ids.at(i); |
| + int fd = fds.at(i); |
| + auto iter = ids_to_keys.find(id); |
| + if (iter != ids_to_keys.end()) { |
| + base::FileDescriptorStore::GetInstance().Set(iter->second, |
| + base::ScopedFD(fd), region); |
| + } else { |
| + base::GlobalDescriptors::GetInstance()->Set(id, fd, region); |
| + } |
| + } |
| } |
| void InitChildProcessImpl(JNIEnv* env, |