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.
5 #ifndef REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_
6 #define REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_
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"
19 class DictionaryValue
;
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
30 class PipeMessagingChannel
: public extensions::NativeMessagingChannel
,
31 public base::NonThreadSafe
{
33 typedef extensions::NativeMessagingChannel::EventHandler EventHandler
;
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 ~PipeMessagingChannel() override
;
40 // extensions::NativeMessagingChannel implementation.
41 void Start(EventHandler
* event_handler
) override
;
42 void SendMessage(scoped_ptr
<base::Value
> message
) override
;
45 // Processes a message received from the client app.
46 void ProcessMessage(scoped_ptr
<base::Value
> message
);
48 // Initiates shutdown.
51 NativeMessagingReader native_messaging_reader_
;
52 scoped_ptr
<NativeMessagingWriter
> native_messaging_writer_
;
54 EventHandler
* event_handler_
;
55 base::WeakPtr
<PipeMessagingChannel
> weak_ptr_
;
56 base::WeakPtrFactory
<PipeMessagingChannel
> weak_factory_
;
58 DISALLOW_COPY_AND_ASSIGN(PipeMessagingChannel
);
61 } // namespace remoting
63 #endif // REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_