| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ |
| 6 #define EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ | 6 #define EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 | 11 |
| 11 namespace base { | 12 namespace base { |
| 12 class Value; | 13 class Value; |
| 13 } // namespace base | 14 } // namespace base |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 // An interface to receive and send messages between a native component and | 18 // An interface to receive and send messages between a native component and |
| 18 // chrome. | 19 // chrome. |
| 19 class NativeMessagingChannel { | 20 class NativeMessagingChannel { |
| 20 public: | 21 public: |
| 21 // Callback interface for the channel. EventHandler must outlive | 22 // Callback interface for the channel. EventHandler must outlive |
| 22 // NativeMessagingChannel. | 23 // NativeMessagingChannel. |
| 23 class EventHandler { | 24 class EventHandler { |
| 24 public: | 25 public: |
| 25 // Called when a message is received from the other endpoint. | 26 // Called when a message is received from the other endpoint. |
| 26 virtual void OnMessage(scoped_ptr<base::Value> message) = 0; | 27 virtual void OnMessage(std::unique_ptr<base::Value> message) = 0; |
| 27 | 28 |
| 28 // Called when the channel is disconnected. | 29 // Called when the channel is disconnected. |
| 29 // EventHandler is guaranteed not to be called after OnDisconnect(). | 30 // EventHandler is guaranteed not to be called after OnDisconnect(). |
| 30 virtual void OnDisconnect() = 0; | 31 virtual void OnDisconnect() = 0; |
| 31 | 32 |
| 32 virtual ~EventHandler() {} | 33 virtual ~EventHandler() {} |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 virtual ~NativeMessagingChannel() {} | 36 virtual ~NativeMessagingChannel() {} |
| 36 | 37 |
| 37 // Starts reading and processing messages. | 38 // Starts reading and processing messages. |
| 38 virtual void Start(EventHandler* event_handler) = 0; | 39 virtual void Start(EventHandler* event_handler) = 0; |
| 39 | 40 |
| 40 // Sends a message to the other endpoint. | 41 // Sends a message to the other endpoint. |
| 41 virtual void SendMessage(scoped_ptr<base::Value> message) = 0; | 42 virtual void SendMessage(std::unique_ptr<base::Value> message) = 0; |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 } // namespace extensions | 45 } // namespace extensions |
| 45 | 46 |
| 46 #endif // EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ | 47 #endif // EXTENSIONS_BROWSER_API_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ |
| OLD | NEW |