Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "remoting/host/me2me_preference_pane.h" | 5 #import "remoting/host/me2me_preference_pane.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <launch.h> | 8 #include <launch.h> |
| 9 #import <PreferencePanes/PreferencePanes.h> | 9 #import <PreferencePanes/PreferencePanes.h> |
| 10 #import <SecurityInterface/SFAuthorizationView.h> | 10 #import <SecurityInterface/SFAuthorizationView.h> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
| 24 #include "remoting/host/host_config.h" | 24 #include "remoting/host/host_config.h" |
| 25 #include "remoting/host/json_host_config.h" | 25 #include "remoting/host/json_host_config.h" |
| 26 #include "remoting/protocol/me2me_host_authenticator_factory.h" | 26 #include "remoting/protocol/me2me_host_authenticator_factory.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 // The name of the Remoting Host service that is registered with launchd. | 29 // The name of the Remoting Host service that is registered with launchd. |
| 30 #define kServiceName "org.chromium.chromoting" | 30 #define kServiceName "org.chromium.chromoting" |
| 31 | |
| 32 #define kUpdateCompleteNotificationName kServiceName ".update_complete" | |
| 31 #define kConfigDir "/Library/PrivilegedHelperTools/" | 33 #define kConfigDir "/Library/PrivilegedHelperTools/" |
| 32 | 34 |
| 33 // This helper script is executed as root. It is passed a command-line option | 35 // This helper script is executed as root. It is passed a command-line option |
| 34 // (--enable or --disable), which causes it to create or remove a file that | 36 // (--enable or --disable), which causes it to create or remove a file that |
| 35 // informs the host's launch script of whether the host is enabled or disabled. | 37 // informs the host's launch script of whether the host is enabled or disabled. |
| 36 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh"; | 38 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh"; |
| 37 | 39 |
| 38 bool GetTemporaryConfigFilePath(FilePath* path) { | 40 bool GetTemporaryConfigFilePath(FilePath* path) { |
| 39 if (!file_util::GetTempDir(path)) | 41 if (!file_util::GetTempDir(path)) |
| 40 return false; | 42 return false; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 } | 98 } |
| 97 | 99 |
| 98 - (void)willUnselect { | 100 - (void)willUnselect { |
| 99 NSDistributedNotificationCenter* center = | 101 NSDistributedNotificationCenter* center = |
| 100 [NSDistributedNotificationCenter defaultCenter]; | 102 [NSDistributedNotificationCenter defaultCenter]; |
| 101 [center removeObserver:self]; | 103 [center removeObserver:self]; |
| 102 | 104 |
| 103 [service_status_timer_ invalidate]; | 105 [service_status_timer_ invalidate]; |
| 104 [service_status_timer_ release]; | 106 [service_status_timer_ release]; |
| 105 service_status_timer_ = nil; | 107 service_status_timer_ = nil; |
| 108 if (have_new_config_) { | |
| 109 [self notifyPlugin: @"CANCEL"]; | |
| 110 } | |
| 106 } | 111 } |
| 107 | 112 |
| 108 - (void)onApply:(id)sender { | 113 - (void)onApply:(id)sender { |
| 109 if (!have_new_config_) { | 114 if (!have_new_config_) { |
| 110 // It shouldn't be possible to hit the button if there is no config to | 115 // It shouldn't be possible to hit the button if there is no config to |
| 111 // apply, but check anyway just in case it happens somehow. | 116 // apply, but check anyway just in case it happens somehow. |
| 112 return; | 117 return; |
| 113 } | 118 } |
| 114 | 119 |
| 115 // Ensure the authorization token is up-to-date before using it. | 120 // Ensure the authorization token is up-to-date before using it. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 pid_t job_pid = base::mac::PIDForJob(kServiceName); | 289 pid_t job_pid = base::mac::PIDForJob(kServiceName); |
| 285 if (job_pid > 0) { | 290 if (job_pid > 0) { |
| 286 kill(job_pid, SIGHUP); | 291 kill(job_pid, SIGHUP); |
| 287 } else { | 292 } else { |
| 288 LOG(ERROR) << "Failed to obtain PID of service " << kServiceName; | 293 LOG(ERROR) << "Failed to obtain PID of service " << kServiceName; |
| 289 [self showError]; | 294 [self showError]; |
| 290 } | 295 } |
| 291 } else { | 296 } else { |
| 292 [self sendJobControlMessage:LAUNCH_KEY_STARTJOB]; | 297 [self sendJobControlMessage:LAUNCH_KEY_STARTJOB]; |
| 293 } | 298 } |
| 299 | |
| 300 // Broadcast a distributed notification to inform the plugin that the | |
| 301 // configuration has been applied. | |
| 302 [self notifyPlugin: @"OK"]; | |
| 294 } | 303 } |
| 295 | 304 |
| 296 - (BOOL)runHelperAsRootWithCommand:(const char*)command | 305 - (BOOL)runHelperAsRootWithCommand:(const char*)command |
| 297 inputData:(const std::string&)input_data { | 306 inputData:(const std::string&)input_data { |
| 298 AuthorizationRef authorization = | 307 AuthorizationRef authorization = |
| 299 [[authorization_view_ authorization] authorizationRef]; | 308 [[authorization_view_ authorization] authorizationRef]; |
| 300 if (!authorization) { | 309 if (!authorization) { |
| 301 LOG(ERROR) << "Failed to obtain authorizationRef"; | 310 LOG(ERROR) << "Failed to obtain authorizationRef"; |
| 302 return NO; | 311 return NO; |
| 303 } | 312 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 | 402 |
| 394 int error = launch_data_get_errno(response.get()); | 403 int error = launch_data_get_errno(response.get()); |
| 395 if (error) { | 404 if (error) { |
| 396 LOG(ERROR) << "launchd returned error: " << error; | 405 LOG(ERROR) << "launchd returned error: " << error; |
| 397 [self showError]; | 406 [self showError]; |
| 398 return NO; | 407 return NO; |
| 399 } | 408 } |
| 400 return YES; | 409 return YES; |
| 401 } | 410 } |
| 402 | 411 |
| 412 - (void)notifyPlugin:(NSString*)result { | |
| 413 NSDistributedNotificationCenter* center = | |
| 414 [NSDistributedNotificationCenter defaultCenter]; | |
| 415 NSString* name = | |
| 416 [[NSString alloc] initWithUTF8String:kUpdateCompleteNotificationName]; | |
|
Lambros
2012/05/15 18:55:35
nit: stringWithUTF8String might be easier (and doe
Jamie
2012/05/15 20:53:50
Thanks, I wasn't aware of that.
| |
| 417 NSDictionary* result_dictionary = | |
| 418 [NSDictionary dictionaryWithObject:result | |
| 419 forKey:@"result"]; | |
| 420 [center postNotificationName:name | |
| 421 object:nil | |
| 422 userInfo:result_dictionary]; | |
| 423 } | |
| 424 | |
| 403 @end | 425 @end |
| OLD | NEW |