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 #ifndef REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_ |
| 6 #define REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/files/file.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "extensions/browser/api/messaging/native_messaging_channel.h" |
| 15 #include "remoting/host/native_messaging/native_messaging_reader.h" |
| 16 #include "remoting/host/native_messaging/native_messaging_writer.h" |
| 17 |
| 18 namespace base { |
| 19 class DictionaryValue; |
| 20 class Value; |
| 21 } // namespace base |
| 22 |
| 23 namespace remoting { |
| 24 |
| 25 // An implementation of extensions::NativeMessagingChannel using a pipe. It |
| 26 // is used by the It2MeNativeMessagingHost and Me2MeNativeMessagingHost to |
| 27 // communicate with the chrome process. |
| 28 // TODO(kelvinp): Move this class to the extensions/browser/api/messaging |
| 29 // directory. |
| 30 class PipeMessagingChannel : public extensions::NativeMessagingChannel, |
| 31 public base::NonThreadSafe { |
| 32 public: |
| 33 typedef extensions::NativeMessagingChannel::EventHandler EventHandler; |
| 34 |
| 35 // Constructs an object taking the ownership of |input| and |output|. Closes |
| 36 // |input| and |output| to prevent the caller from using them. |
| 37 PipeMessagingChannel(base::File input, base::File output); |
| 38 virtual ~PipeMessagingChannel(); |
| 39 |
| 40 // extensions::NativeMessagingChannel implementation. |
| 41 virtual void Start(EventHandler* event_handler) OVERRIDE; |
| 42 virtual void SendMessage(scoped_ptr<base::Value> message) OVERRIDE; |
| 43 |
| 44 private: |
| 45 // Processes a message received from the client app. |
| 46 void ProcessMessage(scoped_ptr<base::Value> message); |
| 47 |
| 48 // Initiates shutdown. |
| 49 void Shutdown(); |
| 50 |
| 51 NativeMessagingReader native_messaging_reader_; |
| 52 scoped_ptr<NativeMessagingWriter> native_messaging_writer_; |
| 53 |
| 54 EventHandler* event_handler_; |
| 55 base::WeakPtr<PipeMessagingChannel> weak_ptr_; |
| 56 base::WeakPtrFactory<PipeMessagingChannel> weak_factory_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(PipeMessagingChannel); |
| 59 }; |
| 60 |
| 61 } // namespace remoting |
| 62 |
| 63 #endif // REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_ |
OLD | NEW |