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

Unified Diff: remoting/host/mac/me2me_preference_pane.mm

Issue 1778763002: Prepare remoting/ for compilation with OS X 10.7 deployment target. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp89_107_base4
Patch Set: Created 4 years, 9 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
« no previous file with comments | « remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/mac/me2me_preference_pane.mm
diff --git a/remoting/host/mac/me2me_preference_pane.mm b/remoting/host/mac/me2me_preference_pane.mm
index 508f5cd648487f93d0328e465ae4cd6d9d78a606..c4d83179ac4c9f32da0f20448a1ea3bff1b7f995 100644
--- a/remoting/host/mac/me2me_preference_pane.mm
+++ b/remoting/host/mac/me2me_preference_pane.mm
@@ -16,6 +16,8 @@
#include <fstream>
+#include "base/mac/authorization_util.h"
+#include "base/mac/launchd.h"
#include "base/mac/mac_logging.h"
#include "base/mac/scoped_launch_data.h"
#include "base/memory/scoped_ptr.h"
@@ -49,139 +51,6 @@ bool IsConfigValid(const remoting::JsonHostConfig* config) {
} // namespace
-// These methods are copied from base/mac, but with the logging changed to use
-// NSLog().
-//
-// TODO(lambroslambrou): Once the "base" target supports building for 64-bit
-// on Mac OS X, remove these implementations and use the ones in base/mac.
-namespace base {
-namespace mac {
-
-// MessageForJob sends a single message to launchd with a simple dictionary
-// mapping |operation| to |job_label|, and returns the result of calling
-// launch_msg to send that message. On failure, returns nullptr. The caller
-// assumes ownership of the returned launch_data_t object.
-launch_data_t MessageForJob(const std::string& job_label,
- const char* operation) {
- // launch_data_alloc returns something that needs to be freed.
- ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
- if (!message.is_valid()) {
- NSLog(@"launch_data_alloc");
- return nullptr;
- }
-
- // launch_data_new_string returns something that needs to be freed, but
- // the dictionary will assume ownership when launch_data_dict_insert is
- // called, so put it in a scoper and .release() it when given to the
- // dictionary.
- ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
- if (!job_label_launchd.is_valid()) {
- NSLog(@"launch_data_new_string");
- return nullptr;
- }
-
- if (!launch_data_dict_insert(message.get(),
- job_label_launchd.release(),
- operation)) {
- return nullptr;
- }
-
- return launch_msg(message.get());
-}
-
-pid_t PIDForJob(const std::string& job_label) {
- ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
- if (!response.is_valid()) {
- return -1;
- }
-
- launch_data_type_t response_type = launch_data_get_type(response.get());
- if (response_type != LAUNCH_DATA_DICTIONARY) {
- if (response_type == LAUNCH_DATA_ERRNO) {
- NSLog(@"PIDForJob: error %d", launch_data_get_errno(response.get()));
- } else {
- NSLog(@"PIDForJob: expected dictionary, got %d", response_type);
- }
- return -1;
- }
-
- launch_data_t pid_data = launch_data_dict_lookup(response.get(),
- LAUNCH_JOBKEY_PID);
- if (!pid_data)
- return 0;
-
- if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) {
- NSLog(@"PIDForJob: expected integer");
- return -1;
- }
-
- return launch_data_get_integer(pid_data);
-}
-
-OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization,
- const char* tool_path,
- AuthorizationFlags options,
- const char** arguments,
- FILE** pipe,
- pid_t* pid) {
- // pipe may be nullptr, but this function needs one. In that case, use a
- // local pipe.
- FILE* local_pipe;
- FILE** pipe_pointer;
- if (pipe) {
- pipe_pointer = pipe;
- } else {
- pipe_pointer = &local_pipe;
- }
-
- // AuthorizationExecuteWithPrivileges wants |char* const*| for |arguments|,
- // but it doesn't actually modify the arguments, and that type is kind of
- // silly and callers probably aren't dealing with that. Put the cast here
- // to make things a little easier on callers.
- OSStatus status = AuthorizationExecuteWithPrivileges(authorization,
- tool_path,
- options,
- (char* const*)arguments,
- pipe_pointer);
- if (status != errAuthorizationSuccess) {
- return status;
- }
-
- long line_pid = -1;
- size_t line_length = 0;
- char* line_c = fgetln(*pipe_pointer, &line_length);
- if (line_c) {
- if (line_length > 0 && line_c[line_length - 1] == '\n') {
- // line_c + line_length is the start of the next line if there is one.
- // Back up one character.
- --line_length;
- }
- std::string line(line_c, line_length);
-
- // The version in base/mac used base::StringToInt() here.
- line_pid = strtol(line.c_str(), nullptr, 10);
- if (line_pid == 0) {
- NSLog(@"ExecuteWithPrivilegesAndGetPid: funny line: %s", line.c_str());
- line_pid = -1;
- }
- } else {
- NSLog(@"ExecuteWithPrivilegesAndGetPid: no line");
- }
-
- if (!pipe) {
- fclose(*pipe_pointer);
- }
-
- if (pid) {
- *pid = line_pid;
- }
-
- return status;
-}
-
-} // namespace mac
-} // namespace base
-
namespace remoting {
JsonHostConfig::JsonHostConfig(const std::string& filename)
« no previous file with comments | « remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698