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

Side by Side Diff: remoting/host/plugin/daemon_controller_mac.cc

Issue 10566013: Detect if user closes the pref-pane without disabling Chromoting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
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 #include "remoting/host/plugin/daemon_controller.h" 5 #include "remoting/host/plugin/daemon_controller.h"
6 6
7 #include <launch.h> 7 #include <launch.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/foundation_util.h" 18 #include "base/mac/foundation_util.h"
19 #include "base/mac/launchd.h" 19 #include "base/mac/launchd.h"
20 #include "base/mac/mac_logging.h" 20 #include "base/mac/mac_logging.h"
21 #include "base/mac/mac_util.h" 21 #include "base/mac/mac_util.h"
22 #include "base/mac/scoped_launch_data.h" 22 #include "base/mac/scoped_launch_data.h"
23 #include "base/sys_string_conversions.h"
23 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
24 #include "base/time.h" 25 #include "base/time.h"
25 #include "base/values.h" 26 #include "base/values.h"
26 #include "remoting/host/json_host_config.h" 27 #include "remoting/host/json_host_config.h"
27 28
28 namespace remoting { 29 namespace remoting {
29 30
30 namespace { 31 namespace {
31 32
32 // The NSSystemDirectories.h header has a conflicting definition of 33 // The NSSystemDirectories.h header has a conflicting definition of
33 // NSSearchPathDirectory with the one in base/mac/foundation_util.h. 34 // NSSearchPathDirectory with the one in base/mac/foundation_util.h.
34 // Foundation.h would work, but it can only be included from Objective-C files. 35 // Foundation.h would work, but it can only be included from Objective-C files.
35 // Therefore, we define the needed constants here. 36 // Therefore, we define the needed constants here.
36 const int NSLibraryDirectory = 5; 37 const int NSLibraryDirectory = 5;
37 38
38 // The name of the Remoting Host service that is registered with launchd. 39 // The name of the Remoting Host service that is registered with launchd.
39 #define kServiceName "org.chromium.chromoting" 40 #define kServiceName "org.chromium.chromoting"
40 41
41 // Use separate named notifications for success and failure because sandboxed 42 // Use separate named notifications for success and failure because sandboxed
42 // components can't include a dictionary when sending distributed notifications. 43 // components can't include a dictionary when sending distributed notifications.
43 // The preferences panel is not yet sandboxed, but err on the side of caution. 44 // The preferences panel is not yet sandboxed, but err on the side of caution.
44 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded" 45 #define kUpdateSucceededNotificationName kServiceName ".update_succeeded"
45 #define kUpdateFailedNotificationName kServiceName ".update_failed" 46 #define kUpdateFailedNotificationName kServiceName ".update_failed"
47 #define kUserCanceledNotificationName kServiceName ".user_canceled"
48
49 const char* all_notifications[] = {
50 kUpdateSucceededNotificationName,
51 kUpdateFailedNotificationName,
52 kUserCanceledNotificationName
53 };
46 54
47 #define kConfigDir "/Library/PrivilegedHelperTools/" 55 #define kConfigDir "/Library/PrivilegedHelperTools/"
48 56
49 // This helper script is used to get the installed host version. 57 // This helper script is used to get the installed host version.
50 const char kHostHelperScript[] = kConfigDir kServiceName ".me2me.sh"; 58 const char kHostHelperScript[] = kConfigDir kServiceName ".me2me.sh";
51 59
52 // Use a single configuration file, instead of separate "auth" and "host" files. 60 // Use a single configuration file, instead of separate "auth" and "host" files.
53 // This is because the SetConfigAndStart() API only provides a single 61 // This is because the SetConfigAndStart() API only provides a single
54 // dictionary, and splitting this into two dictionaries would require 62 // dictionary, and splitting this into two dictionaries would require
55 // knowledge of which keys belong in which files. 63 // knowledge of which keys belong in which files.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 : auth_thread_("Auth thread") { 111 : auth_thread_("Auth thread") {
104 auth_thread_.Start(); 112 auth_thread_.Start();
105 } 113 }
106 114
107 DaemonControllerMac::~DaemonControllerMac() { 115 DaemonControllerMac::~DaemonControllerMac() {
108 auth_thread_.Stop(); 116 auth_thread_.Stop();
109 DeregisterForPreferencePaneNotifications(); 117 DeregisterForPreferencePaneNotifications();
110 } 118 }
111 119
112 void DaemonControllerMac::DeregisterForPreferencePaneNotifications() { 120 void DaemonControllerMac::DeregisterForPreferencePaneNotifications() {
113 CFNotificationCenterRemoveObserver( 121 for (size_t i = 0; i < arraysize(all_notifications); i++) {
114 CFNotificationCenterGetDistributedCenter(), 122 base::mac::ScopedCFTypeRef<CFStringRef> cfstring(
115 this, 123 base::SysUTF8ToCFStringRef(all_notifications[i]));
116 CFSTR(kUpdateSucceededNotificationName), 124 CFNotificationCenterRemoveObserver(
117 NULL); 125 CFNotificationCenterGetDistributedCenter(),
118 CFNotificationCenterRemoveObserver( 126 this,
119 CFNotificationCenterGetDistributedCenter(), 127 cfstring,
120 this, 128 NULL);
121 CFSTR(kUpdateFailedNotificationName), 129 }
122 NULL);
123 } 130 }
124 131
125 DaemonController::State DaemonControllerMac::GetState() { 132 DaemonController::State DaemonControllerMac::GetState() {
126 if (!base::mac::IsOSSnowLeopardOrLater()) { 133 if (!base::mac::IsOSSnowLeopardOrLater()) {
127 return DaemonController::STATE_NOT_IMPLEMENTED; 134 return DaemonController::STATE_NOT_IMPLEMENTED;
128 } 135 }
129 pid_t job_pid = base::mac::PIDForJob(kServiceName); 136 pid_t job_pid = base::mac::PIDForJob(kServiceName);
130 if (job_pid < 0) { 137 if (job_pid < 0) {
131 return DaemonController::STATE_NOT_INSTALLED; 138 return DaemonController::STATE_NOT_INSTALLED;
132 } else if (job_pid == 0) { 139 } else if (job_pid == 0) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // This is safe because HostNPScriptObject::InvokeAsyncResultCallback 325 // This is safe because HostNPScriptObject::InvokeAsyncResultCallback
319 // bounces the invocation to the correct thread, so it doesn't matter 326 // bounces the invocation to the correct thread, so it doesn't matter
320 // which thread CompletionCallbacks are called on. 327 // which thread CompletionCallbacks are called on.
321 void DaemonControllerMac::RegisterForPreferencePaneNotifications( 328 void DaemonControllerMac::RegisterForPreferencePaneNotifications(
322 const CompletionCallback& done_callback) { 329 const CompletionCallback& done_callback) {
323 // We can only have one callback registered at a time. This is enforced by the 330 // We can only have one callback registered at a time. This is enforced by the
324 // UX flow of the web-app. 331 // UX flow of the web-app.
325 DCHECK(current_callback_.is_null()); 332 DCHECK(current_callback_.is_null());
326 current_callback_ = done_callback; 333 current_callback_ = done_callback;
327 334
328 CFNotificationCenterAddObserver( 335 for (size_t i = 0; i < arraysize(all_notifications); i++) {
329 CFNotificationCenterGetDistributedCenter(), 336 base::mac::ScopedCFTypeRef<CFStringRef> cfstring(
330 this, 337 base::SysUTF8ToCFStringRef(all_notifications[i]));
331 &DaemonControllerMac::PreferencePaneCallback, 338 CFNotificationCenterAddObserver(
332 CFSTR(kUpdateSucceededNotificationName), 339 CFNotificationCenterGetDistributedCenter(),
333 NULL, 340 this,
334 CFNotificationSuspensionBehaviorDeliverImmediately); 341 &DaemonControllerMac::PreferencePaneCallback,
335 CFNotificationCenterAddObserver( 342 cfstring,
336 CFNotificationCenterGetDistributedCenter(), 343 NULL,
337 this, 344 CFNotificationSuspensionBehaviorDeliverImmediately);
338 &DaemonControllerMac::PreferencePaneCallback, 345 }
339 CFSTR(kUpdateFailedNotificationName),
340 NULL,
341 CFNotificationSuspensionBehaviorDeliverImmediately);
342 } 346 }
343 347
344 void DaemonControllerMac::PreferencePaneCallbackDelegate(CFStringRef name) { 348 void DaemonControllerMac::PreferencePaneCallbackDelegate(CFStringRef name) {
345 AsyncResult result = RESULT_FAILED; 349 AsyncResult result = RESULT_FAILED;
346 if (CFStringCompare(name, CFSTR(kUpdateSucceededNotificationName), 0) == 350 if (CFStringCompare(name, CFSTR(kUpdateSucceededNotificationName), 0) ==
347 kCFCompareEqualTo) { 351 kCFCompareEqualTo) {
348 result = RESULT_OK; 352 result = RESULT_OK;
349 } else if (CFStringCompare(name, CFSTR(kUpdateFailedNotificationName), 0) == 353 } else if (CFStringCompare(name, CFSTR(kUpdateFailedNotificationName), 0) ==
350 kCFCompareEqualTo) { 354 kCFCompareEqualTo) {
355 result = RESULT_FAILED;
356 } else if (CFStringCompare(name, CFSTR(kUserCanceledNotificationName), 0) ==
357 kCFCompareEqualTo) {
351 result = RESULT_CANCELLED; 358 result = RESULT_CANCELLED;
352 } else { 359 } else {
353 LOG(WARNING) << "Ignoring unexpected notification: " << name; 360 LOG(WARNING) << "Ignoring unexpected notification: " << name;
354 return; 361 return;
355 } 362 }
356 DCHECK(!current_callback_.is_null()); 363 DCHECK(!current_callback_.is_null());
357 current_callback_.Run(result); 364 current_callback_.Run(result);
358 current_callback_.Reset(); 365 current_callback_.Reset();
359 DeregisterForPreferencePaneNotifications(); 366 DeregisterForPreferencePaneNotifications();
360 } 367 }
(...skipping 11 matching lines...) Expand all
372 } 379 }
373 } 380 }
374 381
375 } // namespace 382 } // namespace
376 383
377 scoped_ptr<DaemonController> remoting::DaemonController::Create() { 384 scoped_ptr<DaemonController> remoting::DaemonController::Create() {
378 return scoped_ptr<DaemonController>(new DaemonControllerMac()); 385 return scoped_ptr<DaemonController>(new DaemonControllerMac());
379 } 386 }
380 387
381 } // namespace remoting 388 } // namespace remoting
OLDNEW
« remoting/host/me2me_preference_pane.mm ('K') | « remoting/host/me2me_preference_pane.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698