Chromium Code Reviews| Index: remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm |
| =================================================================== |
| --- remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm (revision 147494) |
| +++ remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm (working copy) |
| @@ -7,33 +7,16 @@ |
| #import <Cocoa/Cocoa.h> |
| #include "base/mac/scoped_authorizationref.h" |
| -#include "base/mac/scoped_cftyperef.h" |
| #include "remoting/host/constants_mac.h" |
| -@implementation RemotingUninstallerAppDelegate |
| +@implementation RemotingUninstaller |
| -NSString* const kLaunchAgentsDir = @"/Library/LaunchAgents"; |
| -NSString* const kPrefPaneDir = @"/Library/PreferencePanes"; |
| -NSString* const kHelperToolsDir = @"/Library/PrivilegedHelperTools"; |
| -NSString* const kApplicationDir = @"/Applications"; |
| - |
| -NSString* const kPrefPaneName = @kServiceName ".prefPane"; |
| -NSString* const kUninstallerName = |
| - @"Chrome Remote Desktop Host Uninstaller.app"; |
| - |
| // Keystone |
| const char kKeystoneAdmin[] = "/Library/Google/GoogleSoftwareUpdate/" |
| "GoogleSoftwareUpdate.bundle/Contents/MacOS/" |
| "ksadmin"; |
| const char kKeystonePID[] = "com.google.chrome_remote_desktop"; |
| -- (void)dealloc { |
| - [super dealloc]; |
| -} |
| - |
| -- (void)applicationDidFinishLaunching:(NSNotification*)aNotification { |
| -} |
| - |
| - (void)logOutput:(FILE*) pipe { |
| char readBuffer[128]; |
| for (;;) { |
| @@ -45,28 +28,30 @@ |
| } |
| } |
| -- (void)messageBox:(const char*)message { |
| - base::mac::ScopedCFTypeRef<CFStringRef> message_ref( |
| - CFStringCreateWithCString(NULL, message, (int)strlen(message))); |
| - CFOptionFlags result; |
| - CFUserNotificationDisplayAlert(0, kCFUserNotificationNoteAlertLevel, |
| - NULL, NULL, NULL, |
| - CFSTR("Chrome Remote Desktop Uninstaller"), |
| - message_ref, NULL, NULL, NULL, &result); |
| +- (NSArray*)convertToNSArray:(const char**)array { |
|
Lambros
2012/07/23 22:06:47
Is it normal ObjC++ style to add these kinds of pr
garykac
2012/07/23 22:41:09
Not sure about style. I moved it out as a plain fu
|
| + NSMutableArray* ns_array = [[[NSMutableArray alloc] init] autorelease]; |
| + int i = 0; |
| + const char* element = array[i++]; |
| + while (element != NULL) { |
| + [ns_array addObject:[NSString stringWithUTF8String:element]]; |
| + element = array[i++]; |
| + } |
| + return ns_array; |
| } |
| --(void)runCommand:(NSString*)cmd |
| - withArguments:(NSArray*)args { |
| +- (void)runCommand:(const char*)cmd |
| + withArguments:(const char**)args { |
| NSTask* task; |
| NSPipe* output = [NSPipe pipe]; |
| NSString* result; |
| - NSLog(@"Executing: %@ %@", cmd, [args componentsJoinedByString:@" "]); |
| + NSArray* arg_array = [self convertToNSArray:args]; |
| + NSLog(@"Executing: %s %@", cmd, [arg_array componentsJoinedByString:@" "]); |
| @try { |
| task = [[[NSTask alloc] init] autorelease]; |
| - [task setLaunchPath:cmd]; |
| - [task setArguments:args]; |
| + [task setLaunchPath:[NSString stringWithUTF8String:cmd]]; |
| + [task setArguments:arg_array]; |
| [task setStandardInput:[NSPipe pipe]]; |
| [task setStandardOutput:output]; |
| [task launch]; |
| @@ -97,13 +82,13 @@ |
| withArguments:(const char**)args |
| usingAuth:(AuthorizationRef)authRef { |
| - NSMutableArray* arg_array = [[[NSMutableArray alloc] init] autorelease]; |
| - int i = 0; |
| - const char* arg = args[i++]; |
| - while (arg != NULL) { |
| - [arg_array addObject:[NSString stringWithUTF8String:arg]]; |
| - arg = args[i++]; |
| + if (authRef == nil) { |
| + // We're running as root, so just run the command directly. |
|
Lambros
2012/07/23 20:42:35
This feels wrong to me - are you absolutely sure y
garykac
2012/07/23 22:41:09
Hmm.. Previous tests made me think this was requir
|
| + [self runCommand:cmd withArguments:args]; |
| + return; |
| } |
| + |
| + NSArray* arg_array = [self convertToNSArray:args]; |
| NSLog(@"Executing (as Admin): %s %@", cmd, |
| [arg_array componentsJoinedByString:@" "]); |
| FILE* pipe = NULL; |
| @@ -131,119 +116,40 @@ |
| [self sudoCommand:"/bin/rm" withArguments:args usingAuth:authRef]; |
| } |
| --(void)shutdownService { |
| - NSString* launchCtl = @"/bin/launchctl"; |
| - NSArray* argsStop = [NSArray arrayWithObjects:@"stop", |
| - @kServiceName, nil]; |
| +- (void)shutdownService { |
| + const char* launchCtl = "/bin/launchctl"; |
| + const char* argsStop[] = { "stop", remoting::kServiceName, NULL }; |
| [self runCommand:launchCtl withArguments:argsStop]; |
| - NSString* plist = [NSString stringWithFormat:@"%@/%@.plist", |
| - kLaunchAgentsDir, @kServiceName]; |
| - if ([[NSFileManager defaultManager] fileExistsAtPath:plist]) { |
| - NSArray* argsUnload = [NSArray arrayWithObjects:@"unload", |
| - @"-w", @"-S", @"Aqua", plist, nil]; |
| + if ([[NSFileManager defaultManager] fileExistsAtPath: |
| + [NSString stringWithUTF8String:remoting::kServicePlistPath]]) { |
| + const char* argsUnload[] = { "unload", "-w", "-S", "Aqua", |
| + remoting::kServicePlistPath, NULL }; |
| [self runCommand:launchCtl withArguments:argsUnload]; |
| } |
| } |
| --(void)keystoneUnregisterUsingAuth:(AuthorizationRef)authRef { |
| +- (void)keystoneUnregisterUsingAuth:(AuthorizationRef)authRef { |
| const char* args[] = { "--delete", "--productid", kKeystonePID, "-S", NULL }; |
| [self sudoCommand:kKeystoneAdmin withArguments:args usingAuth:authRef]; |
| } |
| --(void)remotingUninstallUsingAuth:(AuthorizationRef)authRef { |
| - NSString* host_enabled = [NSString stringWithFormat:@"%@/%@.me2me_enabled", |
| - kHelperToolsDir, @kServiceName]; |
| - [self sudoDelete:[host_enabled UTF8String] usingAuth:authRef]; |
| +- (void)remotingUninstallUsingAuth:(AuthorizationRef)authRef { |
| + // Remove the enabled file before shutting down the service or else it might |
| + // restart itself. |
| + [self sudoDelete:remoting::kHostEnabledPath usingAuth:authRef]; |
| [self shutdownService]; |
| - NSString* plist = [NSString stringWithFormat:@"%@/%@.plist", |
| - kLaunchAgentsDir, @kServiceName]; |
| - [self sudoDelete:[plist UTF8String] usingAuth:authRef]; |
| + [self sudoDelete:remoting::kServicePlistPath usingAuth:authRef]; |
| + [self sudoDelete:remoting::kHostBinaryPath usingAuth:authRef]; |
| + [self sudoDelete:remoting::kHostHelperScriptPath usingAuth:authRef]; |
| + [self sudoDelete:remoting::kHostConfigFilePath usingAuth:authRef]; |
| + [self sudoDelete:remoting::kPrefPaneFilePath usingAuth:authRef]; |
| + [self sudoDelete:remoting::kBrandedUninstallerPath usingAuth:authRef]; |
| + [self sudoDelete:remoting::kUnbrandedUninstallerPath usingAuth:authRef]; |
| - NSString* host_binary = [NSString stringWithFormat:@"%@/%@.me2me_host.app", |
| - kHelperToolsDir, @kServiceName]; |
| - [self sudoDelete:[host_binary UTF8String] usingAuth:authRef]; |
| - |
| - NSString* host_script = [NSString stringWithFormat:@"%@/%@.me2me.sh", |
| - kHelperToolsDir, @kServiceName]; |
| - [self sudoDelete:[host_script UTF8String] usingAuth:authRef]; |
| - |
| - NSString* auth = [NSString stringWithFormat:@"%@/%@.json", |
| - kHelperToolsDir, @kServiceName]; |
| - [self sudoDelete:[auth UTF8String] usingAuth:authRef]; |
| - |
| - NSString* prefpane = [NSString stringWithFormat:@"%@/%@", |
| - kPrefPaneDir, kPrefPaneName]; |
| - [self sudoDelete:[prefpane UTF8String] usingAuth:authRef]; |
| - |
| - NSString* uninstaller = [NSString stringWithFormat:@"%@/%@", |
| - kApplicationDir, kUninstallerName]; |
| - [self sudoDelete:[uninstaller UTF8String] usingAuth:authRef]; |
| - |
| [self keystoneUnregisterUsingAuth:authRef]; |
| } |
| -- (IBAction)uninstall:(NSButton*)sender { |
| - base::mac::ScopedAuthorizationRef authRef; |
| - |
| - NSLog(@"Chrome Remote Desktop uninstall starting."); |
| - |
| - @try { |
| - OSStatus status; |
| - status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, |
| - kAuthorizationFlagDefaults, &authRef); |
| - if (status != errAuthorizationSuccess) { |
| - [NSException raise:@"AuthorizationCreate Failure" |
| - format:@"Error during AuthorizationCreate status=%ld", status]; |
| - } |
| - |
| - AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0}; |
| - AuthorizationRights rights = {1, &right}; |
| - AuthorizationFlags flags = kAuthorizationFlagDefaults | |
| - kAuthorizationFlagInteractionAllowed | |
| - kAuthorizationFlagPreAuthorize | |
| - kAuthorizationFlagExtendRights; |
| - status = AuthorizationCopyRights(authRef, &rights, NULL, flags, NULL); |
| - if (status == errAuthorizationCanceled) { |
| - NSLog(@"Chrome Remote Desktop Host uninstall canceled."); |
| - const char* message = "Chrome Remote Desktop Host uninstall canceled."; |
| - [self messageBox:message]; |
| - } else if (status == errAuthorizationSuccess) { |
| - [self remotingUninstallUsingAuth:authRef]; |
| - |
| - NSLog(@"Chrome Remote Desktop Host uninstall complete."); |
| - const char* message = |
| - "Chrome Remote Desktop Host was successfully uninstalled."; |
| - [self messageBox:message]; |
| - } else { |
| - [NSException raise:@"AuthorizationCopyRights Failure" |
| - format:@"Error during AuthorizationCopyRights status=%ld", status]; |
| - } |
| - } |
| - @catch (NSException* exception) { |
| - NSLog(@"Exception %@ %@", [exception name], [exception reason]); |
| - const char* message = |
| - "Error! Unable to uninstall Chrome Remote Desktop Host."; |
| - [self messageBox:message]; |
| - } |
| - |
| - [NSApp terminate:self]; |
| -} |
| - |
| -- (IBAction)cancel:(id)sender { |
| - [NSApp terminate:self]; |
| -} |
| - |
| -- (IBAction)handleMenuClose:(NSMenuItem*)sender { |
| - [NSApp terminate:self]; |
| -} |
| - |
| @end |
| - |
| -int main(int argc, char* argv[]) |
| -{ |
| - return NSApplicationMain(argc, (const char**)argv); |
| -} |
| - |