summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-26 09:23:46 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-26 09:23:46 +0000
commitc852b7ad4d99658dddf8fe28265855bcd49fafa8 (patch)
tree4f942203918127f38ca54eccf5bba6f23ce871c1 /apps
parent9737b3637bcdcd39c3a5cdf666380113ffb3a247 (diff)
downloadchromium_src-c852b7ad4d99658dddf8fe28265855bcd49fafa8.zip
chromium_src-c852b7ad4d99658dddf8fe28265855bcd49fafa8.tar.gz
chromium_src-c852b7ad4d99658dddf8fe28265855bcd49fafa8.tar.bz2
Send Chrome's process id to the app shim.
This saves the app shim from having to look it up using Chrome's bundle id. This also allows the shim to connect to Chrome processes started by tests which are not associated with the bundle. BUG=168080 Review URL: https://chromiumcodereview.appspot.com/22903025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/app_shim/chrome_main_app_mode_mac.mm27
1 files changed, 20 insertions, 7 deletions
diff --git a/apps/app_shim/chrome_main_app_mode_mac.mm b/apps/app_shim/chrome_main_app_mode_mac.mm
index ddad52a..773bd8d 100644
--- a/apps/app_shim/chrome_main_app_mode_mac.mm
+++ b/apps/app_shim/chrome_main_app_mode_mac.mm
@@ -21,6 +21,7 @@
#include "base/mac/scoped_nsobject.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread.h"
#include "chrome/common/chrome_constants.h"
@@ -118,9 +119,12 @@ void AppShimController::Init() {
channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT,
this, g_io_thread->message_loop_proxy().get());
+ bool launched_by_chrome =
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ app_mode::kLaunchedByChromeProcessId);
channel_->Send(new AppShimHostMsg_LaunchApp(
g_info->profile_dir, g_info->app_mode_id,
- CommandLine::ForCurrentProcess()->HasSwitch(app_mode::kNoLaunchApp) ?
+ launched_by_chrome ?
apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL));
nsapp_delegate_.reset([[AppShimDelegate alloc] initWithController:this]);
@@ -432,15 +436,24 @@ int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) {
g_io_thread = io_thread;
// Find already running instances of Chrome.
- NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier];
- NSArray* existing_chrome = [NSRunningApplication
- runningApplicationsWithBundleIdentifier:chrome_bundle_id];
+ pid_t pid = -1;
+ std::string chrome_process_id = CommandLine::ForCurrentProcess()->
+ GetSwitchValueASCII(app_mode::kLaunchedByChromeProcessId);
+ if (!chrome_process_id.empty()) {
+ if (!base::StringToInt(chrome_process_id, &pid))
+ LOG(FATAL) << "Invalid PID: " << chrome_process_id;
+ } else {
+ NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier];
+ NSArray* existing_chrome = [NSRunningApplication
+ runningApplicationsWithBundleIdentifier:chrome_bundle_id];
+ if ([existing_chrome count] > 0)
+ pid = [[existing_chrome objectAtIndex:0] processIdentifier];
+ }
// Launch Chrome if it isn't already running.
ProcessSerialNumber psn;
- if ([existing_chrome count] > 0) {
- OSStatus status = GetProcessForPID(
- [[existing_chrome objectAtIndex:0] processIdentifier], &psn);
+ if (pid > -1) {
+ OSStatus status = GetProcessForPID(pid, &psn);
if (status)
return 1;