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

Side by Side Diff: remoting/host/me2me_preference_pane.mm

Issue 10386128: Use distributed notifications instead of polling to determine success/failure of the preference pan… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/host/plugin/daemon_controller_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Use separate named notifications for success and failure because sandboxed
33 // components can't include a dictionary when sending distributed notifications.
34 // The preferences panel is not yet sandboxed, but err on the side of caution.
35 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded"
36 #define kUpdateFailedNotificationName kServiceName ".update_failed"
37
31 #define kConfigDir "/Library/PrivilegedHelperTools/" 38 #define kConfigDir "/Library/PrivilegedHelperTools/"
32 39
33 // This helper script is executed as root. It is passed a command-line option 40 // 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 41 // (--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. 42 // informs the host's launch script of whether the host is enabled or disabled.
36 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh"; 43 const char kHelperTool[] = kConfigDir kServiceName ".me2me.sh";
37 44
38 bool GetTemporaryConfigFilePath(FilePath* path) { 45 bool GetTemporaryConfigFilePath(FilePath* path) {
39 if (!file_util::GetTempDir(path)) 46 if (!file_util::GetTempDir(path))
40 return false; 47 return false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 103 }
97 104
98 - (void)willUnselect { 105 - (void)willUnselect {
99 NSDistributedNotificationCenter* center = 106 NSDistributedNotificationCenter* center =
100 [NSDistributedNotificationCenter defaultCenter]; 107 [NSDistributedNotificationCenter defaultCenter];
101 [center removeObserver:self]; 108 [center removeObserver:self];
102 109
103 [service_status_timer_ invalidate]; 110 [service_status_timer_ invalidate];
104 [service_status_timer_ release]; 111 [service_status_timer_ release];
105 service_status_timer_ = nil; 112 service_status_timer_ = nil;
113 if (have_new_config_) {
114 [self notifyPlugin: kUpdateFailedNotificationName];
115 }
106 } 116 }
107 117
108 - (void)onApply:(id)sender { 118 - (void)onApply:(id)sender {
109 if (!have_new_config_) { 119 if (!have_new_config_) {
110 // It shouldn't be possible to hit the button if there is no config to 120 // 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. 121 // apply, but check anyway just in case it happens somehow.
112 return; 122 return;
113 } 123 }
114 124
115 // Ensure the authorization token is up-to-date before using it. 125 // Ensure the authorization token is up-to-date before using it.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 pid_t job_pid = base::mac::PIDForJob(kServiceName); 294 pid_t job_pid = base::mac::PIDForJob(kServiceName);
285 if (job_pid > 0) { 295 if (job_pid > 0) {
286 kill(job_pid, SIGHUP); 296 kill(job_pid, SIGHUP);
287 } else { 297 } else {
288 LOG(ERROR) << "Failed to obtain PID of service " << kServiceName; 298 LOG(ERROR) << "Failed to obtain PID of service " << kServiceName;
289 [self showError]; 299 [self showError];
290 } 300 }
291 } else { 301 } else {
292 [self sendJobControlMessage:LAUNCH_KEY_STARTJOB]; 302 [self sendJobControlMessage:LAUNCH_KEY_STARTJOB];
293 } 303 }
304
305 // Broadcast a distributed notification to inform the plugin that the
306 // configuration has been applied.
307 [self notifyPlugin: kUpdateSucceededNotificationName];
294 } 308 }
295 309
296 - (BOOL)runHelperAsRootWithCommand:(const char*)command 310 - (BOOL)runHelperAsRootWithCommand:(const char*)command
297 inputData:(const std::string&)input_data { 311 inputData:(const std::string&)input_data {
298 AuthorizationRef authorization = 312 AuthorizationRef authorization =
299 [[authorization_view_ authorization] authorizationRef]; 313 [[authorization_view_ authorization] authorizationRef];
300 if (!authorization) { 314 if (!authorization) {
301 LOG(ERROR) << "Failed to obtain authorizationRef"; 315 LOG(ERROR) << "Failed to obtain authorizationRef";
302 return NO; 316 return NO;
303 } 317 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 407
394 int error = launch_data_get_errno(response.get()); 408 int error = launch_data_get_errno(response.get());
395 if (error) { 409 if (error) {
396 LOG(ERROR) << "launchd returned error: " << error; 410 LOG(ERROR) << "launchd returned error: " << error;
397 [self showError]; 411 [self showError];
398 return NO; 412 return NO;
399 } 413 }
400 return YES; 414 return YES;
401 } 415 }
402 416
417 - (void)notifyPlugin:(const char*)message {
418 NSDistributedNotificationCenter* center =
419 [NSDistributedNotificationCenter defaultCenter];
420 NSString* name = [NSString stringWithUTF8String:message];
421 [center postNotificationName:name
422 object:nil
423 userInfo:nil];
424 }
425
403 @end 426 @end
OLDNEW
« no previous file with comments | « no previous file | remoting/host/plugin/daemon_controller_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698