• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/extensions/api/messaging/native_message_port.h"
6 
7 #include "base/bind.h"
8 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
9 #include "content/public/browser/browser_thread.h"
10 
11 namespace extensions {
12 
NativeMessagePort(NativeMessageProcessHost * native_process)13 NativeMessagePort::NativeMessagePort(NativeMessageProcessHost* native_process)
14     : native_process_(native_process) {
15 }
16 
~NativeMessagePort()17 NativeMessagePort::~NativeMessagePort() {
18   content::BrowserThread::DeleteSoon(
19       content::BrowserThread::IO, FROM_HERE, native_process_);
20 }
21 
DispatchOnMessage(const Message & message,int target_port_id)22 void NativeMessagePort::DispatchOnMessage(
23     const Message& message,
24     int target_port_id) {
25   content::BrowserThread::PostTask(
26       content::BrowserThread::IO, FROM_HERE,
27       base::Bind(&NativeMessageProcessHost::Send,
28                  base::Unretained(native_process_), message.data));
29 }
30 
31 }  // namespace extensions
32