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

Side by Side Diff: chrome/app_shim/chrome_main_app_mode_mac.mm

Issue 2390953003: [Mac Fix-It] Changed OpenApplicationWithPath to use NSWorkspace. (Closed)
Patch Set: Addressed review comments 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 unified diff | Download patch
OLDNEW
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 #include <vector> 11 #include <vector>
12 12
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/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/bundle_locations.h" 18 #include "base/mac/bundle_locations.h"
19 #include "base/mac/foundation_util.h" 19 #include "base/mac/foundation_util.h"
20 #include "base/mac/launch_services_util.h" 20 #import "base/mac/launch_services_util.h"
21 #include "base/mac/mac_logging.h" 21 #include "base/mac/mac_logging.h"
22 #include "base/mac/mac_util.h" 22 #include "base/mac/mac_util.h"
23 #include "base/mac/scoped_nsautorelease_pool.h" 23 #include "base/mac/scoped_nsautorelease_pool.h"
24 #include "base/mac/scoped_nsobject.h" 24 #include "base/mac/scoped_nsobject.h"
25 #include "base/mac/sdk_forward_declarations.h" 25 #include "base/mac/sdk_forward_declarations.h"
26 #include "base/macros.h" 26 #include "base/macros.h"
27 #include "base/message_loop/message_loop.h" 27 #include "base/message_loop/message_loop.h"
28 #include "base/run_loop.h" 28 #include "base/run_loop.h"
29 #include "base/strings/string_number_conversions.h" 29 #include "base/strings/string_number_conversions.h"
30 #include "base/strings/sys_string_conversions.h" 30 #include "base/strings/sys_string_conversions.h"
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 674
675 // If the shim is the app launcher, pass --show-app-list when starting a new 675 // If the shim is the app launcher, pass --show-app-list when starting a new
676 // Chrome process to inform startup codepaths and load the correct profile. 676 // Chrome process to inform startup codepaths and load the correct profile.
677 if (info->app_mode_id == app_mode::kAppListModeId) { 677 if (info->app_mode_id == app_mode::kAppListModeId) {
678 command_line.AppendSwitch(switches::kShowAppList); 678 command_line.AppendSwitch(switches::kShowAppList);
679 } else { 679 } else {
680 command_line.AppendSwitchPath(switches::kProfileDirectory, 680 command_line.AppendSwitchPath(switches::kProfileDirectory,
681 info->profile_dir); 681 info->profile_dir);
682 } 682 }
683 683
684 bool success = 684 base::Process app = base::mac::OpenApplicationWithPath(
685 base::mac::OpenApplicationWithPath(base::mac::OuterBundlePath(), 685 base::mac::OuterBundlePath(), command_line, NSWorkspaceLaunchDefault);
686 command_line, 686
687 kLSLaunchDefaults, 687 // TODO(crbug.com/652563): Do not use deprecated GetProcessForPID. Change
688 &psn); 688 // |ReplyEventHandler| to take |pid_t| instead of |ProcessSerialNumber|.
689 if (!success) 689 if (!app.IsValid() || GetProcessForPID(app.Pid(), &psn) != noErr)
690 return 1; 690 return 1;
691 691
692 base::Callback<void(bool)> on_ping_chrome_reply = 692 base::Callback<void(bool)> on_ping_chrome_reply =
693 base::Bind(&AppShimController::OnPingChromeReply, 693 base::Bind(&AppShimController::OnPingChromeReply,
694 base::Unretained(&controller)); 694 base::Unretained(&controller));
695 695
696 // This code abuses the fact that Apple Events sent before the process is 696 // This code abuses the fact that Apple Events sent before the process is
697 // fully initialized don't receive a reply until its run loop starts. Once 697 // fully initialized don't receive a reply until its run loop starts. Once
698 // the reply is received, Chrome will have opened its IPC port, guaranteed. 698 // the reply is received, Chrome will have opened its IPC port, guaranteed.
699 [ReplyEventHandler pingProcess:psn 699 [ReplyEventHandler pingProcess:psn
700 andCall:on_ping_chrome_reply]; 700 andCall:on_ping_chrome_reply];
701 701
702 main_message_loop.task_runner()->PostDelayedTask( 702 main_message_loop.task_runner()->PostDelayedTask(
703 FROM_HERE, base::Bind(&AppShimController::OnPingChromeTimeout, 703 FROM_HERE, base::Bind(&AppShimController::OnPingChromeTimeout,
704 base::Unretained(&controller)), 704 base::Unretained(&controller)),
705 base::TimeDelta::FromSeconds(kPingChromeTimeoutSeconds)); 705 base::TimeDelta::FromSeconds(kPingChromeTimeoutSeconds));
706 } else { 706 } else {
707 // Chrome already running. Proceed to init. This could still fail if Chrome 707 // Chrome already running. Proceed to init. This could still fail if Chrome
708 // is still starting up or shutting down, but the process will exit quickly, 708 // is still starting up or shutting down, but the process will exit quickly,
709 // which is preferable to waiting for the Apple Event to timeout after one 709 // which is preferable to waiting for the Apple Event to timeout after one
710 // minute. 710 // minute.
711 main_message_loop.task_runner()->PostTask( 711 main_message_loop.task_runner()->PostTask(
712 FROM_HERE, 712 FROM_HERE,
713 base::Bind(&AppShimController::Init, base::Unretained(&controller))); 713 base::Bind(&AppShimController::Init, base::Unretained(&controller)));
714 } 714 }
715 715
716 base::RunLoop().Run(); 716 base::RunLoop().Run();
717 return 0; 717 return 0;
718 } 718 }
OLDNEW
« no previous file with comments | « chrome/app_shim/app_mode_loader_mac.mm ('k') | chrome/browser/apps/app_shim/app_shim_interactive_uitest_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698