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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "chrome/common/chrome_paths.h" | 7 #include "chrome/common/chrome_paths.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/main_function_params.h" | 9 #include "chrome/common/main_function_params.h" |
10 #include "chrome/common/sandbox_policy.h" | 10 #include "chrome/common/sandbox_policy.h" |
11 #include "chrome/service/cloud_print/cloud_print_proxy.h" | 11 #include "chrome/service/cloud_print/cloud_print_proxy.h" |
12 #include "chrome/service/service_process.h" | 12 #include "chrome/service/service_process.h" |
13 | 13 |
14 #if defined(ENABLE_REMOTING) | |
15 #include "remoting/host/json_host_config.h" | |
16 #include "remoting/host/chromoting_host.h" | |
17 #include "remoting/host/chromoting_host_context.h" | |
18 | |
19 // This method is called as a signal that the Chromoting Host Process is | |
20 // shutting down because of failure or a request made by the user. | |
21 // We'll then post a task to |message_loop| to stop the chromoting host | |
22 // context to finish the final cleanup. | |
23 static void OnChromotingHostShutdown( | |
24 MessageLoop* message_loop, remoting::ChromotingHostContext* context) { | |
25 message_loop->PostTask(FROM_HERE, | |
26 NewRunnableMethod(context, &remoting::ChromotingHostContext::Stop)); | |
27 } | |
28 #endif | |
29 | |
30 // Mainline routine for running as the service process. | 14 // Mainline routine for running as the service process. |
31 int ServiceProcessMain(const MainFunctionParams& parameters) { | 15 int ServiceProcessMain(const MainFunctionParams& parameters) { |
32 MessageLoopForUI main_message_loop; | 16 MessageLoopForUI main_message_loop; |
33 PlatformThread::SetName("CrServiceMain"); | 17 PlatformThread::SetName("CrServiceMain"); |
34 | 18 |
35 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
36 sandbox::BrokerServices* broker_services = | 20 sandbox::BrokerServices* broker_services = |
37 parameters.sandbox_info_.BrokerServices(); | 21 parameters.sandbox_info_.BrokerServices(); |
38 if (broker_services) | 22 if (broker_services) |
39 sandbox::InitBrokerServices(broker_services); | 23 sandbox::InitBrokerServices(broker_services); |
40 #endif // defined(OS_WIN) | 24 #endif // defined(OS_WIN) |
41 | 25 |
42 ServiceProcess service_process; | 26 ServiceProcess service_process; |
43 service_process.Initialize(); | 27 service_process.Initialize(&main_message_loop); |
44 | 28 |
45 // Enable Cloud Print if needed. | 29 // Enable Cloud Print if needed. |
46 if (parameters.command_line_.HasSwitch(switches::kEnableCloudPrintProxy)) { | 30 if (parameters.command_line_.HasSwitch(switches::kEnableCloudPrintProxy)) { |
47 std::string lsid = | 31 std::string lsid = |
48 parameters.command_line_.GetSwitchValueASCII( | 32 parameters.command_line_.GetSwitchValueASCII( |
49 switches::kServiceAccountLsid); | 33 switches::kServiceAccountLsid); |
50 service_process.GetCloudPrintProxy()->EnableForUser(lsid); | 34 service_process.GetCloudPrintProxy()->EnableForUser(lsid); |
51 } | 35 } |
52 | 36 |
53 #if defined(ENABLE_REMOTING) | |
54 // Enable Chromoting Host if needed. | |
55 // TODO(hclam): Merge this config file with Cloud Printing. | |
56 // TODO(hclam): There is only start but not stop of the chromoting host | |
57 // process. | |
58 FilePath user_data_dir; | |
59 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
60 FilePath chromoting_config_path = | |
61 user_data_dir.Append(FILE_PATH_LITERAL(".ChromotingConfig.json")); | |
62 scoped_refptr<remoting::JsonHostConfig> chromoting_config; | |
63 scoped_ptr<remoting::ChromotingHostContext> chromoting_context; | |
64 scoped_refptr<remoting::ChromotingHost> chromoting_host; | |
65 if (parameters.command_line_.HasSwitch(switches::kEnableRemoting)) { | |
66 chromoting_config = new remoting::JsonHostConfig( | |
67 chromoting_config_path, | |
68 service_process.file_thread()->message_loop_proxy()); | |
69 if (!chromoting_config->Read()) { | |
70 LOG(ERROR) << "Failed to read chromoting config file."; | |
71 } else { | |
72 chromoting_context.reset(new remoting::ChromotingHostContext()); | |
73 | |
74 // Create the Chromoting Host Process with the context and config. | |
75 chromoting_host = service_process.CreateChromotingHost( | |
76 chromoting_context.get(), chromoting_config); | |
77 | |
78 // And start the context and the host process. | |
79 chromoting_context->Start(); | |
80 | |
81 // When ChromotingHost is shutdown because of failure or a request that | |
82 // we made. ShutdownChromotingTask() is calls. | |
83 // ShutdownChromotingTask() will then post a task to | |
84 // |main_message_loop| to shutdown the chromoting context. | |
85 chromoting_host->Start( | |
86 NewRunnableFunction(&OnChromotingHostShutdown, | |
87 &main_message_loop, chromoting_context.get())); | |
88 } | |
89 } | |
90 #endif | |
91 | |
92 MessageLoop::current()->Run(); | 37 MessageLoop::current()->Run(); |
93 service_process.Teardown(); | 38 service_process.Teardown(); |
94 | |
95 return 0; | 39 return 0; |
96 } | 40 } |
OLD | NEW |