Index: apps/app_shim/chrome_main_app_mode_mac.mm |
diff --git a/apps/app_shim/chrome_main_app_mode_mac.mm b/apps/app_shim/chrome_main_app_mode_mac.mm |
index 2c13ba23c29ec3de0afd7e68c465542fb17e6ced..7e9a759b403902c26779afdf546f3025f2688f11 100644 |
--- a/apps/app_shim/chrome_main_app_mode_mac.mm |
+++ b/apps/app_shim/chrome_main_app_mode_mac.mm |
@@ -109,6 +109,11 @@ class AppShimController : public IPC::Listener { |
// Connects to Chrome and sends a LaunchApp message. |
void Init(); |
+ // Create a channel from |socket_path| and send a LaunchApp message. |
+ // This may be called multiple times at startup to try to connect to different |
+ // paths. |
+ void CreateChannelAndSendLaunchApp(const base::FilePath& socket_path); |
+ |
// Builds main menu bar items. |
void SetUpMenu(); |
@@ -140,7 +145,9 @@ class AppShimController : public IPC::Listener { |
// Terminates the app shim process. |
void Close(); |
- IPC::ChannelProxy* channel_; |
+ base::FilePath user_data_dir_; |
+ bool should_try_long_socket_path; |
+ scoped_ptr<IPC::ChannelProxy> channel_; |
base::scoped_nsobject<AppShimDelegate> delegate_; |
bool launch_app_done_; |
bool ping_chrome_reply_received_; |
@@ -149,7 +156,7 @@ class AppShimController : public IPC::Listener { |
}; |
AppShimController::AppShimController() |
- : channel_(NULL), |
+ : should_try_long_socket_path(true), |
delegate_([[AppShimDelegate alloc] init]), |
launch_app_done_(false), |
ping_chrome_reply_received_(false) { |
@@ -189,15 +196,18 @@ void AppShimController::Init() { |
// The user_data_dir for shims actually contains the app_data_path. |
// I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ |
- base::FilePath user_data_dir = |
- g_info->user_data_dir.DirName().DirName().DirName(); |
- CHECK(!user_data_dir.empty()); |
+ user_data_dir_ = g_info->user_data_dir.DirName().DirName().DirName(); |
+ CHECK(!user_data_dir_.empty()); |
+ |
+ // Connect to the short socket path first. |
+ CreateChannelAndSendLaunchApp(app_mode::GetShortSocketPath(user_data_dir_)); |
+} |
- base::FilePath socket_path = |
- user_data_dir.Append(app_mode::kAppShimSocketName); |
+void AppShimController::CreateChannelAndSendLaunchApp( |
+ const base::FilePath& socket_path) { |
IPC::ChannelHandle handle(socket_path.value()); |
- channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
- this, g_io_thread->message_loop_proxy().get()); |
+ channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
+ this, g_io_thread->message_loop_proxy().get())); |
bool launched_by_chrome = |
CommandLine::ForCurrentProcess()->HasSwitch( |
@@ -278,10 +288,22 @@ bool AppShimController::OnMessageReceived(const IPC::Message& message) { |
} |
void AppShimController::OnChannelError() { |
+ // TODO(jackhou): Remove this in M35 or later. |
+ // On failure, try to connect to the long socket path. |
palmer
2013/12/10 20:04:23
What's the "long" socket path? Is it the one in $H
jackhou1
2014/01/06 05:29:52
The new implementation decides based on whether th
|
+ if (should_try_long_socket_path) { |
+ should_try_long_socket_path = false; |
+ base::FilePath udd_plus_socket_name = |
+ user_data_dir_.Append(app_mode::kAppShimSocketName); |
+ CreateChannelAndSendLaunchApp(udd_plus_socket_name); |
+ return; |
+ } |
+ |
Close(); |
} |
void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) { |
+ should_try_long_socket_path = false; |
+ |
if (result != apps::APP_SHIM_LAUNCH_SUCCESS) { |
Close(); |
return; |