Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we | 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we |
| 6 // produce small app bundles which locate the Chromium framework and load it, | 6 // produce small app bundles which locate the Chromium framework and load it, |
| 7 // passing the appropriate data. This is the entry point into the framework for | 7 // passing the appropriate data. This is the entry point into the framework for |
| 8 // those app bundles. | 8 // those app bundles. |
| 9 | 9 |
| 10 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
| 11 | 11 |
| 12 #include "apps/app_shim/app_shim_messages.h" | 12 #include "apps/app_shim/app_shim_messages.h" |
| 13 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/mac/launch_services_util.h" | 16 #include "base/mac/launch_services_util.h" |
| 17 #include "base/mac/mac_logging.h" | 17 #include "base/mac/mac_logging.h" |
| 18 #include "base/mac/mac_util.h" | 18 #include "base/mac/mac_util.h" |
| 19 #include "base/mac/scoped_nsautorelease_pool.h" | 19 #include "base/mac/scoped_nsautorelease_pool.h" |
| 20 #include "base/mac/scoped_nsobject.h" | 20 #include "base/mac/scoped_nsobject.h" |
| 21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/strings/sys_string_conversions.h" | 23 #include "base/strings/sys_string_conversions.h" |
| 24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_paths_internal.h" | |
| 27 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/mac/app_mode_common.h" | 27 #include "chrome/common/mac/app_mode_common.h" |
| 29 #include "ipc/ipc_channel_proxy.h" | 28 #include "ipc/ipc_channel_proxy.h" |
| 30 #include "ipc/ipc_listener.h" | 29 #include "ipc/ipc_listener.h" |
| 31 #include "ipc/ipc_message.h" | 30 #include "ipc/ipc_message.h" |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 const app_mode::ChromeAppModeInfo* g_info; | 34 const app_mode::ChromeAppModeInfo* g_info; |
| 36 base::Thread* g_io_thread = NULL; | 35 base::Thread* g_io_thread = NULL; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 bool launch_app_done_; | 89 bool launch_app_done_; |
| 91 | 90 |
| 92 DISALLOW_COPY_AND_ASSIGN(AppShimController); | 91 DISALLOW_COPY_AND_ASSIGN(AppShimController); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 AppShimController::AppShimController() : channel_(NULL), | 94 AppShimController::AppShimController() : channel_(NULL), |
| 96 launch_app_done_(false) {} | 95 launch_app_done_(false) {} |
| 97 | 96 |
| 98 void AppShimController::Init() { | 97 void AppShimController::Init() { |
| 99 DCHECK(g_io_thread); | 98 DCHECK(g_io_thread); |
| 100 NSString* chrome_bundle_path = | 99 if (g_info->user_data_dir.empty()) { |
|
tapted
2013/07/17 08:34:21
Can a shim ever be created like this? Maybe just C
jackhou1
2013/07/30 07:34:34
Done.
| |
| 101 base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); | |
| 102 NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; | |
| 103 base::FilePath user_data_dir; | |
| 104 if (!chrome::GetUserDataDirectoryForBrowserBundle(chrome_bundle, | |
|
tapted
2013/07/17 08:34:21
I started wondering whether this approach was chos
jackhou1
2013/07/30 07:34:34
The Info.plist has Chrome's bundle id, which app_m
| |
| 105 &user_data_dir)) { | |
| 106 Close(); | 100 Close(); |
| 107 return; | 101 return; |
| 108 } | 102 } |
| 109 | 103 |
| 110 base::FilePath socket_path = | 104 base::FilePath socket_path; |
| 111 user_data_dir.Append(app_mode::kAppShimSocketName); | 105 base::FilePath maybe_profile_dir = |
|
tapted
2013/07/17 08:34:21
Perhaps a helper function, which describes the log
jackhou1
2013/07/30 07:34:34
Since we're not changing the user_data_dir field,
| |
| 106 g_info->user_data_dir.DirName().DirName().BaseName(); | |
| 107 if (maybe_profile_dir == g_info->profile_dir) | |
|
tapted
2013/07/17 08:34:21
What happens if someone's Chrome user data dir is
jackhou1
2013/07/30 07:34:34
Obsolete since we're leaving the user_data_dir unc
| |
| 108 socket_path = g_info->user_data_dir.DirName().DirName().DirName(); | |
| 109 else | |
| 110 socket_path = g_info->user_data_dir; | |
| 111 | |
| 112 socket_path = socket_path.Append(app_mode::kAppShimSocketName); | |
| 112 IPC::ChannelHandle handle(socket_path.value()); | 113 IPC::ChannelHandle handle(socket_path.value()); |
| 113 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, | 114 channel_ = new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, |
| 114 this, g_io_thread->message_loop_proxy().get()); | 115 this, g_io_thread->message_loop_proxy().get()); |
| 115 | 116 |
| 116 channel_->Send(new AppShimHostMsg_LaunchApp( | 117 channel_->Send(new AppShimHostMsg_LaunchApp( |
| 117 g_info->profile_dir, g_info->app_mode_id, | 118 g_info->profile_dir, g_info->app_mode_id, |
| 118 CommandLine::ForCurrentProcess()->HasSwitch(app_mode::kNoLaunchApp) ? | 119 CommandLine::ForCurrentProcess()->HasSwitch(app_mode::kNoLaunchApp) ? |
| 119 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL)); | 120 apps::APP_SHIM_LAUNCH_REGISTER_ONLY : apps::APP_SHIM_LAUNCH_NORMAL)); |
| 120 | 121 |
| 121 nsapp_delegate_.reset([[AppShimDelegate alloc] initWithController:this]); | 122 nsapp_delegate_.reset([[AppShimDelegate alloc] initWithController:this]); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 // fully initialized don't receive a reply until its run loop starts. Once | 399 // fully initialized don't receive a reply until its run loop starts. Once |
| 399 // the reply is received, Chrome will have opened its IPC port, guaranteed. | 400 // the reply is received, Chrome will have opened its IPC port, guaranteed. |
| 400 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; | 401 [ReplyEventHandler pingProcess:psn andCall:base::Bind(&OnPingChromeReply)]; |
| 401 | 402 |
| 402 base::MessageLoopForUI main_message_loop; | 403 base::MessageLoopForUI main_message_loop; |
| 403 main_message_loop.set_thread_name("MainThread"); | 404 main_message_loop.set_thread_name("MainThread"); |
| 404 base::PlatformThread::SetName("CrAppShimMain"); | 405 base::PlatformThread::SetName("CrAppShimMain"); |
| 405 main_message_loop.Run(); | 406 main_message_loop.Run(); |
| 406 return 0; | 407 return 0; |
| 407 } | 408 } |
| OLD | NEW |