| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/location.h" | 13 #include "base/location.h" |
| 12 #include "base/metrics/histogram_base.h" | 14 #include "base/metrics/histogram_base.h" |
| 13 #include "base/metrics/histogram_delta_serialization.h" | 15 #include "base/metrics/histogram_delta_serialization.h" |
| 14 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
| 15 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
| 16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // TODO(hclam): Handle error connecting to channel. | 52 // TODO(hclam): Handle error connecting to channel. |
| 51 const IPC::ChannelHandle channel_id = GetServiceProcessChannel(); | 53 const IPC::ChannelHandle channel_id = GetServiceProcessChannel(); |
| 52 SetChannel(IPC::ChannelProxy::Create( | 54 SetChannel(IPC::ChannelProxy::Create( |
| 53 channel_id, | 55 channel_id, |
| 54 IPC::Channel::MODE_NAMED_CLIENT, | 56 IPC::Channel::MODE_NAMED_CLIENT, |
| 55 this, | 57 this, |
| 56 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get())); | 58 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get())); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void ServiceProcessControl::SetChannel(scoped_ptr<IPC::ChannelProxy> channel) { | 61 void ServiceProcessControl::SetChannel(scoped_ptr<IPC::ChannelProxy> channel) { |
| 60 channel_ = channel.Pass(); | 62 channel_ = std::move(channel); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void ServiceProcessControl::RunConnectDoneTasks() { | 65 void ServiceProcessControl::RunConnectDoneTasks() { |
| 64 // The tasks executed here may add more tasks to the vector. So copy | 66 // The tasks executed here may add more tasks to the vector. So copy |
| 65 // them to the stack before executing them. This way recursion is | 67 // them to the stack before executing them. This way recursion is |
| 66 // avoided. | 68 // avoided. |
| 67 TaskList tasks; | 69 TaskList tasks; |
| 68 | 70 |
| 69 if (IsConnected()) { | 71 if (IsConnected()) { |
| 70 tasks.swap(connect_success_tasks_); | 72 tasks.swap(connect_success_tasks_); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (CheckServiceProcessReady()) { | 113 if (CheckServiceProcessReady()) { |
| 112 ConnectInternal(); | 114 ConnectInternal(); |
| 113 return; | 115 return; |
| 114 } | 116 } |
| 115 | 117 |
| 116 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", SERVICE_EVENT_LAUNCH, | 118 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", SERVICE_EVENT_LAUNCH, |
| 117 SERVICE_EVENT_MAX); | 119 SERVICE_EVENT_MAX); |
| 118 | 120 |
| 119 scoped_ptr<base::CommandLine> cmd_line(CreateServiceProcessCommandLine()); | 121 scoped_ptr<base::CommandLine> cmd_line(CreateServiceProcessCommandLine()); |
| 120 // And then start the process asynchronously. | 122 // And then start the process asynchronously. |
| 121 launcher_ = new Launcher(cmd_line.Pass()); | 123 launcher_ = new Launcher(std::move(cmd_line)); |
| 122 launcher_->Run(base::Bind(&ServiceProcessControl::OnProcessLaunched, | 124 launcher_->Run(base::Bind(&ServiceProcessControl::OnProcessLaunched, |
| 123 base::Unretained(this))); | 125 base::Unretained(this))); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void ServiceProcessControl::Disconnect() { | 128 void ServiceProcessControl::Disconnect() { |
| 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 128 channel_.reset(); | 130 channel_.reset(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void ServiceProcessControl::OnProcessLaunched() { | 133 void ServiceProcessControl::OnProcessLaunched() { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 return ret; | 318 return ret; |
| 317 } | 319 } |
| 318 | 320 |
| 319 // static | 321 // static |
| 320 ServiceProcessControl* ServiceProcessControl::GetInstance() { | 322 ServiceProcessControl* ServiceProcessControl::GetInstance() { |
| 321 return base::Singleton<ServiceProcessControl>::get(); | 323 return base::Singleton<ServiceProcessControl>::get(); |
| 322 } | 324 } |
| 323 | 325 |
| 324 ServiceProcessControl::Launcher::Launcher( | 326 ServiceProcessControl::Launcher::Launcher( |
| 325 scoped_ptr<base::CommandLine> cmd_line) | 327 scoped_ptr<base::CommandLine> cmd_line) |
| 326 : cmd_line_(cmd_line.Pass()), | 328 : cmd_line_(std::move(cmd_line)), launched_(false), retry_count_(0) {} |
| 327 launched_(false), | |
| 328 retry_count_(0) { | |
| 329 } | |
| 330 | 329 |
| 331 // Execute the command line to start the process asynchronously. | 330 // Execute the command line to start the process asynchronously. |
| 332 // After the command is executed, |task| is called with the process handle on | 331 // After the command is executed, |task| is called with the process handle on |
| 333 // the UI thread. | 332 // the UI thread. |
| 334 void ServiceProcessControl::Launcher::Run(const base::Closure& task) { | 333 void ServiceProcessControl::Launcher::Run(const base::Closure& task) { |
| 335 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 334 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 336 notify_task_ = task; | 335 notify_task_ = task; |
| 337 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 336 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 338 base::Bind(&Launcher::DoRun, this)); | 337 base::Bind(&Launcher::DoRun, this)); |
| 339 } | 338 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 if (process_.IsValid()) { | 382 if (process_.IsValid()) { |
| 384 BrowserThread::PostTask( | 383 BrowserThread::PostTask( |
| 385 BrowserThread::IO, FROM_HERE, | 384 BrowserThread::IO, FROM_HERE, |
| 386 base::Bind(&Launcher::DoDetectLaunched, this)); | 385 base::Bind(&Launcher::DoDetectLaunched, this)); |
| 387 } else { | 386 } else { |
| 388 BrowserThread::PostTask( | 387 BrowserThread::PostTask( |
| 389 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); | 388 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); |
| 390 } | 389 } |
| 391 } | 390 } |
| 392 #endif // !OS_MACOSX | 391 #endif // !OS_MACOSX |
| OLD | NEW |