Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: chrome/app_shim/chrome_main_app_mode_mac.mm

Issue 2416313002: Prepare chrome_main_app_mode_mac.mm for 10.9 (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build_overrides/build.gni ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app_shim/chrome_main_app_mode_mac.mm
diff --git a/chrome/app_shim/chrome_main_app_mode_mac.mm b/chrome/app_shim/chrome_main_app_mode_mac.mm
index a6d38f95182530545be4234b7abf2420ac72af76..6aaeca9dbb7363106424faf361bb6d532e095d02 100644
--- a/chrome/app_shim/chrome_main_app_mode_mac.mm
+++ b/chrome/app_shim/chrome_main_app_mode_mac.mm
@@ -480,11 +480,7 @@ void AppShimController::SendSetAppHidden(bool hidden) {
base::Callback<void(bool)> onReply_;
AEDesc replyEvent_;
}
-// Sends an Apple Event to the process identified by |psn|, and calls |replyFn|
-// when the reply is received. Internally this creates a ReplyEventHandler,
-// which will delete itself once the reply event has been received.
-+ (void)pingProcess:(const ProcessSerialNumber&)psn
- andCall:(base::Callback<void(bool)>)replyFn;
+
@end
@interface ReplyEventHandler (PrivateMethods)
@@ -493,9 +489,8 @@ void AppShimController::SendSetAppHidden(bool hidden) {
// Apple Event reply arrives.
- (id)initWithCallback:(base::Callback<void(bool)>)replyFn;
-// Sends an Apple Event ping to the process identified by |psn| and registers
-// to listen for a reply.
-- (void)pingProcess:(const ProcessSerialNumber&)psn;
+// Returns the apple event that should be sent to the process.
+- (NSAppleEventDescriptor*)appleEventToSendToProcess;
// Called when a response is received from the target process for the ping sent
// by |-pingProcess:|.
@@ -508,14 +503,7 @@ void AppShimController::SendSetAppHidden(bool hidden) {
@end
@implementation ReplyEventHandler
-+ (void)pingProcess:(const ProcessSerialNumber&)psn
- andCall:(base::Callback<void(bool)>)replyFn {
- // The object will release itself when the reply arrives, or possibly earlier
- // if an unrecoverable error occurs.
- ReplyEventHandler* handler =
- [[ReplyEventHandler alloc] initWithCallback:replyFn];
- [handler pingProcess:psn];
-}
+
@end
@implementation ReplyEventHandler (PrivateMethods)
@@ -526,35 +514,20 @@ void AppShimController::SendSetAppHidden(bool hidden) {
return self;
}
-- (void)pingProcess:(const ProcessSerialNumber&)psn {
+- (NSAppleEventDescriptor*)appleEventToSendToProcess {
// Register the reply listener.
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
andSelector:@selector(message:withReply:)
forEventClass:'aevt'
andEventID:'ansr'];
- // Craft the Apple Event to send.
- NSAppleEventDescriptor* target = [NSAppleEventDescriptor
- descriptorWithDescriptorType:typeProcessSerialNumber
- bytes:&psn
- length:sizeof(psn)];
- NSAppleEventDescriptor* initial_event =
- [NSAppleEventDescriptor
- appleEventWithEventClass:app_mode::kAEChromeAppClass
- eventID:app_mode::kAEChromeAppPing
- targetDescriptor:target
- returnID:kAutoGenerateReturnID
- transactionID:kAnyTransactionID];
-
- // Note that AESendMessage effectively ignores kAEDefaultTimeout, because this
- // call does not pass kAEWantReceipt (which is deprecated and unsupported on
- // Mac). Instead, rely on OnPingChromeTimeout().
- OSStatus status = AESendMessage(
- [initial_event aeDesc], &replyEvent_, kAEQueueReply, kAEDefaultTimeout);
- if (status != noErr) {
- OSSTATUS_LOG(ERROR, status) << "AESendMessage";
- [self closeWithSuccess:false];
- }
+ NSAppleEventDescriptor* initial_event = [NSAppleEventDescriptor
+ appleEventWithEventClass:app_mode::kAEChromeAppClass
+ eventID:app_mode::kAEChromeAppPing
+ targetDescriptor:nil
+ returnID:kAutoGenerateReturnID
+ transactionID:kAnyTransactionID];
+ return initial_event;
}
- (void)message:(NSAppleEventDescriptor*)event
@@ -668,7 +641,6 @@ int ChromeAppModeStart_v4(const app_mode::ChromeAppModeInfo* info) {
!base::CommandLine::ForCurrentProcess()->HasSwitch(
app_mode::kLaunchedForTest)) {
// Launch Chrome if it isn't already running.
- ProcessSerialNumber psn;
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitch(switches::kSilentLaunch);
@@ -681,23 +653,20 @@ int ChromeAppModeStart_v4(const app_mode::ChromeAppModeInfo* info) {
info->profile_dir);
}
+ base::Callback<void(bool)> on_ping_chrome_reply = base::Bind(
+ &AppShimController::OnPingChromeReply, base::Unretained(&controller));
+
+ // Self-owned object that will delete itself.
+ ReplyEventHandler* handler =
+ [[ReplyEventHandler alloc] initWithCallback:on_ping_chrome_reply];
+ // NSAppleEventDescriptor* descriptor = [handler appleEventToSendToProcess];
tapted 2016/10/17 04:44:07 I think the rest looks good - we just need to pass
+
base::Process app = base::mac::OpenApplicationWithPath(
base::mac::OuterBundlePath(), command_line, NSWorkspaceLaunchDefault);
-
- // TODO(crbug.com/652563): Do not use deprecated GetProcessForPID. Change
- // |ReplyEventHandler| to take |pid_t| instead of |ProcessSerialNumber|.
- if (!app.IsValid() || GetProcessForPID(app.Pid(), &psn) != noErr)
+ if (!app.IsValid()) {
+ [handler closeWithSuccess:false];
return 1;
-
- base::Callback<void(bool)> on_ping_chrome_reply =
- base::Bind(&AppShimController::OnPingChromeReply,
- base::Unretained(&controller));
-
- // This code abuses the fact that Apple Events sent before the process is
- // fully initialized don't receive a reply until its run loop starts. Once
- // the reply is received, Chrome will have opened its IPC port, guaranteed.
- [ReplyEventHandler pingProcess:psn
- andCall:on_ping_chrome_reply];
+ }
main_message_loop.task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&AppShimController::OnPingChromeTimeout,
« no previous file with comments | « build_overrides/build.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698