Chromium Code Reviews| Index: chrome/browser/extensions/api/messaging/native_message_port_chromeos.cc |
| diff --git a/chrome/browser/extensions/api/messaging/native_message_port_chromeos.cc b/chrome/browser/extensions/api/messaging/native_message_port_chromeos.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db538bb5cdffc5abd046f1e0c9619f1fd6bcc10d |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/messaging/native_message_port_chromeos.cc |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/messaging/native_message_port.h" |
| + |
| +#include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
| + |
| +namespace extensions { |
| + |
| +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.
|
| + 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() { |
| +} |
| + |
| +void NativeMessagePort::DispatchOnMessage(const Message& message, |
| + int target_port_id) { |
| + native_message_host_->Send(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) { |
| + weak_factory_.InvalidateWeakPtrs(); |
| + if (weak_message_service_) { |
| + weak_message_service_->CloseChannel(port_id_, error_message); |
| + } |
| +} |
| + |
| +} // namespace extensions |
| + |