diff options
Diffstat (limited to 'chrome/browser/mac/dock.mm')
-rw-r--r-- | chrome/browser/mac/dock.mm | 67 |
1 files changed, 4 insertions, 63 deletions
diff --git a/chrome/browser/mac/dock.mm b/chrome/browser/mac/dock.mm index 1256b17b..1dce41ee 100644 --- a/chrome/browser/mac/dock.mm +++ b/chrome/browser/mac/dock.mm @@ -120,71 +120,12 @@ NSMutableArray* PersistentAppPaths(NSArray* persistent_apps) { return app_paths; } -// Returns the process ID for a process whose bundle identifier is bundle_id. -// The process is looked up using the Process Manager. Returns -1 on error, -// including when no process matches the bundle identifier. -pid_t PIDForProcessBundleID(const std::string& bundle_id) { - // This technique is racy: what happens if |psn| becomes invalid before a - // subsequent call to GetNextProcess, or if the Process Manager's internal - // order of processes changes? Tolerate the race by allowing failure. Since - // this function is only used on Leopard to find the Dock process so that it - // can be restarted, the worst that can happen here is that the Dock won't - // be restarted. - ProcessSerialNumber psn = {0, kNoProcess}; - OSStatus status; - while ((status = GetNextProcess(&psn)) == noErr) { - pid_t process_pid; - if ((status = GetProcessPID(&psn, &process_pid)) != noErr) { - OSSTATUS_LOG(ERROR, status) << "GetProcessPID"; - continue; - } - - base::mac::ScopedCFTypeRef<CFDictionaryRef> process_dictionary( - ProcessInformationCopyDictionary(&psn, - kProcessDictionaryIncludeAllInformationMask)); - if (!process_dictionary.get()) { - LOG(ERROR) << "ProcessInformationCopyDictionary"; - continue; - } - - CFStringRef process_bundle_id_cf = base::mac::CFCast<CFStringRef>( - CFDictionaryGetValue(process_dictionary, kCFBundleIdentifierKey)); - if (!process_bundle_id_cf) { - // Not all processes have a bundle ID. - continue; - } - - std::string process_bundle_id = - base::SysCFStringRefToUTF8(process_bundle_id_cf); - if (process_bundle_id == bundle_id) { - // Found it! - return process_pid; - } - } - - // status will be procNotFound (-600) if the process wasn't found. - OSSTATUS_LOG(ERROR, status) << "GetNextProcess"; - - return -1; -} - // Restart the Dock process by sending it a SIGHUP. void Restart() { - pid_t pid; - - if (base::mac::IsOSSnowLeopardOrLater()) { - // Doing this via launchd using the proper job label is the safest way to - // handle the restart. Unlike "killall Dock", looking this up via launchd - // guarantees that only the right process will be targeted. - pid = base::mac::PIDForJob("com.apple.Dock.agent"); - } else { - // On Leopard, the Dock doesn't have a known fixed job label name as it - // does on Snow Leopard and Lion because it's not launched as a launch - // agent. Look the PID up by finding a process with the expected bundle - // identifier using the Process Manager. - pid = PIDForProcessBundleID("com.apple.dock"); - } - + // Doing this via launchd using the proper job label is the safest way to + // handle the restart. Unlike "killall Dock", looking this up via launchd + // guarantees that only the right process will be targeted. + pid_t pid = base::mac::PIDForJob("com.apple.Dock.agent"); if (pid <= 0) { return; } |