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

Unified Diff: chrome/browser/mac/relauncher.mm

Issue 2260633004: mac: Update relauncher to not use deprecated APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up. Created 4 years, 4 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 | « chrome/browser/mac/relauncher.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/mac/relauncher.mm
diff --git a/chrome/browser/mac/relauncher.cc b/chrome/browser/mac/relauncher.mm
similarity index 90%
rename from chrome/browser/mac/relauncher.cc
rename to chrome/browser/mac/relauncher.mm
index 40ea5371bf90732f5c8ea768b4d9bb80bb158eee..abc309410658dde15beb466fa95a72c41f87ab10 100644
--- a/chrome/browser/mac/relauncher.cc
+++ b/chrome/browser/mac/relauncher.mm
@@ -4,7 +4,8 @@
#include "chrome/browser/mac/relauncher.h"
-#include <ApplicationServices/ApplicationServices.h>
+#import <AppKit/AppKit.h>
+
#include <AvailabilityMacros.h>
#include <crt_externs.h>
#include <dlfcn.h>
@@ -23,7 +24,7 @@
#include "base/logging.h"
#include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h"
-#include "base/mac/scoped_cftyperef.h"
+#include "base/mac/scoped_nsobject.h"
#include "base/path_service.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/launch.h"
@@ -281,12 +282,8 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
// won't contain the argv[0] of the relauncher process, the
// RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the
// executable path of the process to be launched.
- base::ScopedCFTypeRef<CFMutableArrayRef> relaunch_args(
- CFArrayCreateMutable(NULL, argc - 4, &kCFTypeArrayCallBacks));
- if (!relaunch_args) {
- LOG(ERROR) << "CFArrayCreateMutable";
- return 1;
- }
+ base::scoped_nsobject<NSMutableArray> relaunch_args(
+ [[NSMutableArray alloc] init]);
// Figure out what to execute, what arguments to pass it, and whether to
// start it in the background.
@@ -326,13 +323,13 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
relaunch_executable.assign(arg);
seen_relaunch_executable = true;
} else {
- base::ScopedCFTypeRef<CFStringRef> arg_cf(
- base::SysUTF8ToCFStringRef(arg));
- if (!arg_cf) {
- LOG(ERROR) << "base::SysUTF8ToCFStringRef failed for " << arg;
+
+ NSString* arg_string = base::SysUTF8ToNSString(arg);
+ if (!arg_string) {
+ LOG(ERROR) << "base::SysUTF8ToNSString failed for " << arg;
return 1;
}
- CFArrayAppendValue(relaunch_args, arg_cf);
+ [relaunch_args addObject:arg_string];
}
}
}
@@ -342,26 +339,24 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
return 1;
}
- FSRef app_fsref;
- if (!base::mac::FSRefFromPath(relaunch_executable, &app_fsref)) {
- LOG(ERROR) << "base::mac::FSRefFromPath failed for " << relaunch_executable;
- return 1;
- }
-
- LSApplicationParameters ls_parameters = {
- 0, // version
- kLSLaunchDefaults | kLSLaunchAndDisplayErrors | kLSLaunchNewInstance |
- (background ? kLSLaunchDontSwitch : 0),
- &app_fsref,
- NULL, // asyncLaunchRefCon
- NULL, // environment
- relaunch_args,
- NULL // initialEvent
- };
-
- OSStatus status = LSOpenApplication(&ls_parameters, NULL);
- if (status != noErr) {
- OSSTATUS_LOG(ERROR, status) << "LSOpenApplication";
+ base::scoped_nsobject<NSString> path([[NSString alloc]
+ initWithCString:relaunch_executable.c_str()
Mark Mentovai 2016/08/22 17:43:31 Wouldn’t we usually -initWithUTF8String? Technica
erikchen 2016/08/22 17:54:12 Switched to base::SysUTF8ToNSString
+ encoding:NSUTF8StringEncoding]);
+ base::scoped_nsobject<NSURL> url([[NSURL alloc] initFileURLWithPath:path]);
+ NSDictionary* configuration =
+ @{NSWorkspaceLaunchConfigurationArguments : (relaunch_args.get())};
+
+ NSRunningApplication *application = [[NSWorkspace sharedWorkspace]
+ launchApplicationAtURL:url
+ options:NSWorkspaceLaunchDefault |
+ NSWorkspaceLaunchWithErrorPresentation |
+ (background ? NSWorkspaceLaunchWithoutActivation
+ : 0) |
+ NSWorkspaceLaunchNewInstance
+ configuration:configuration
+ error:nil];
+ if (!application) {
+ LOG(ERROR) << "Failed to relaunch " << relaunch_executable;
return 1;
}
« no previous file with comments | « chrome/browser/mac/relauncher.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698