| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PORT_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PORT_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PORT_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PORT_H_ |
| 7 | 7 |
| 8 #include "base/threading/thread_checker.h" | 8 #include "base/threading/thread_checker.h" |
| 9 #include "chrome/browser/extensions/api/messaging/message_service.h" | 9 #include "chrome/browser/extensions/api/messaging/message_service.h" |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 class NativeMessageProcessHost; | 12 class NativeMessageProcessHost; |
| 13 | 13 |
| 14 // A port that manages communication with a native application. | 14 // A port that manages communication with a native application. |
| 15 // All methods must be called on the UI Thread of the browser process. | 15 // All methods must be called on the UI Thread of the browser process. |
| 16 class NativeMessagePort : public MessageService::MessagePort { | 16 class NativeMessagePort : public MessageService::MessagePort { |
| 17 public: | 17 public: |
| 18 NativeMessagePort(base::WeakPtr<MessageService> message_service, | 18 NativeMessagePort(base::WeakPtr<MessageService> message_service, |
| 19 int port_id, | 19 int port_id, |
| 20 scoped_ptr<NativeMessageHost> native_message_host); | 20 scoped_ptr<NativeMessageHost> native_message_host); |
| 21 ~NativeMessagePort() override; | 21 ~NativeMessagePort() override; |
| 22 | 22 |
| 23 // MessageService::MessagePort implementation. | 23 // MessageService::MessagePort implementation. |
| 24 void DispatchOnMessage(const Message& message, int target_port_id) override; | 24 bool IsValidPort() override; |
| 25 void DispatchOnMessage(const Message& message) override; |
| 25 | 26 |
| 26 private: | 27 private: |
| 27 class Core; | 28 class Core; |
| 28 void PostMessageFromNativeHost(const std::string& message); | 29 void PostMessageFromNativeHost(const std::string& message); |
| 29 void CloseChannel(const std::string& error_message); | 30 void CloseChannel(const std::string& error_message); |
| 30 | 31 |
| 31 base::ThreadChecker thread_checker_; | 32 base::ThreadChecker thread_checker_; |
| 32 base::WeakPtr<MessageService> weak_message_service_; | 33 base::WeakPtr<MessageService> weak_message_service_; |
| 33 scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_; | 34 scoped_refptr<base::SingleThreadTaskRunner> host_task_runner_; |
| 34 int port_id_; | 35 int port_id_; |
| 35 scoped_ptr<Core> core_; | 36 scoped_ptr<Core> core_; |
| 36 | 37 |
| 37 base::WeakPtrFactory<NativeMessagePort> weak_factory_; | 38 base::WeakPtrFactory<NativeMessagePort> weak_factory_; |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 } // namespace extensions | 41 } // namespace extensions |
| 41 | 42 |
| 42 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PORT_H_ | 43 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PORT_H_ |
| OLD | NEW |