| Index: chrome/browser/extensions/api/messaging/native_message_port.cc
|
| diff --git a/chrome/browser/extensions/api/messaging/native_message_port.cc b/chrome/browser/extensions/api/messaging/native_message_port.cc
|
| index a0a47d561bbb77cad1e495fcaad3a1a5bb46da41..6e15ecca2ea04cb036f217f15d614c096e39cad1 100644
|
| --- a/chrome/browser/extensions/api/messaging/native_message_port.cc
|
| +++ b/chrome/browser/extensions/api/messaging/native_message_port.cc
|
| @@ -10,22 +10,45 @@
|
|
|
| namespace extensions {
|
|
|
| -NativeMessagePort::NativeMessagePort(NativeMessageProcessHost* native_process)
|
| - : native_process_(native_process) {
|
| +NativeMessagePort::NativeMessagePort(
|
| + base::WeakPtr<MessageService> message_service,
|
| + int port_id,
|
| + scoped_ptr<NativeMessageHost> native_message_host)
|
| + : weak_message_service_(message_service),
|
| + port_id_(port_id),
|
| + native_message_host_(native_message_host.Pass()),
|
| + weak_factory_(this) {
|
| + native_message_host_->set_client(weak_factory_.GetWeakPtr());
|
| }
|
|
|
| NativeMessagePort::~NativeMessagePort() {
|
| content::BrowserThread::DeleteSoon(
|
| - content::BrowserThread::IO, FROM_HERE, native_process_);
|
| + content::BrowserThread::IO, FROM_HERE, native_message_host_.release());
|
| }
|
|
|
| void NativeMessagePort::DispatchOnMessage(
|
| const Message& message,
|
| int target_port_id) {
|
| content::BrowserThread::PostTask(
|
| - content::BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&NativeMessageProcessHost::Send,
|
| - base::Unretained(native_process_), message.data));
|
| + content::BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&NativeMessageHost::Send,
|
| + base::Unretained(native_message_host_.get()),
|
| + message.data));
|
| +}
|
| +
|
| +void NativeMessagePort::PostMessageFromNativeHost(const std::string& message) {
|
| + if (weak_message_service_) {
|
| + weak_message_service_->PostMessage(
|
| + port_id_, Message(message, false /* user_gesture */));
|
| + }
|
| +}
|
| +
|
| +void NativeMessagePort::CloseChannel(const std::string& error_message) {
|
| + if (weak_message_service_) {
|
| + weak_message_service_->CloseChannel(port_id_, error_message);
|
| + }
|
| }
|
|
|
| } // namespace extensions
|
| +
|
|
|