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

Unified Diff: chrome/browser/child_process_launcher.cc

Issue 3443002: [Mac] Replace the existing browser-child mach ipc with a long-lived listener ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/chrome_dll_main.cc ('k') | chrome/browser/mach_broker_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/child_process_launcher.cc
===================================================================
--- chrome/browser/child_process_launcher.cc (revision 59759)
+++ chrome/browser/child_process_launcher.cc (working copy)
@@ -7,6 +7,7 @@
#include <utility> // For std::pair.
#include "base/command_line.h"
+#include "base/lock.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/thread.h"
@@ -161,21 +162,30 @@
}
#endif // defined(OS_LINUX)
- // Actually launch the app.
- bool launched;
+ bool launched = false;
#if defined(OS_MACOSX)
- task_t child_task;
- launched = base::LaunchAppAndGetTask(
- cmd_line->argv(), env, fds_to_map, false, &child_task, &handle);
- if (launched && child_task != MACH_PORT_NULL) {
- MachBroker::instance()->RegisterPid(
- handle,
- MachBroker::MachInfo().SetTask(child_task));
- }
-#else
- launched = base::LaunchApp(cmd_line->argv(), env, fds_to_map,
- /* wait= */false, &handle);
+ // It is possible for the child process to die immediately after
+ // launching. To prevent leaking MachBroker map entries in this case,
+ // lock around all of LaunchApp(). If the child dies, the death
+ // notification will be processed by the MachBroker after the call to
+ // AddPlaceholderForPid(), enabling proper cleanup.
+ { // begin scope for AutoLock
+ MachBroker* broker = MachBroker::instance();
+ AutoLock lock(broker->GetLock());
+
+ // This call to |PrepareForFork()| will start the MachBroker listener
+ // thread, if it is not already running. Therefore the browser process
+ // will be listening for Mach IPC before LaunchApp() is called.
+ broker->PrepareForFork();
#endif
+ // Actually launch the app.
+ launched = base::LaunchApp(cmd_line->argv(), env, fds_to_map,
+ /* wait= */false, &handle);
+#if defined(OS_MACOSX)
+ if (launched)
+ broker->AddPlaceholderForPid(handle);
+ } // end scope for AutoLock
+#endif
if (!launched)
handle = base::kNullProcessHandle;
}
« no previous file with comments | « chrome/app/chrome_dll_main.cc ('k') | chrome/browser/mach_broker_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698