Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 "chrome/browser/extensions/api/messaging/native_message_process_host.h" | |
| 8 | |
| 9 namespace extensions { | |
| 10 | |
| 11 NativeMessagePort::NativeMessagePort( | |
|
Sergey Ulanov
2014/09/27 00:24:10
Why do we need chrome-os specific version of this
kelvinp
2014/09/29 22:59:40
Done.
| |
| 12 base::WeakPtr<MessageService> message_service, | |
| 13 int port_id, | |
| 14 scoped_ptr<NativeMessageHost> native_message_host) | |
| 15 : weak_message_service_(message_service), | |
| 16 port_id_(port_id), | |
| 17 native_message_host_(native_message_host.Pass()), | |
| 18 weak_factory_(this) { | |
| 19 native_message_host_->set_client(weak_factory_.GetWeakPtr()); | |
| 20 } | |
| 21 | |
| 22 NativeMessagePort::~NativeMessagePort() { | |
| 23 } | |
| 24 | |
| 25 void NativeMessagePort::DispatchOnMessage(const Message& message, | |
| 26 int target_port_id) { | |
| 27 native_message_host_->Send(message.data); | |
| 28 } | |
| 29 | |
| 30 void NativeMessagePort::PostMessageFromNativeHost(const std::string& message) { | |
| 31 if (weak_message_service_) { | |
| 32 weak_message_service_->PostMessage( | |
| 33 port_id_, Message(message, false /* user_gesture */)); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void NativeMessagePort::CloseChannel(const std::string& error_message) { | |
| 38 weak_factory_.InvalidateWeakPtrs(); | |
| 39 if (weak_message_service_) { | |
| 40 weak_message_service_->CloseChannel(port_id_, error_message); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 } // namespace extensions | |
| 45 | |
| OLD | NEW |