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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java

Issue 10949027: Close leaking FDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments. Created 8 years, 3 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 | Annotate | Revision Log
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 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.RemoteException; 8 import android.os.RemoteException;
9 import android.util.Log; 9 import android.util.Log;
10 import android.view.Surface; 10 import android.view.Surface;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 154 }
155 155
156 /** 156 /**
157 * Spawns and connects to a sandboxed process. May be called on any thread. It will not 157 * Spawns and connects to a sandboxed process. May be called on any thread. It will not
158 * block, but will instead callback to {@link #nativeOnSandboxedProcessStart ed} when the 158 * block, but will instead callback to {@link #nativeOnSandboxedProcessStart ed} when the
159 * connection is established. Note this callback will not necessarily be fro m the same thread 159 * connection is established. Note this callback will not necessarily be fro m the same thread
160 * (currently it always comes from the main thread). 160 * (currently it always comes from the main thread).
161 * 161 *
162 * @param context Context used to obtain the application context. 162 * @param context Context used to obtain the application context.
163 * @param commandLine The sandboxed process command line argv. 163 * @param commandLine The sandboxed process command line argv.
164 * @param ipcFd File descriptor used to set up IPC. 164 * @param file_ids The ID that should be used when mapping files in the crea ted process.
165 * @param file_fds The file descriptors that should be mapped in the created process.
166 * @param file_autoclose Whether the file descriptors should be closed once they were passed to
167 * the created process.
165 * @param clientContext Arbitrary parameter used by the client to distinguis h this connection. 168 * @param clientContext Arbitrary parameter used by the client to distinguis h this connection.
166 */ 169 */
167 @CalledByNative 170 @CalledByNative
168 static void start( 171 static void start(
169 Context context, 172 Context context,
170 final String[] commandLine, 173 final String[] commandLine,
171 int ipcFd, 174 int[] file_ids,
172 int[] fileToRegisterIdFds, 175 int[] file_fds,
176 boolean[] file_autoclose,
173 final int clientContext) { 177 final int clientContext) {
178 assert file_ids.length == file_fds.length && file_fds.length == file_aut oclose.length;
179 FileDescriptorInfo[] filesToBeMapped = new FileDescriptorInfo[file_fds.l ength];
180 for (int i = 0; i < file_fds.length; i++) {
181 filesToBeMapped[i] =
182 new FileDescriptorInfo(file_ids[i], file_fds[i], file_autocl ose[i]);
183 }
174 assert clientContext != 0; 184 assert clientContext != 0;
175 SandboxedProcessConnection allocatedConnection; 185 SandboxedProcessConnection allocatedConnection;
176 synchronized (SandboxedProcessLauncher.class) { 186 synchronized (SandboxedProcessLauncher.class) {
177 allocatedConnection = mSpareConnection; 187 allocatedConnection = mSpareConnection;
178 mSpareConnection = null; 188 mSpareConnection = null;
179 } 189 }
180 if (allocatedConnection == null) { 190 if (allocatedConnection == null) {
181 allocatedConnection = allocateBoundConnection(context, commandLine); 191 allocatedConnection = allocateBoundConnection(context, commandLine);
182 if (allocatedConnection == null) { 192 if (allocatedConnection == null) {
183 // Notify the native code so it can free the heap allocated call back. 193 // Notify the native code so it can free the heap allocated call back.
(...skipping 10 matching lines...) Expand all
194 final int pid = connection.getPid(); 204 final int pid = connection.getPid();
195 Log.d(TAG, "on connect callback, pid=" + pid + " context=" + cli entContext); 205 Log.d(TAG, "on connect callback, pid=" + pid + " context=" + cli entContext);
196 if (pid != NULL_PROCESS_HANDLE) { 206 if (pid != NULL_PROCESS_HANDLE) {
197 mServiceMap.put(pid, connection); 207 mServiceMap.put(pid, connection);
198 } else { 208 } else {
199 freeConnection(connection); 209 freeConnection(connection);
200 } 210 }
201 nativeOnSandboxedProcessStarted(clientContext, pid); 211 nativeOnSandboxedProcessStarted(clientContext, pid);
202 } 212 }
203 }; 213 };
204 connection.setupConnection(commandLine, ipcFd, fileToRegisterIdFds, crea teCallback(), 214 connection.setupConnection(commandLine, filesToBeMapped, createCallback( ), onConnect);
205 onConnect);
206 } 215 }
207 216
208 /** 217 /**
209 * Terminates a sandboxed process. This may be called from any thread. 218 * Terminates a sandboxed process. This may be called from any thread.
210 * 219 *
211 * @param pid The pid (process handle) of the service connection obtained fr om {@link #start}. 220 * @param pid The pid (process handle) of the service connection obtained fr om {@link #start}.
212 */ 221 */
213 @CalledByNative 222 @CalledByNative
214 static void stop(int pid) { 223 static void stop(int pid) {
215 Log.d(TAG, "stopping sandboxed connection: pid=" + pid); 224 Log.d(TAG, "stopping sandboxed connection: pid=" + pid);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // avoid waiting for the finalizer to get around to it. 301 // avoid waiting for the finalizer to get around to it.
293 if (surface != null) { 302 if (surface != null) {
294 surface.release(); 303 surface.release();
295 } 304 }
296 } 305 }
297 }; 306 };
298 }; 307 };
299 308
300 private static native void nativeOnSandboxedProcessStarted(int clientContext , int pid); 309 private static native void nativeOnSandboxedProcessStarted(int clientContext , int pid);
301 } 310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698