OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/service_process/service_process_control.h" | 5 #include "chrome/browser/service_process/service_process_control.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/metrics/histogram_base.h" | 11 #include "base/metrics/histogram_base.h" |
12 #include "base/metrics/histogram_delta_serialization.h" | 12 #include "base/metrics/histogram_delta_serialization.h" |
13 #include "base/process/kill.h" | 13 #include "base/process/kill.h" |
14 #include "base/process/launch.h" | 14 #include "base/process/launch.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/upgrade_detector.h" | 20 #include "chrome/browser/upgrade_detector.h" |
21 #include "chrome/common/chrome_switches.h" | |
22 #include "chrome/common/service_messages.h" | 21 #include "chrome/common/service_messages.h" |
23 #include "chrome/common/service_process_util.h" | 22 #include "chrome/common/service_process_util.h" |
24 #include "components/cloud_devices/common/cloud_devices_switches.h" | |
25 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
27 #include "content/public/common/child_process_host.h" | 25 #include "content/public/common/child_process_host.h" |
28 #include "google_apis/gaia/gaia_switches.h" | |
29 #include "ui/base/ui_base_switches.h" | |
30 | 26 |
31 using content::BrowserThread; | 27 using content::BrowserThread; |
32 using content::ChildProcessHost; | 28 using content::ChildProcessHost; |
33 | 29 |
34 // ServiceProcessControl implementation. | 30 // ServiceProcessControl implementation. |
35 ServiceProcessControl::ServiceProcessControl() { | 31 ServiceProcessControl::ServiceProcessControl() { |
36 } | 32 } |
37 | 33 |
38 ServiceProcessControl::~ServiceProcessControl() { | 34 ServiceProcessControl::~ServiceProcessControl() { |
39 } | 35 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 116 |
121 // A service process should have a different mechanism for starting, but now | 117 // A service process should have a different mechanism for starting, but now |
122 // we start it as if it is a child process. | 118 // we start it as if it is a child process. |
123 | 119 |
124 #if defined(OS_LINUX) | 120 #if defined(OS_LINUX) |
125 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 121 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
126 #else | 122 #else |
127 int flags = ChildProcessHost::CHILD_NORMAL; | 123 int flags = ChildProcessHost::CHILD_NORMAL; |
128 #endif | 124 #endif |
129 | 125 |
130 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 126 scoped_ptr<CommandLine> cmd_line(CreateServiceProcessCommandLine()); |
Lei Zhang
2014/06/20 02:50:29
base::CommandLine
Vitaly Buka (NO REVIEWS)
2014/06/20 04:38:43
Done.
| |
131 if (exe_path.empty()) | |
132 NOTREACHED() << "Unable to get service process binary name."; | |
133 | |
134 CommandLine* cmd_line = new CommandLine(exe_path); | |
135 cmd_line->AppendSwitchASCII(switches::kProcessType, | |
136 switches::kServiceProcess); | |
137 | |
138 static const char* const kSwitchesToCopy[] = { | |
139 switches::kCloudPrintSetupProxy, | |
140 switches::kCloudPrintURL, | |
141 switches::kCloudPrintXmppEndpoint, | |
142 #if defined(OS_WIN) | |
143 switches::kEnableCloudPrintXps, | |
144 #endif | |
145 switches::kEnableLogging, | |
146 switches::kIgnoreUrlFetcherCertRequests, | |
147 switches::kLang, | |
148 switches::kLoggingLevel, | |
149 switches::kLsoUrl, | |
150 switches::kNoServiceAutorun, | |
151 switches::kUserDataDir, | |
152 switches::kV, | |
153 switches::kVModule, | |
154 switches::kWaitForDebugger, | |
155 }; | |
156 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), | |
157 kSwitchesToCopy, | |
158 arraysize(kSwitchesToCopy)); | |
159 | |
160 // And then start the process asynchronously. | 127 // And then start the process asynchronously. |
161 launcher_ = new Launcher(this, cmd_line); | 128 launcher_ = new Launcher(this, cmd_line.Pass()); |
162 launcher_->Run(base::Bind(&ServiceProcessControl::OnProcessLaunched, | 129 launcher_->Run(base::Bind(&ServiceProcessControl::OnProcessLaunched, |
163 base::Unretained(this))); | 130 base::Unretained(this))); |
164 } | 131 } |
165 | 132 |
166 void ServiceProcessControl::Disconnect() { | 133 void ServiceProcessControl::Disconnect() { |
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
168 channel_.reset(); | 135 channel_.reset(); |
169 } | 136 } |
170 | 137 |
171 void ServiceProcessControl::OnProcessLaunched() { | 138 void ServiceProcessControl::OnProcessLaunched() { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 bool ret = Send(new ServiceMsg_Shutdown()); | 316 bool ret = Send(new ServiceMsg_Shutdown()); |
350 channel_.reset(); | 317 channel_.reset(); |
351 return ret; | 318 return ret; |
352 } | 319 } |
353 | 320 |
354 // static | 321 // static |
355 ServiceProcessControl* ServiceProcessControl::GetInstance() { | 322 ServiceProcessControl* ServiceProcessControl::GetInstance() { |
356 return Singleton<ServiceProcessControl>::get(); | 323 return Singleton<ServiceProcessControl>::get(); |
357 } | 324 } |
358 | 325 |
359 ServiceProcessControl::Launcher::Launcher(ServiceProcessControl* process, | 326 ServiceProcessControl::Launcher::Launcher( |
360 CommandLine* cmd_line) | 327 ServiceProcessControl* process, |
328 scoped_ptr<base::CommandLine> cmd_line) | |
361 : process_(process), | 329 : process_(process), |
362 cmd_line_(cmd_line), | 330 cmd_line_(cmd_line.Pass()), |
363 launched_(false), | 331 launched_(false), |
364 retry_count_(0), | 332 retry_count_(0), |
365 process_handle_(base::kNullProcessHandle) { | 333 process_handle_(base::kNullProcessHandle) { |
366 } | 334 } |
367 | 335 |
368 // Execute the command line to start the process asynchronously. | 336 // Execute the command line to start the process asynchronously. |
369 // After the command is executed, |task| is called with the process handle on | 337 // After the command is executed, |task| is called with the process handle on |
370 // the UI thread. | 338 // the UI thread. |
371 void ServiceProcessControl::Launcher::Run(const base::Closure& task) { | 339 void ServiceProcessControl::Launcher::Run(const base::Closure& task) { |
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 if (base::LaunchProcess(*cmd_line_, options, &process_handle_)) { | 396 if (base::LaunchProcess(*cmd_line_, options, &process_handle_)) { |
429 BrowserThread::PostTask( | 397 BrowserThread::PostTask( |
430 BrowserThread::IO, FROM_HERE, | 398 BrowserThread::IO, FROM_HERE, |
431 base::Bind(&Launcher::DoDetectLaunched, this)); | 399 base::Bind(&Launcher::DoDetectLaunched, this)); |
432 } else { | 400 } else { |
433 BrowserThread::PostTask( | 401 BrowserThread::PostTask( |
434 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); | 402 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); |
435 } | 403 } |
436 } | 404 } |
437 #endif // !OS_MACOSX | 405 #endif // !OS_MACOSX |
OLD | NEW |