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

Unified Diff: remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm

Issue 10807061: [Chromoting] Update uninstaller to facilitate testing automation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
Index: remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm
===================================================================
--- remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm (revision 0)
+++ remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm (working copy)
@@ -0,0 +1,112 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/mac/scoped_authorizationref.h"
+#include "base/mac/scoped_cftyperef.h"
+#include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h"
+
+@implementation RemotingUninstallerAppDelegate
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
+}
+
+- (void)messageBox:(const char*)message {
+ base::mac::ScopedCFTypeRef<CFStringRef> message_ref(
+ CFStringCreateWithCString(kCFAllocatorDefault, message,
+ kCFStringEncodingUTF8));
+ CFOptionFlags result;
+ CFUserNotificationDisplayAlert(0, kCFUserNotificationNoteAlertLevel,
+ NULL, NULL, NULL,
+ CFSTR("Chrome Remote Desktop Uninstaller"),
+ message_ref, NULL, NULL, NULL, &result);
+}
+
+- (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) {
+ RemotingUninstaller* uninstaller =
+ [[[RemotingUninstaller alloc] init] autorelease];
+ [uninstaller 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[])
+{
+ // If we're launched as root, then skip the elevation and UI confirmations.
+ // This is provided as a convenience for our automated testing.
+ int euid = geteuid();
Lambros 2012/07/23 22:06:47 nit: s/int/uid_t, but I think it's OK to get rid o
garykac 2012/07/23 22:41:09 No longer applicable
+ if (euid == 0) {
+ @autoreleasepool {
+ NSLog(@"Running as euid=0. Suppressing UI and elevation prompts.");
+
+ RemotingUninstaller* uninstaller =
+ [[[RemotingUninstaller alloc] init] autorelease];
+ [uninstaller remotingUninstallUsingAuth:nil];
+
+ NSLog(@"Chrome Remote Desktop Host uninstall complete.");
+ return 0;
+ }
+ } else {
+ return NSApplicationMain(argc, (const char**)argv);
+ }
+}
+
Property changes on: remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property

Powered by Google App Engine
This is Rietveld 408576698