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/extensions/api/messaging/message_service.h" | 5 #include "chrome/browser/extensions/api/messaging/message_service.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 209 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
210 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 210 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
211 source_extension_id)); | 211 source_extension_id)); |
212 | 212 |
213 NativeMessageProcessHost::MessageType type = | 213 NativeMessageProcessHost::MessageType type = |
214 channel_name == "chrome.extension.sendNativeMessage" ? | 214 channel_name == "chrome.extension.sendNativeMessage" ? |
215 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST : | 215 NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST : |
216 NativeMessageProcessHost::TYPE_CONNECT; | 216 NativeMessageProcessHost::TYPE_CONNECT; |
217 | 217 |
218 content::BrowserThread::PostTask( | 218 content::BrowserThread::PostTask( |
219 content::BrowserThread::FILE, | 219 content::BrowserThread::IO, |
rvargas (doing something else)
2012/11/29 01:19:23
Why the IO thread?
eaugusti
2012/12/07 02:21:08
Because Windows' FILE thread has a MessageLoopForI
| |
220 FROM_HERE, | 220 FROM_HERE, |
221 base::Bind(&NativeMessageProcessHost::Create, | 221 base::Bind(&NativeMessageProcessHost::Create, |
222 base::WeakPtr<NativeMessageProcessHost::Client>( | 222 base::WeakPtr<NativeMessageProcessHost::Client>( |
223 weak_factory_.GetWeakPtr()), | 223 weak_factory_.GetWeakPtr()), |
224 native_app_name, connect_message, receiver_port_id, | 224 native_app_name, connect_message, receiver_port_id, |
225 type, | 225 type, |
226 base::Bind(&MessageService::FinalizeOpenChannelToNativeApp, | 226 base::Bind(&MessageService::FinalizeOpenChannelToNativeApp, |
227 weak_factory_.GetWeakPtr(), | 227 weak_factory_.GetWeakPtr(), |
228 receiver_port_id, | 228 receiver_port_id, |
229 channel_name, | 229 channel_name, |
230 base::Passed(&channel), | 230 base::Passed(&channel), |
231 tab_json))); | 231 tab_json))); |
232 } | 232 } |
233 | 233 |
234 void MessageService::FinalizeOpenChannelToNativeApp( | 234 void MessageService::FinalizeOpenChannelToNativeApp( |
235 int receiver_port_id, | 235 int receiver_port_id, |
236 const std::string& channel_name, | 236 const std::string& channel_name, |
237 scoped_ptr<MessageChannel> channel, | 237 scoped_ptr<MessageChannel> channel, |
238 const std::string& tab_json, | 238 const std::string& tab_json, |
239 NativeMessageProcessHost::ScopedHost native_process) { | 239 NativeMessageProcessHost::ScopedHost native_process) { |
240 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 240 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
241 | 241 |
242 // Abandon the channel | 242 // Abandon the channel |
243 if (!native_process.get()) { | 243 if (!native_process.get()) { |
244 LOG(ERROR) << "Failed to create native process."; | 244 LOG(ERROR) << "Failed to create native process."; |
245 channel->opener->DispatchOnDisconnect( | |
246 GET_OPPOSITE_PORT_ID(receiver_port_id), true); | |
245 return; | 247 return; |
246 } | 248 } |
247 channel->receiver.reset(new NativeMessagePort(native_process.release())); | 249 channel->receiver.reset(new NativeMessagePort(native_process.release())); |
248 | 250 |
249 // Keep the opener alive until the channel is closed. | 251 // Keep the opener alive until the channel is closed. |
250 channel->opener->IncrementLazyKeepaliveCount(); | 252 channel->opener->IncrementLazyKeepaliveCount(); |
251 | 253 |
252 AddChannel(channel.release(), receiver_port_id); | 254 AddChannel(channel.release(), receiver_port_id); |
253 } | 255 } |
254 | 256 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 return; | 502 return; |
501 | 503 |
502 params->source = source; | 504 params->source = source; |
503 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 505 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
504 MSG_ROUTING_CONTROL, | 506 MSG_ROUTING_CONTROL, |
505 params->target_extension_id)); | 507 params->target_extension_id)); |
506 OpenChannelImpl(params.Pass()); | 508 OpenChannelImpl(params.Pass()); |
507 } | 509 } |
508 | 510 |
509 } // namespace extensions | 511 } // namespace extensions |
OLD | NEW |