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 "chrome/browser/service/service_process_control.h" | 5 #include "chrome/browser/service/service_process_control.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 // Actually going to connect. | 117 // Actually going to connect. |
118 VLOG(1) << "Connecting to Service Process IPC Server"; | 118 VLOG(1) << "Connecting to Service Process IPC Server"; |
119 // Run the IPC channel on the shared IO thread. | 119 // Run the IPC channel on the shared IO thread. |
120 base::Thread* io_thread = g_browser_process->io_thread(); | 120 base::Thread* io_thread = g_browser_process->io_thread(); |
121 | 121 |
122 // TODO(hclam): Handle error connecting to channel. | 122 // TODO(hclam): Handle error connecting to channel. |
123 const std::string channel_id = GetServiceProcessChannelName(); | 123 const std::string channel_id = GetServiceProcessChannelName(); |
124 channel_.reset( | 124 channel_.reset( |
125 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, | 125 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_NAMED_CLIENT, this, |
126 io_thread->message_loop(), true, | 126 io_thread->message_loop(), true, |
127 g_browser_process->shutdown_event())); | 127 g_browser_process->shutdown_event())); |
128 channel_->set_sync_messages_with_no_timeout_allowed(false); | |
129 | |
130 // We just established a channel with the service process. Notify it if an | |
131 // upgrade is available. | |
132 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | |
133 Send(new ServiceMsg_UpdateAvailable); | |
134 } else { | |
135 if (registrar_.IsEmpty()) | |
136 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, | |
137 NotificationService::AllSources()); | |
138 } | |
139 } | 128 } |
140 | 129 |
141 void ServiceProcessControl::RunConnectDoneTasks() { | 130 void ServiceProcessControl::RunConnectDoneTasks() { |
142 RunAllTasksHelper(&connect_done_tasks_); | 131 RunAllTasksHelper(&connect_done_tasks_); |
143 DCHECK(connect_done_tasks_.empty()); | 132 DCHECK(connect_done_tasks_.empty()); |
144 if (is_connected()) { | 133 if (is_connected()) { |
145 RunAllTasksHelper(&connect_success_tasks_); | 134 RunAllTasksHelper(&connect_success_tasks_); |
146 DCHECK(connect_success_tasks_.empty()); | 135 DCHECK(connect_success_tasks_.empty()); |
147 STLDeleteElements(&connect_failure_tasks_); | 136 STLDeleteElements(&connect_failure_tasks_); |
148 } else { | 137 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
172 failure_task = NULL; | 161 failure_task = NULL; |
173 connect_done_tasks_.push_back(success_task); | 162 connect_done_tasks_.push_back(success_task); |
174 } else { | 163 } else { |
175 connect_success_tasks_.push_back(success_task); | 164 connect_success_tasks_.push_back(success_task); |
176 } | 165 } |
177 } | 166 } |
178 | 167 |
179 if (failure_task) | 168 if (failure_task) |
180 connect_failure_tasks_.push_back(failure_task); | 169 connect_failure_tasks_.push_back(failure_task); |
181 | 170 |
| 171 // If we already in the process of launching, then we are done. |
| 172 if (launcher_) { |
| 173 return; |
| 174 } |
| 175 |
182 // If the service process is already running then connects to it. | 176 // If the service process is already running then connects to it. |
183 if (CheckServiceProcessReady()) { | 177 if (CheckServiceProcessReady()) { |
184 ConnectInternal(); | 178 ConnectInternal(); |
185 return; | 179 return; |
186 } | 180 } |
187 | 181 |
188 // If we already in the process of launching, then we are done. | |
189 if (launcher_) { | |
190 return; | |
191 } | |
192 | |
193 // A service process should have a different mechanism for starting, but now | 182 // A service process should have a different mechanism for starting, but now |
194 // we start it as if it is a child process. | 183 // we start it as if it is a child process. |
195 FilePath exe_path = ChildProcessHost::GetChildPath(true); | 184 FilePath exe_path = ChildProcessHost::GetChildPath(true); |
196 if (exe_path.empty()) { | 185 if (exe_path.empty()) { |
197 NOTREACHED() << "Unable to get service process binary name."; | 186 NOTREACHED() << "Unable to get service process binary name."; |
198 } | 187 } |
199 | 188 |
200 CommandLine* cmd_line = new CommandLine(exe_path); | 189 CommandLine* cmd_line = new CommandLine(exe_path); |
201 cmd_line->AppendSwitchASCII(switches::kProcessType, | 190 cmd_line->AppendSwitchASCII(switches::kProcessType, |
202 switches::kServiceProcess); | 191 switches::kServiceProcess); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 OnCloudPrintProxyIsEnabled) | 237 OnCloudPrintProxyIsEnabled) |
249 IPC_MESSAGE_HANDLER(ServiceHostMsg_RemotingHost_HostInfo, | 238 IPC_MESSAGE_HANDLER(ServiceHostMsg_RemotingHost_HostInfo, |
250 OnRemotingHostInfo) | 239 OnRemotingHostInfo) |
251 IPC_MESSAGE_UNHANDLED(handled = false) | 240 IPC_MESSAGE_UNHANDLED(handled = false) |
252 IPC_END_MESSAGE_MAP() | 241 IPC_END_MESSAGE_MAP() |
253 return handled; | 242 return handled; |
254 } | 243 } |
255 | 244 |
256 void ServiceProcessControl::OnChannelConnected(int32 peer_pid) { | 245 void ServiceProcessControl::OnChannelConnected(int32 peer_pid) { |
257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 247 channel_->set_sync_messages_with_no_timeout_allowed(false); |
| 248 |
| 249 // We just established a channel with the service process. Notify it if an |
| 250 // upgrade is available. |
| 251 if (UpgradeDetector::GetInstance()->notify_upgrade()) { |
| 252 Send(new ServiceMsg_UpdateAvailable); |
| 253 } else { |
| 254 if (registrar_.IsEmpty()) |
| 255 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, |
| 256 NotificationService::AllSources()); |
| 257 } |
258 RunConnectDoneTasks(); | 258 RunConnectDoneTasks(); |
259 } | 259 } |
260 | 260 |
261 void ServiceProcessControl::OnChannelError() { | 261 void ServiceProcessControl::OnChannelError() { |
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
263 channel_.reset(); | 263 channel_.reset(); |
264 RunConnectDoneTasks(); | 264 RunConnectDoneTasks(); |
265 } | 265 } |
266 | 266 |
267 bool ServiceProcessControl::Send(IPC::Message* message) { | 267 bool ServiceProcessControl::Send(IPC::Message* message) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 MessageHandler* message_handler) { | 334 MessageHandler* message_handler) { |
335 message_handlers_.insert(message_handler); | 335 message_handlers_.insert(message_handler); |
336 } | 336 } |
337 | 337 |
338 void ServiceProcessControl::RemoveMessageHandler( | 338 void ServiceProcessControl::RemoveMessageHandler( |
339 MessageHandler* message_handler) { | 339 MessageHandler* message_handler) { |
340 message_handlers_.erase(message_handler); | 340 message_handlers_.erase(message_handler); |
341 } | 341 } |
342 | 342 |
343 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl); | 343 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl); |
OLD | NEW |