Chromium Code Reviews| Index: chrome/app/chrome_main_app_mode_mac.mm |
| diff --git a/chrome/app/chrome_main_app_mode_mac.mm b/chrome/app/chrome_main_app_mode_mac.mm |
| index 1de3fe5899ec42689fbbc4614cc5863a9ea4f127..02fcb25195c5571708cced810dd84cf679957f9f 100644 |
| --- a/chrome/app/chrome_main_app_mode_mac.mm |
| +++ b/chrome/app/chrome_main_app_mode_mac.mm |
| @@ -17,6 +17,7 @@ |
| #include "base/mac/mac_logging.h" |
| #include "base/mac/mac_util.h" |
| #include "base/mac/scoped_nsautorelease_pool.h" |
| +#include "base/memory/scoped_nsobject.h" |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| #include "base/strings/sys_string_conversions.h" |
| @@ -36,6 +37,20 @@ base::Thread* g_io_thread = NULL; |
| } // namespace |
| +class AppShimController; |
| + |
| +@interface AppShimDelegate : NSObject { |
|
tapted
2013/05/24 08:43:51
NSObject -> NSObject<NSApplicationDelegate> to say
jackhou1
2013/05/27 01:02:47
Done.
|
| + @private |
| + AppShimController* appShimController_; |
|
tapted
2013/05/24 08:43:51
needs a comment " // Weak. Owns us."
jackhou1
2013/05/27 01:02:47
Done.
|
| + BOOL terminateNow_; |
| +} |
| + |
| +@property(assign, nonatomic) AppShimController* appShimController; |
| + |
| +- (void)terminateNow; |
| + |
| +@end |
| + |
| // The AppShimController is responsible for communication with the main Chrome |
| // process, and generally controls the lifetime of the app shim process. |
| class AppShimController : public IPC::Listener { |
| @@ -45,6 +60,9 @@ class AppShimController : public IPC::Listener { |
| // Connects to Chrome and sends a LaunchApp message. |
| void Init(); |
| + // Sends a QuitApp message to Chrome. |
| + void QuitApp(); |
| + |
| private: |
| // IPC::Listener implemetation. |
| virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| @@ -62,6 +80,7 @@ class AppShimController : public IPC::Listener { |
| void Quit(); |
| IPC::ChannelProxy* channel_; |
| + scoped_nsobject<AppShimDelegate> nsapp_delegate_; |
| DISALLOW_COPY_AND_ASSIGN(AppShimController); |
| }; |
| @@ -89,6 +108,14 @@ void AppShimController::Init() { |
| channel_->Send(new AppShimHostMsg_LaunchApp( |
| g_info->profile_dir.value(), g_info->app_mode_id)); |
| + |
| + nsapp_delegate_.reset([[AppShimDelegate alloc] init]); |
|
tapted
2013/05/24 08:43:51
perhaps initWithController rather than the separat
jackhou1
2013/05/27 01:02:47
Done.
|
| + [nsapp_delegate_ setAppShimController:this]; |
| + [NSApp setDelegate:nsapp_delegate_]; |
| +} |
| + |
| +void AppShimController::QuitApp() { |
| + channel_->Send(new AppShimHostMsg_QuitApp); |
| } |
| bool AppShimController::OnMessageReceived(const IPC::Message& message) { |
| @@ -124,13 +151,39 @@ void AppShimController::OnLaunchAppDone(bool success) { |
| } |
| void AppShimController::Quit() { |
|
tapted
2013/05/24 08:43:51
will it be less confusing if this is called 'Close
jackhou1
2013/05/27 01:02:47
Yeah, agreed.
|
| - [NSApp terminate:nil]; |
| + [nsapp_delegate_ terminateNow]; |
| } |
| void AppShimController::OnDidActivateApplication() { |
| channel_->Send(new AppShimHostMsg_FocusApp); |
| } |
| +@implementation AppShimDelegate |
| + |
| +@synthesize appShimController = appShimController_; |
| + |
| +- (id)init { |
|
tapted
2013/05/24 08:43:51
init functions all follow the pattern
- (id) init
jackhou1
2013/05/27 01:02:47
Done.
|
| + terminateNow_ = NO; |
|
tapted
2013/05/24 08:43:51
don't need to initialize objective C members that
jackhou1
2013/05/27 01:02:47
Done.
|
| + return self; |
| +} |
| + |
| +- (NSApplicationTerminateReply) |
| + applicationShouldTerminate:(NSApplication*)sender { |
| + if (terminateNow_) |
| + return NSTerminateNow; |
| + |
| + appShimController_->QuitApp(); |
| + // Wait for the channel to close before terminating. |
| + return NSTerminateCancel; |
|
tapted
2013/05/24 08:43:51
I think this needs to set a flag like 'terminateRe
jackhou1
2013/05/27 01:02:47
Done.
|
| +} |
| + |
| +- (void)terminateNow { |
| + terminateNow_ = YES; |
|
tapted
2013/05/24 08:43:51
...then after this check
if (terminateRequested_)
jackhou1
2013/05/27 01:02:47
Done.
|
| + [NSApp terminate:nil]; |
| +} |
| + |
| +@end |
| + |
| //----------------------------------------------------------------------------- |
| // A ReplyEventHandler is a helper class to send an Apple Event to a process |