OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ | 5 #ifndef REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_ |
6 #define REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ | 6 #define REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
14 #include "chrome/browser/extensions/api/messaging/native_messaging_channel.h" | |
15 | |
Sergey Ulanov
2014/09/15 19:53:39
remove this empty line.
kelvinp
2014/09/16 00:32:51
Done.
| |
14 #include "remoting/host/native_messaging/native_messaging_reader.h" | 16 #include "remoting/host/native_messaging/native_messaging_reader.h" |
15 #include "remoting/host/native_messaging/native_messaging_writer.h" | 17 #include "remoting/host/native_messaging/native_messaging_writer.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class DictionaryValue; | 20 class DictionaryValue; |
19 class Value; | 21 class Value; |
20 } // namespace base | 22 } // namespace base |
21 | 23 |
22 namespace remoting { | 24 namespace remoting { |
23 | 25 |
24 // Implements reading messages and sending responses across the native messaging | 26 // An implementation of |extensions::NativeMessagingChannel| using a pipe. It |
25 // host pipe. | 27 // is used by the |It2MeNativeMessagingHost| and |Me2MeNativeMessagingHost| to |
26 class NativeMessagingChannel : public base::NonThreadSafe { | 28 // communicate with the chrome process. |
29 class PipeMessagingChannel : | |
Sergey Ulanov
2014/09/15 19:53:39
This class can also be used in chrome. We were pre
kelvinp
2014/09/16 00:32:51
Todo statement added.
| |
30 public extensions::NativeMessagingChannel, | |
Sergey Ulanov
2014/09/15 19:53:39
indentation. : should be on this line.
kelvinp
2014/09/16 00:32:51
Done.
| |
31 public base::NonThreadSafe { | |
27 public: | 32 public: |
28 // Used to send a message to the client app. | 33 typedef extensions::NativeMessagingChannel::SendMessageCallback |
29 typedef base::Callback<void(scoped_ptr<base::DictionaryValue> message)> | |
30 SendMessageCallback; | 34 SendMessageCallback; |
31 | 35 |
32 // Constructs an object taking the ownership of |input| and |output|. Closes | 36 // Constructs an object taking the ownership of |input| and |output|. Closes |
33 // |input| and |output| to prevent the caller from using them. | 37 // |input| and |output| to prevent the caller from using them. |
34 NativeMessagingChannel(base::File input, base::File output); | 38 PipeMessagingChannel(base::File input, base::File output); |
35 ~NativeMessagingChannel(); | 39 virtual ~PipeMessagingChannel(); |
36 | 40 |
37 // Starts reading and processing messages. | 41 // extensions::NativeMessagingChannel implementation. |
38 void Start(const SendMessageCallback& received_message, | 42 virtual void Start(const SendMessageCallback& received_message, |
39 const base::Closure& quit_closure); | 43 const base::Closure& quit_closure) OVERRIDE; |
40 | 44 virtual void SendMessage(scoped_ptr<base::DictionaryValue> message) OVERRIDE; |
41 // Sends a message to the client app. | |
42 void SendMessage(scoped_ptr<base::DictionaryValue> message); | |
43 | 45 |
44 private: | 46 private: |
45 // Processes a message received from the client app. | 47 // Processes a message received from the client app. |
46 void ProcessMessage(scoped_ptr<base::Value> message); | 48 void ProcessMessage(scoped_ptr<base::Value> message); |
47 | 49 |
48 // Initiates shutdown and runs |quit_closure| if there are no pending requests | 50 // Initiates shutdown and runs |quit_closure| if there are no pending requests |
49 // left. | 51 // left. |
50 void Shutdown(); | 52 void Shutdown(); |
51 | 53 |
52 base::Closure quit_closure_; | 54 base::Closure quit_closure_; |
53 | 55 |
54 NativeMessagingReader native_messaging_reader_; | 56 NativeMessagingReader native_messaging_reader_; |
55 scoped_ptr<NativeMessagingWriter> native_messaging_writer_; | 57 scoped_ptr<NativeMessagingWriter> native_messaging_writer_; |
56 | 58 |
57 // The callback to invoke when a message is received. | 59 // The callback to invoke when a message is received. |
58 SendMessageCallback received_message_; | 60 SendMessageCallback received_message_; |
59 | 61 |
60 base::WeakPtr<NativeMessagingChannel> weak_ptr_; | 62 base::WeakPtr<PipeMessagingChannel> weak_ptr_; |
61 base::WeakPtrFactory<NativeMessagingChannel> weak_factory_; | 63 base::WeakPtrFactory<PipeMessagingChannel> weak_factory_; |
62 | 64 |
63 DISALLOW_COPY_AND_ASSIGN(NativeMessagingChannel); | 65 DISALLOW_COPY_AND_ASSIGN(PipeMessagingChannel); |
64 }; | 66 }; |
65 | 67 |
66 } // namespace remoting | 68 } // namespace remoting |
67 | 69 |
68 #endif // REMOTING_HOST_NATIVE_MESSAGING_NATIVE_MESSAGING_CHANNEL_H_ | 70 #endif // REMOTING_HOST_NATIVE_MESSAGING_PIPE_MESSAGING_CHANNEL_H_ |
OLD | NEW |