| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/child_process_launcher.h" | 5 #include "chrome/browser/child_process_launcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| 11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/common/chrome_descriptors.h" | 12 #include "chrome/common/chrome_descriptors.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/process_watcher.h" | 14 #include "chrome/common/process_watcher.h" |
| 15 #include "chrome/common/result_codes.h" | 15 #include "chrome/common/result_codes.h" |
| 16 | 16 |
| 17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 18 #include "chrome/browser/sandbox_policy.h" | 18 #include "chrome/browser/sandbox_policy.h" |
| 19 #elif defined(OS_LINUX) | 19 #elif defined(OS_LINUX) |
| 20 #include "base/singleton.h" | 20 #include "base/singleton.h" |
| 21 #include "chrome/browser/crash_handler_host_linux.h" | 21 #include "chrome/browser/crash_handler_host_linux.h" |
| 22 #include "chrome/browser/zygote_host_linux.h" | 22 #include "chrome/browser/zygote_host_linux.h" |
| 23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 27 #include "base/global_descriptors_posix.h" | 27 #include "base/global_descriptors_posix.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 #include "chrome/common/mach_ipc_mac.h" |
| 31 #include <mach/host_info.h> |
| 32 #include <mach/processor_info.h> |
| 33 |
| 30 // Having the functionality of ChildProcessLauncher be in an internal | 34 // Having the functionality of ChildProcessLauncher be in an internal |
| 31 // ref counted object allows us to automatically terminate the process when the | 35 // ref counted object allows us to automatically terminate the process when the |
| 32 // parent class destructs, while still holding on to state that we need. | 36 // parent class destructs, while still holding on to state that we need. |
| 33 class ChildProcessLauncher::Context | 37 class ChildProcessLauncher::Context |
| 34 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { | 38 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { |
| 35 public: | 39 public: |
| 36 Context() | 40 Context() |
| 37 : starting_(true) | 41 : starting_(true) |
| 38 #if defined(OS_LINUX) | 42 #if defined(OS_LINUX) |
| 39 , zygote_(false) | 43 , zygote_(false) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 161 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
| 158 } | 162 } |
| 159 #endif // defined(OS_LINUX) | 163 #endif // defined(OS_LINUX) |
| 160 | 164 |
| 161 // Actually launch the app. | 165 // Actually launch the app. |
| 162 if (!base::LaunchApp(cmd_line->argv(), env, fds_to_map, false, &handle)) | 166 if (!base::LaunchApp(cmd_line->argv(), env, fds_to_map, false, &handle)) |
| 163 handle = base::kNullProcessHandle; | 167 handle = base::kNullProcessHandle; |
| 164 } | 168 } |
| 165 #endif | 169 #endif |
| 166 | 170 |
| 171 // This creates our named server port |
| 172 ReceivePort receivePort("com.Google.MyService"); |
| 173 |
| 174 MachReceiveMessage message; |
| 175 kern_return_t result = receivePort.WaitForMessage(&message, 1000); // timeo
ut 1000ms |
| 176 |
| 177 if (result == KERN_SUCCESS && message.GetMessageID() == 57) { |
| 178 |
| 179 mach_port_t task = message.GetTranslatedPort(0); |
| 180 mach_port_t thread = message.GetTranslatedPort(1); |
| 181 mach_port_t host = message.GetTranslatedPort(2); |
| 182 |
| 183 unsigned char *messageString = static_cast<unsigned char*>(message.GetData
()); |
| 184 |
| 185 printf("message string = %s %lu %lu\n", messageString, (unsigned long)task
, (unsigned long)thread); |
| 186 |
| 187 kern_return_t error; |
| 188 host_cpu_load_info_data_t /*prev_cpu_load, */cpu_load; |
| 189 mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT; |
| 190 error = host_statistics(host, |
| 191 HOST_CPU_LOAD_INFO, |
| 192 (host_info_t)&cpu_load, |
| 193 &count); |
| 194 if (error != KERN_SUCCESS) { |
| 195 fprintf(stderr, "error 1 %lu\n", (unsigned long) error); |
| 196 } |
| 197 printf("(%d %d %d)\n", |
| 198 cpu_load.cpu_ticks[CPU_STATE_USER], |
| 199 cpu_load.cpu_ticks[CPU_STATE_SYSTEM], |
| 200 cpu_load.cpu_ticks[CPU_STATE_IDLE]); |
| 201 |
| 202 task_basic_info_data_t ti; |
| 203 // count = TASK_EVENTS_INFO_COUNT; |
| 204 // error = task_info(task, TASK_EVENTS_INFO, (task_info_t)&ti, &count); |
| 205 count = TASK_BASIC_INFO_COUNT; |
| 206 error = task_info(task, TASK_BASIC_INFO, (task_info_t)&ti, &count); |
| 207 |
| 208 if (error != KERN_SUCCESS) { |
| 209 fprintf(stderr, "error 1 %lu\n", (unsigned long) error); |
| 210 } |
| 211 |
| 212 // TODO: error checking (if renderer turns into a zombie) |
| 213 fprintf(stderr, "mem real %d virtual %d\n", ti.resident_size, ti.virtual_s
ize); |
| 214 } else { |
| 215 fprintf(stderr, "Failed to receive message %lu\n", (unsigned long)result); |
| 216 } |
| 217 |
| 167 ChromeThread::PostTask( | 218 ChromeThread::PostTask( |
| 168 client_thread_id_, FROM_HERE, | 219 client_thread_id_, FROM_HERE, |
| 169 NewRunnableMethod( | 220 NewRunnableMethod( |
| 170 this, | 221 this, |
| 171 &ChildProcessLauncher::Context::Notify, | 222 &ChildProcessLauncher::Context::Notify, |
| 172 #if defined(OS_LINUX) | 223 #if defined(OS_LINUX) |
| 173 zygote, | 224 zygote, |
| 174 #endif | 225 #endif |
| 175 handle)); | 226 handle)); |
| 176 } | 227 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 if (child_exited) | 352 if (child_exited) |
| 302 context_->process_.Close(); | 353 context_->process_.Close(); |
| 303 | 354 |
| 304 return did_crash; | 355 return did_crash; |
| 305 } | 356 } |
| 306 | 357 |
| 307 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { | 358 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { |
| 308 DCHECK(!context_->starting_); | 359 DCHECK(!context_->starting_); |
| 309 context_->process_.SetProcessBackgrounded(background); | 360 context_->process_.SetProcessBackgrounded(background); |
| 310 } | 361 } |
| OLD | NEW |