OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/debug/debugger.h" | 5 #include "base/debug/debugger.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/path_service.h" | |
8 #include "base/singleton.h" | |
9 #include "base/threading/platform_thread.h" | |
10 #include "chrome/common/chrome_paths.h" | |
11 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/main_function_params.h" | 8 #include "chrome/common/main_function_params.h" |
13 #include "chrome/common/sandbox_policy.h" | |
14 #include "chrome/common/service_process_util.h" | 9 #include "chrome/common/service_process_util.h" |
15 #include "chrome/service/cloud_print/cloud_print_proxy.h" | |
16 #include "chrome/service/service_process.h" | 10 #include "chrome/service/service_process.h" |
17 | 11 |
18 #if defined(OS_MACOSX) | 12 #if defined(OS_WIN) |
| 13 #include "chrome/common/sandbox_policy.h" |
| 14 #elif defined(OS_MACOSX) |
19 #include "chrome/common/chrome_application_mac.h" | 15 #include "chrome/common/chrome_application_mac.h" |
20 #endif | 16 #endif // defined(OS_WIN) |
21 | 17 |
22 // Mainline routine for running as the service process. | 18 // Mainline routine for running as the service process. |
23 int ServiceProcessMain(const MainFunctionParams& parameters) { | 19 int ServiceProcessMain(const MainFunctionParams& parameters) { |
24 // If there is already a service process running, quit now. | |
25 if (!ServiceProcessState::GetInstance()->Initialize()) | |
26 return 0; | |
27 | |
28 MessageLoopForUI main_message_loop; | 20 MessageLoopForUI main_message_loop; |
| 21 main_message_loop.set_thread_name("MainThread"); |
29 if (parameters.command_line_.HasSwitch(switches::kWaitForDebugger)) { | 22 if (parameters.command_line_.HasSwitch(switches::kWaitForDebugger)) { |
30 base::debug::WaitForDebugger(60, true); | 23 base::debug::WaitForDebugger(60, true); |
31 } | 24 } |
32 | 25 |
| 26 VLOG(1) << "Service process launched: " |
| 27 << parameters.command_line_.command_line_string(); |
| 28 |
33 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
34 chrome_application_mac::RegisterCrApp(); | 30 chrome_application_mac::RegisterCrApp(); |
35 #endif | 31 #endif |
36 | 32 |
37 base::PlatformThread::SetName("CrServiceMain"); | 33 base::PlatformThread::SetName("CrServiceMain"); |
38 | 34 |
| 35 // If there is already a service process running, quit now. |
| 36 if (!ServiceProcessState::GetInstance()->Initialize()) |
| 37 return 0; |
| 38 |
39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
40 sandbox::BrokerServices* broker_services = | 40 sandbox::BrokerServices* broker_services = |
41 parameters.sandbox_info_.BrokerServices(); | 41 parameters.sandbox_info_.BrokerServices(); |
42 if (broker_services) | 42 if (broker_services) |
43 sandbox::InitBrokerServices(broker_services); | 43 sandbox::InitBrokerServices(broker_services); |
44 #endif // defined(OS_WIN) | 44 #elif defined(OS_MACOSX) |
| 45 chrome_application_mac::RegisterCrApp(); |
| 46 #endif // defined(OS_WIN) |
45 | 47 |
46 ServiceProcess service_process; | 48 ServiceProcess service_process; |
47 if (!service_process.Initialize(&main_message_loop, | 49 if (service_process.Initialize(&main_message_loop, |
48 parameters.command_line_)) { | 50 parameters.command_line_)) { |
| 51 MessageLoop::current()->Run(); |
| 52 } else { |
49 LOG(ERROR) << "Service process failed to initialize"; | 53 LOG(ERROR) << "Service process failed to initialize"; |
50 return 0; | |
51 } | 54 } |
52 | |
53 MessageLoop::current()->Run(); | |
54 service_process.Teardown(); | 55 service_process.Teardown(); |
55 return 0; | 56 return 0; |
56 } | 57 } |
OLD | NEW |