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

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

Issue 1551943002: Rewrite most of the scopers in //base/mac to use ScopedTypeRef or ScopedGeneric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS Created 4 years, 11 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
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/mac/me2me_preference_pane.h" 5 #import "remoting/host/mac/me2me_preference_pane.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <CommonCrypto/CommonHMAC.h> 8 #include <CommonCrypto/CommonHMAC.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <launch.h> 10 #include <launch.h>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 namespace mac { 57 namespace mac {
58 58
59 // MessageForJob sends a single message to launchd with a simple dictionary 59 // MessageForJob sends a single message to launchd with a simple dictionary
60 // mapping |operation| to |job_label|, and returns the result of calling 60 // mapping |operation| to |job_label|, and returns the result of calling
61 // launch_msg to send that message. On failure, returns nullptr. The caller 61 // launch_msg to send that message. On failure, returns nullptr. The caller
62 // assumes ownership of the returned launch_data_t object. 62 // assumes ownership of the returned launch_data_t object.
63 launch_data_t MessageForJob(const std::string& job_label, 63 launch_data_t MessageForJob(const std::string& job_label,
64 const char* operation) { 64 const char* operation) {
65 // launch_data_alloc returns something that needs to be freed. 65 // launch_data_alloc returns something that needs to be freed.
66 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY)); 66 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
67 if (!message) { 67 if (!message.is_valid()) {
68 NSLog(@"launch_data_alloc"); 68 NSLog(@"launch_data_alloc");
69 return nullptr; 69 return nullptr;
70 } 70 }
71 71
72 // launch_data_new_string returns something that needs to be freed, but 72 // launch_data_new_string returns something that needs to be freed, but
73 // the dictionary will assume ownership when launch_data_dict_insert is 73 // the dictionary will assume ownership when launch_data_dict_insert is
74 // called, so put it in a scoper and .release() it when given to the 74 // called, so put it in a scoper and .release() it when given to the
75 // dictionary. 75 // dictionary.
76 ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str())); 76 ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
77 if (!job_label_launchd) { 77 if (!job_label_launchd.is_valid()) {
78 NSLog(@"launch_data_new_string"); 78 NSLog(@"launch_data_new_string");
79 return nullptr; 79 return nullptr;
80 } 80 }
81 81
82 if (!launch_data_dict_insert(message, 82 if (!launch_data_dict_insert(message.get(),
83 job_label_launchd.release(), 83 job_label_launchd.release(),
84 operation)) { 84 operation)) {
85 return nullptr; 85 return nullptr;
86 } 86 }
87 87
88 return launch_msg(message); 88 return launch_msg(message.get());
89 } 89 }
90 90
91 pid_t PIDForJob(const std::string& job_label) { 91 pid_t PIDForJob(const std::string& job_label) {
92 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB)); 92 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
93 if (!response) { 93 if (!response.is_valid()) {
94 return -1; 94 return -1;
95 } 95 }
96 96
97 launch_data_type_t response_type = launch_data_get_type(response); 97 launch_data_type_t response_type = launch_data_get_type(response.get());
98 if (response_type != LAUNCH_DATA_DICTIONARY) { 98 if (response_type != LAUNCH_DATA_DICTIONARY) {
99 if (response_type == LAUNCH_DATA_ERRNO) { 99 if (response_type == LAUNCH_DATA_ERRNO) {
100 NSLog(@"PIDForJob: error %d", launch_data_get_errno(response)); 100 NSLog(@"PIDForJob: error %d", launch_data_get_errno(response.get()));
101 } else { 101 } else {
102 NSLog(@"PIDForJob: expected dictionary, got %d", response_type); 102 NSLog(@"PIDForJob: expected dictionary, got %d", response_type);
103 } 103 }
104 return -1; 104 return -1;
105 } 105 }
106 106
107 launch_data_t pid_data = launch_data_dict_lookup(response, 107 launch_data_t pid_data = launch_data_dict_lookup(response.get(),
108 LAUNCH_JOBKEY_PID); 108 LAUNCH_JOBKEY_PID);
109 if (!pid_data) 109 if (!pid_data)
110 return 0; 110 return 0;
111 111
112 if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) { 112 if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) {
113 NSLog(@"PIDForJob: expected integer"); 113 NSLog(@"PIDForJob: expected integer");
114 return -1; 114 return -1;
115 } 115 }
116 116
117 return launch_data_get_integer(pid_data); 117 return launch_data_get_integer(pid_data);
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } else { 576 } else {
577 NSLog(@"%s failed with exit status %d", remoting::kHostHelperScriptPath, 577 NSLog(@"%s failed with exit status %d", remoting::kHostHelperScriptPath,
578 exit_status); 578 exit_status);
579 return NO; 579 return NO;
580 } 580 }
581 } 581 }
582 582
583 - (BOOL)sendJobControlMessage:(const char*)launch_key { 583 - (BOOL)sendJobControlMessage:(const char*)launch_key {
584 base::mac::ScopedLaunchData response( 584 base::mac::ScopedLaunchData response(
585 base::mac::MessageForJob(remoting::kServiceName, launch_key)); 585 base::mac::MessageForJob(remoting::kServiceName, launch_key));
586 if (!response) { 586 if (!response.is_valid()) {
587 NSLog(@"Failed to send message to launchd"); 587 NSLog(@"Failed to send message to launchd");
588 [self showError]; 588 [self showError];
589 return NO; 589 return NO;
590 } 590 }
591 591
592 // Expect a response of type LAUNCH_DATA_ERRNO. 592 // Expect a response of type LAUNCH_DATA_ERRNO.
593 launch_data_type_t type = launch_data_get_type(response.get()); 593 launch_data_type_t type = launch_data_get_type(response.get());
594 if (type != LAUNCH_DATA_ERRNO) { 594 if (type != LAUNCH_DATA_ERRNO) {
595 NSLog(@"launchd returned unexpected type: %d", type); 595 NSLog(@"launchd returned unexpected type: %d", type);
596 [self showError]; 596 [self showError];
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; 709 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil];
710 [task setLaunchPath:command]; 710 [task setLaunchPath:command];
711 [task setArguments:arguments]; 711 [task setArguments:arguments];
712 [task setStandardInput:[NSPipe pipe]]; 712 [task setStandardInput:[NSPipe pipe]];
713 [task launch]; 713 [task launch];
714 [task release]; 714 [task release];
715 [NSApp terminate:nil]; 715 [NSApp terminate:nil];
716 } 716 }
717 717
718 @end 718 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698