| 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/browser/android/child_process_launcher_android.h" | 5 #include "content/browser/android/child_process_launcher_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 reinterpret_cast<StartChildProcessCallback*>(client_context); | 96 reinterpret_cast<StartChildProcessCallback*>(client_context); |
| 97 if (handle) | 97 if (handle) |
| 98 callback->Run(static_cast<base::ProcessHandle>(handle)); | 98 callback->Run(static_cast<base::ProcessHandle>(handle)); |
| 99 delete callback; | 99 delete callback; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void StartChildProcess( | 102 void StartChildProcess( |
| 103 const base::CommandLine::StringVector& argv, | 103 const base::CommandLine::StringVector& argv, |
| 104 int child_process_id, | 104 int child_process_id, |
| 105 scoped_ptr<content::FileDescriptorInfo> files_to_register, | 105 scoped_ptr<content::FileDescriptorInfo> files_to_register, |
| 106 const std::map<int, base::MemoryMappedFile::Region>& regions, |
| 106 const StartChildProcessCallback& callback) { | 107 const StartChildProcessCallback& callback) { |
| 107 JNIEnv* env = AttachCurrentThread(); | 108 JNIEnv* env = AttachCurrentThread(); |
| 108 DCHECK(env); | 109 DCHECK(env); |
| 109 | 110 |
| 110 // Create the Command line String[] | 111 // Create the Command line String[] |
| 111 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); | 112 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); |
| 112 | 113 |
| 113 size_t file_count = files_to_register->GetMappingSize(); | 114 size_t file_count = files_to_register->GetMappingSize(); |
| 114 DCHECK(file_count > 0); | 115 DCHECK(file_count > 0); |
| 115 | 116 |
| 116 ScopedJavaLocalRef<jintArray> j_file_ids(env, env->NewIntArray(file_count)); | 117 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass( |
| 118 env, "org/chromium/content/browser/FileDescriptorInfo"); |
| 119 ScopedJavaLocalRef<jobjectArray> j_file_infos( |
| 120 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL)); |
| 117 base::android::CheckException(env); | 121 base::android::CheckException(env); |
| 118 jint* file_ids = env->GetIntArrayElements(j_file_ids.obj(), NULL); | 122 |
| 119 base::android::CheckException(env); | |
| 120 ScopedJavaLocalRef<jintArray> j_file_fds(env, env->NewIntArray(file_count)); | |
| 121 base::android::CheckException(env); | |
| 122 jint* file_fds = env->GetIntArrayElements(j_file_fds.obj(), NULL); | |
| 123 base::android::CheckException(env); | |
| 124 ScopedJavaLocalRef<jbooleanArray> j_file_auto_close( | |
| 125 env, env->NewBooleanArray(file_count)); | |
| 126 base::android::CheckException(env); | |
| 127 jboolean* file_auto_close = | |
| 128 env->GetBooleanArrayElements(j_file_auto_close.obj(), NULL); | |
| 129 base::android::CheckException(env); | |
| 130 for (size_t i = 0; i < file_count; ++i) { | 123 for (size_t i = 0; i < file_count; ++i) { |
| 131 file_ids[i] = files_to_register->GetIDAt(i); | 124 int fd = files_to_register->GetFDAt(i); |
| 132 file_fds[i] = files_to_register->GetFDAt(i); | 125 PCHECK(0 <= fd); |
| 133 PCHECK(0 <= file_fds[i]); | 126 int id = files_to_register->GetIDAt(i); |
| 134 file_auto_close[i] = files_to_register->OwnsFD(file_fds[i]); | 127 bool autoClose = files_to_register->OwnsFD(fd); |
| 135 if (file_auto_close[i]) | 128 int64 offset = 0L; |
| 136 ignore_result(files_to_register->ReleaseFD(file_fds[i]).release()); | 129 int64 size = 0L; |
| 130 auto found_region_iter = regions.find(id); |
| 131 if (found_region_iter != regions.end()) { |
| 132 offset = found_region_iter->second.offset; |
| 133 size = found_region_iter->second.size; |
| 134 } |
| 135 ScopedJavaLocalRef<jobject> j_file_info = |
| 136 Java_ChildProcessLauncher_makeFdInfo(env, id, fd, autoClose, offset, |
| 137 size); |
| 138 PCHECK(j_file_info.obj()); |
| 139 env->SetObjectArrayElement(j_file_infos.obj(), i, j_file_info.obj()); |
| 140 if (autoClose) { |
| 141 ignore_result(files_to_register->ReleaseFD(fd).release()); |
| 142 } |
| 137 } | 143 } |
| 138 env->ReleaseIntArrayElements(j_file_ids.obj(), file_ids, 0); | |
| 139 env->ReleaseIntArrayElements(j_file_fds.obj(), file_fds, 0); | |
| 140 env->ReleaseBooleanArrayElements(j_file_auto_close.obj(), file_auto_close, 0); | |
| 141 | 144 |
| 142 Java_ChildProcessLauncher_start(env, | 145 Java_ChildProcessLauncher_start( |
| 143 base::android::GetApplicationContext(), | 146 env, base::android::GetApplicationContext(), j_argv.obj(), |
| 144 j_argv.obj(), | 147 child_process_id, j_file_infos.obj(), |
| 145 child_process_id, | |
| 146 j_file_ids.obj(), | |
| 147 j_file_fds.obj(), | |
| 148 j_file_auto_close.obj(), | |
| 149 reinterpret_cast<intptr_t>(new StartChildProcessCallback(callback))); | 148 reinterpret_cast<intptr_t>(new StartChildProcessCallback(callback))); |
| 150 } | 149 } |
| 151 | 150 |
| 152 void StopChildProcess(base::ProcessHandle handle) { | 151 void StopChildProcess(base::ProcessHandle handle) { |
| 153 JNIEnv* env = AttachCurrentThread(); | 152 JNIEnv* env = AttachCurrentThread(); |
| 154 DCHECK(env); | 153 DCHECK(env); |
| 155 Java_ChildProcessLauncher_stop(env, static_cast<jint>(handle)); | 154 Java_ChildProcessLauncher_stop(env, static_cast<jint>(handle)); |
| 156 } | 155 } |
| 157 | 156 |
| 158 bool IsChildProcessOomProtected(base::ProcessHandle handle) { | 157 bool IsChildProcessOomProtected(base::ProcessHandle handle) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { | 225 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { |
| 227 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 226 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 228 switches::kSingleProcess); | 227 switches::kSingleProcess); |
| 229 } | 228 } |
| 230 | 229 |
| 231 bool RegisterChildProcessLauncher(JNIEnv* env) { | 230 bool RegisterChildProcessLauncher(JNIEnv* env) { |
| 232 return RegisterNativesImpl(env); | 231 return RegisterNativesImpl(env); |
| 233 } | 232 } |
| 234 | 233 |
| 235 } // namespace content | 234 } // namespace content |
| OLD | NEW |