Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 10918255: The Windows portion of Native Messagaing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
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
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
OLDNEW
« no previous file with comments | « base/process_util_win.cc ('k') | chrome/browser/extensions/api/messaging/native_message_port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698