Chromium Code Reviews| 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..f72f7b559257f3bcbd3e58e5df0457592c7edd40 100644 |
| --- a/apps/app_shim/chrome_main_app_mode_mac.mm |
| +++ b/apps/app_shim/chrome_main_app_mode_mac.mm |
| @@ -14,6 +14,7 @@ |
| #include "base/at_exit.h" |
| #include "base/command_line.h" |
| #include "base/files/file_path.h" |
| +#include "base/file_util.h" |
| #include "base/logging.h" |
| #include "base/mac/bundle_locations.h" |
| #include "base/mac/foundation_util.h" |
| @@ -109,6 +110,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 +146,8 @@ class AppShimController : public IPC::Listener { |
| // Terminates the app shim process. |
| void Close(); |
| - IPC::ChannelProxy* channel_; |
| + base::FilePath user_data_dir_; |
| + scoped_ptr<IPC::ChannelProxy> channel_; |
| base::scoped_nsobject<AppShimDelegate> delegate_; |
| bool launch_app_done_; |
| bool ping_chrome_reply_received_; |
| @@ -149,8 +156,7 @@ class AppShimController : public IPC::Listener { |
| }; |
| AppShimController::AppShimController() |
| - : channel_(NULL), |
| - delegate_([[AppShimDelegate alloc] init]), |
| + : delegate_([[AppShimDelegate alloc] init]), |
| launch_app_done_(false), |
| ping_chrome_reply_received_(false) { |
| // Since AppShimController is created before the main message loop starts, |
| @@ -189,15 +195,28 @@ 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()); |
| + |
| + base::FilePath symlink_path = |
| + user_data_dir_.Append(app_mode::kAppShimSocketName); |
| + |
| + base::FilePath socket_path; |
| + if (!base::ReadSymbolicLink(symlink_path, &socket_path)) { |
| + CreateChannelAndSendLaunchApp(symlink_path); |
|
tapted
2014/01/03 13:06:54
nit: maybe a comment here: ~"if the path in the us
jackhou1
2014/01/06 05:29:52
Done.
|
| + return; |
| + } |
| + |
| + app_mode::VerifySocketPermissions(socket_path); |
| + |
| + CreateChannelAndSendLaunchApp(socket_path); |
| +} |
| - 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( |