Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/mac/launchd.h" | 5 #include "base/mac/launchd.h" |
| 6 | |
| 7 #include <launch.h> | |
| 8 | 6 |
| 9 #include "base/logging.h" | 7 #include "base/logging.h" |
| 10 #include "chrome/browser/mac/scoped_launch_data.h" | 8 #include "base/mac/scoped_launch_data.h" |
| 11 | 9 |
| 12 namespace launchd { | 10 namespace base { |
| 13 | 11 namespace mac { |
| 14 namespace { | |
| 15 | 12 |
| 16 // MessageForJob sends a single message to launchd with a simple dictionary | 13 // MessageForJob sends a single message to launchd with a simple dictionary |
| 17 // mapping |operation| to |job_label|, and returns the result of calling | 14 // mapping |operation| to |job_label|, and returns the result of calling |
| 18 // launch_msg to send that message. On failure, returns NULL. The caller | 15 // launch_msg to send that message. On failure, returns NULL. The caller |
| 19 // assumes ownership of the returned launch_data_t object. | 16 // assumes ownership of the returned launch_data_t object. |
| 20 launch_data_t MessageForJob(const std::string& job_label, | 17 launch_data_t MessageForJob(const std::string& job_label, |
| 21 const char* operation) { | 18 const char* operation) { |
| 22 // launch_data_alloc returns something that needs to be freed. | 19 // launch_data_alloc returns something that needs to be freed. |
| 23 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY)); | 20 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY)); |
| 24 if (!message) { | 21 if (!message) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 38 | 35 |
| 39 if (!launch_data_dict_insert(message, | 36 if (!launch_data_dict_insert(message, |
| 40 job_label_launchd.release(), | 37 job_label_launchd.release(), |
| 41 operation)) { | 38 operation)) { |
| 42 return NULL; | 39 return NULL; |
| 43 } | 40 } |
| 44 | 41 |
| 45 return launch_msg(message); | 42 return launch_msg(message); |
| 46 } | 43 } |
| 47 | 44 |
| 48 } // namespace | |
| 49 | |
| 50 pid_t PIDForJob(const std::string& job_label) { | 45 pid_t PIDForJob(const std::string& job_label) { |
| 51 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB)); | 46 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB)); |
| 52 if (!response) { | 47 if (!response) { |
| 53 return -1; | 48 return -1; |
| 54 } | 49 } |
| 55 | 50 |
| 56 launch_data_type_t response_type = launch_data_get_type(response); | 51 launch_data_type_t response_type = launch_data_get_type(response); |
| 57 if (response_type != LAUNCH_DATA_DICTIONARY) { | 52 if (response_type != LAUNCH_DATA_DICTIONARY) { |
| 58 if (response_type == LAUNCH_DATA_ERRNO) { | 53 if (response_type == LAUNCH_DATA_ERRNO) { |
| 59 LOG(ERROR) << "PIDForJob: error " << launch_data_get_errno(response); | 54 LOG(ERROR) << "PIDForJob: error " << launch_data_get_errno(response); |
| 60 } else { | 55 } else { |
| 61 LOG(ERROR) << "PIDForJob: expected dictionary, got " << response_type; | 56 LOG(ERROR) << "PIDForJob: expected dictionary, got " << response_type; |
| 62 } | 57 } |
| 63 return -1; | 58 return -1; |
| 64 } | 59 } |
| 65 | 60 |
| 66 launch_data_t pid_data = launch_data_dict_lookup(response, | 61 launch_data_t pid_data = launch_data_dict_lookup(response, |
| 67 LAUNCH_JOBKEY_PID); | 62 LAUNCH_JOBKEY_PID); |
| 68 if (!pid_data) { | 63 if (!pid_data) |
| 69 LOG(ERROR) << "PIDForJob: no pid"; | 64 return 0; |
|
Mark Mentovai
2012/03/28 16:37:50
Why have you changed this? Now it doesn’t even mat
| |
| 70 return -1; | |
| 71 } | |
| 72 | 65 |
| 73 if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) { | 66 if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) { |
| 74 LOG(ERROR) << "PIDForJob: expected integer"; | 67 LOG(ERROR) << "PIDForJob: expected integer"; |
| 75 return -1; | 68 return -1; |
| 76 } | 69 } |
| 77 | 70 |
| 78 return launch_data_get_integer(pid_data); | 71 return launch_data_get_integer(pid_data); |
| 79 } | 72 } |
| 80 | 73 |
| 81 } // namespace launchd | 74 } // namespace mac |
| 75 } // namespace base | |
| OLD | NEW |