Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: content/browser/android/child_process_launcher_android.cc

Issue 909553003: Android: Get rid of extra dup()s on launching child processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/file_descriptor_info_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::android::CheckException(env); 121 base::android::CheckException(env);
122 jint* file_fds = env->GetIntArrayElements(j_file_fds.obj(), NULL); 122 jint* file_fds = env->GetIntArrayElements(j_file_fds.obj(), NULL);
123 base::android::CheckException(env); 123 base::android::CheckException(env);
124 ScopedJavaLocalRef<jbooleanArray> j_file_auto_close( 124 ScopedJavaLocalRef<jbooleanArray> j_file_auto_close(
125 env, env->NewBooleanArray(file_count)); 125 env, env->NewBooleanArray(file_count));
126 base::android::CheckException(env); 126 base::android::CheckException(env);
127 jboolean* file_auto_close = 127 jboolean* file_auto_close =
128 env->GetBooleanArrayElements(j_file_auto_close.obj(), NULL); 128 env->GetBooleanArrayElements(j_file_auto_close.obj(), NULL);
129 base::android::CheckException(env); 129 base::android::CheckException(env);
130 for (size_t i = 0; i < file_count; ++i) { 130 for (size_t i = 0; i < file_count; ++i) {
131 // Owners of passed descriptors can outlive this function and we don't know
132 // when it is safe to close() them. So we pass dup()-ed FD and
133 // let ChildProcessLauncher in java take care of their lifetimes.
134 // TODO(morrita): Drop FileDescriptorInfo.mAutoClose on Java side.
135 file_auto_close[i] = true; // This indicates ownership transfer.
136 file_ids[i] = files_to_register->GetIDAt(i); 131 file_ids[i] = files_to_register->GetIDAt(i);
137 file_fds[i] = dup(files_to_register->GetFDAt(i)); 132 file_fds[i] = files_to_register->GetFDAt(i);
138 PCHECK(0 <= file_fds[i]); 133 PCHECK(0 <= file_fds[i]);
134 file_auto_close[i] = files_to_register->OwnsFD(file_fds[i]);
mdempsky 2015/02/07 02:37:05 OwnsFD and ReleaseFD seem like clunky APIs, but un
135 if (file_auto_close[i])
136 ignore_result(files_to_register->ReleaseFD(file_fds[i]).release());
139 } 137 }
140 env->ReleaseIntArrayElements(j_file_ids.obj(), file_ids, 0); 138 env->ReleaseIntArrayElements(j_file_ids.obj(), file_ids, 0);
141 env->ReleaseIntArrayElements(j_file_fds.obj(), file_fds, 0); 139 env->ReleaseIntArrayElements(j_file_fds.obj(), file_fds, 0);
142 env->ReleaseBooleanArrayElements(j_file_auto_close.obj(), file_auto_close, 0); 140 env->ReleaseBooleanArrayElements(j_file_auto_close.obj(), file_auto_close, 0);
143 141
144 Java_ChildProcessLauncher_start(env, 142 Java_ChildProcessLauncher_start(env,
145 base::android::GetApplicationContext(), 143 base::android::GetApplicationContext(),
146 j_argv.obj(), 144 j_argv.obj(),
147 child_process_id, 145 child_process_id,
148 j_file_ids.obj(), 146 j_file_ids.obj(),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) { 226 jboolean IsSingleProcess(JNIEnv* env, jclass clazz) {
229 return base::CommandLine::ForCurrentProcess()->HasSwitch( 227 return base::CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kSingleProcess); 228 switches::kSingleProcess);
231 } 229 }
232 230
233 bool RegisterChildProcessLauncher(JNIEnv* env) { 231 bool RegisterChildProcessLauncher(JNIEnv* env) {
234 return RegisterNativesImpl(env); 232 return RegisterNativesImpl(env);
235 } 233 }
236 234
237 } // namespace content 235 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/file_descriptor_info_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698