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/service/service_process_control.h" | 5 #include "chrome/browser/service/service_process_control.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/file_path.h" | 10 #include "base/file_path.h" |
9 #include "base/process_util.h" | 11 #include "base/process_util.h" |
10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
11 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
12 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
13 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/upgrade_detector.h" | 16 #include "chrome/browser/upgrade_detector.h" |
15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 140 |
139 if (browser_command_line.HasSwitch(switches::kEnableLogging)) | 141 if (browser_command_line.HasSwitch(switches::kEnableLogging)) |
140 cmd_line->AppendSwitch(switches::kEnableLogging); | 142 cmd_line->AppendSwitch(switches::kEnableLogging); |
141 | 143 |
142 std::string locale = g_browser_process->GetApplicationLocale(); | 144 std::string locale = g_browser_process->GetApplicationLocale(); |
143 cmd_line->AppendSwitchASCII(switches::kLang, locale); | 145 cmd_line->AppendSwitchASCII(switches::kLang, locale); |
144 | 146 |
145 // And then start the process asynchronously. | 147 // And then start the process asynchronously. |
146 launcher_ = new Launcher(this, cmd_line); | 148 launcher_ = new Launcher(this, cmd_line); |
147 launcher_->Run( | 149 launcher_->Run( |
148 NewRunnableMethod(this, &ServiceProcessControl::OnProcessLaunched)); | 150 base::Bind(&ServiceProcessControl::OnProcessLaunched, |
151 base::Unretained(this))); | |
csilv
2011/10/28 22:58:15
could you clarify why you're using Unretained here
James Hawkins
2011/10/29 17:43:33
ServiceProcessControl is not ref-counted. The oth
| |
149 } | 152 } |
150 | 153 |
151 void ServiceProcessControl::Disconnect() { | 154 void ServiceProcessControl::Disconnect() { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
153 channel_.reset(); | 156 channel_.reset(); |
154 } | 157 } |
155 | 158 |
156 void ServiceProcessControl::OnProcessLaunched() { | 159 void ServiceProcessControl::OnProcessLaunched() { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 if (launcher_->launched()) { | 161 if (launcher_->launched()) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 CommandLine* cmd_line) | 256 CommandLine* cmd_line) |
254 : process_(process), | 257 : process_(process), |
255 cmd_line_(cmd_line), | 258 cmd_line_(cmd_line), |
256 launched_(false), | 259 launched_(false), |
257 retry_count_(0) { | 260 retry_count_(0) { |
258 } | 261 } |
259 | 262 |
260 // Execute the command line to start the process asynchronously. | 263 // Execute the command line to start the process asynchronously. |
261 // After the command is executed, |task| is called with the process handle on | 264 // After the command is executed, |task| is called with the process handle on |
262 // the UI thread. | 265 // the UI thread. |
263 void ServiceProcessControl::Launcher::Run(Task* task) { | 266 void ServiceProcessControl::Launcher::Run(const base::Closure& task) { |
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
265 notify_task_.reset(task); | 268 notify_task_ = task; |
266 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 269 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
267 NewRunnableMethod(this, &Launcher::DoRun)); | 270 base::Bind(&Launcher::DoRun, this)); |
268 } | 271 } |
269 | 272 |
270 ServiceProcessControl::Launcher::~Launcher() {} | 273 ServiceProcessControl::Launcher::~Launcher() {} |
271 | 274 |
272 void ServiceProcessControl::Launcher::Notify() { | 275 void ServiceProcessControl::Launcher::Notify() { |
273 DCHECK(notify_task_.get()); | 276 DCHECK_EQ(false, notify_task_.is_null()); |
274 notify_task_->Run(); | 277 notify_task_.Run(); |
275 notify_task_.reset(); | 278 notify_task_.Reset(); |
276 } | 279 } |
277 | 280 |
278 #if !defined(OS_MACOSX) | 281 #if !defined(OS_MACOSX) |
279 void ServiceProcessControl::Launcher::DoDetectLaunched() { | 282 void ServiceProcessControl::Launcher::DoDetectLaunched() { |
280 DCHECK(notify_task_.get()); | 283 DCHECK_EQ(false, notify_task_.is_null()); |
284 | |
281 const uint32 kMaxLaunchDetectRetries = 10; | 285 const uint32 kMaxLaunchDetectRetries = 10; |
282 launched_ = CheckServiceProcessReady(); | 286 launched_ = CheckServiceProcessReady(); |
283 if (launched_ || (retry_count_ >= kMaxLaunchDetectRetries)) { | 287 if (launched_ || (retry_count_ >= kMaxLaunchDetectRetries)) { |
284 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 288 BrowserThread::PostTask( |
285 NewRunnableMethod(this, &Launcher::Notify)); | 289 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); |
286 return; | 290 return; |
287 } | 291 } |
288 retry_count_++; | 292 retry_count_++; |
289 | 293 |
290 // If the service process is not launched yet then check again in 2 seconds. | 294 // If the service process is not launched yet then check again in 2 seconds. |
291 const int kDetectLaunchRetry = 2000; | 295 const int kDetectLaunchRetry = 2000; |
292 MessageLoop::current()->PostDelayedTask( | 296 MessageLoop::current()->PostDelayedTask( |
293 FROM_HERE, | 297 FROM_HERE, base::Bind(&Launcher::DoDetectLaunched, this), |
294 NewRunnableMethod(this, &Launcher::DoDetectLaunched), | |
295 kDetectLaunchRetry); | 298 kDetectLaunchRetry); |
296 } | 299 } |
297 | 300 |
298 void ServiceProcessControl::Launcher::DoRun() { | 301 void ServiceProcessControl::Launcher::DoRun() { |
299 DCHECK(notify_task_.get()); | 302 DCHECK_EQ(false, notify_task_.is_null()); |
303 | |
300 base::LaunchOptions options; | 304 base::LaunchOptions options; |
301 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
302 options.start_hidden = true; | 306 options.start_hidden = true; |
303 #endif | 307 #endif |
304 if (base::LaunchProcess(*cmd_line_, options, NULL)) { | 308 if (base::LaunchProcess(*cmd_line_, options, NULL)) { |
305 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 309 BrowserThread::PostTask( |
306 NewRunnableMethod(this, | 310 BrowserThread::IO, FROM_HERE, |
307 &Launcher::DoDetectLaunched)); | 311 base::Bind(&Launcher::DoDetectLaunched, this)); |
308 } else { | 312 } else { |
309 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 313 BrowserThread::PostTask( |
310 NewRunnableMethod(this, &Launcher::Notify)); | 314 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); |
311 } | 315 } |
312 } | 316 } |
313 #endif // !OS_MACOSX | 317 #endif // !OS_MACOSX |
OLD | NEW |