OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_READER_IMPL_H_ | 5 #ifndef REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_READER_IMPL_H_ |
6 #define REMOTING_HOST_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_READER_IMPL_H_ | 6 #define REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_READER_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "remoting/host/security_key/remote_security_key_message_reader.h" | |
16 #include "remoting/host/security_key/security_key_message.h" | 15 #include "remoting/host/security_key/security_key_message.h" |
| 16 #include "remoting/host/security_key/security_key_message_reader.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
20 } // namespace base | 20 } // namespace base |
21 | 21 |
22 namespace remoting { | 22 namespace remoting { |
23 | 23 |
24 // RemoteSecurityKeyMessageReader implementation that receives messages from | 24 // SecurityKeyMessageReader implementation that receives messages from |
25 // a pipe. | 25 // a pipe. |
26 class RemoteSecurityKeyMessageReaderImpl | 26 class SecurityKeyMessageReaderImpl : public SecurityKeyMessageReader { |
27 : public RemoteSecurityKeyMessageReader { | |
28 public: | 27 public: |
29 explicit RemoteSecurityKeyMessageReaderImpl(base::File input_file); | 28 explicit SecurityKeyMessageReaderImpl(base::File input_file); |
30 ~RemoteSecurityKeyMessageReaderImpl() override; | 29 ~SecurityKeyMessageReaderImpl() override; |
31 | 30 |
32 // RemoteSecurityKeyMessageReader interface. | 31 // SecurityKeyMessageReader interface. |
33 void Start(const SecurityKeyMessageCallback& message_callback, | 32 void Start(const SecurityKeyMessageCallback& message_callback, |
34 const base::Closure& error_callback) override; | 33 const base::Closure& error_callback) override; |
35 | 34 |
36 private: | 35 private: |
37 // Reads a message from the remote security key process and passes it to | 36 // Reads a message from the remote_security_key process and passes it to |
38 // |message_callback_| on the originating thread. Run on |read_task_runner_|. | 37 // |message_callback_| on the originating thread. Run on |read_task_runner_|. |
39 void ReadMessage(); | 38 void ReadMessage(); |
40 | 39 |
41 // Reads the nubmer of bytes indicated by |bytes_to_read| into |buffer| from | 40 // Reads the nubmer of bytes indicated by |bytes_to_read| into |buffer| from |
42 // |read_stream_|. Returns true if all bytes were retrieved successfully. | 41 // |read_stream_|. Returns true if all bytes were retrieved successfully. |
43 bool ReadFromStream(char* buffer, size_t bytes_to_read); | 42 bool ReadFromStream(char* buffer, size_t bytes_to_read); |
44 | 43 |
45 // Callback run on |read_task_runner_| when an error occurs or EOF is reached. | 44 // Callback run on |read_task_runner_| when an error occurs or EOF is reached. |
46 void NotifyError(); | 45 void NotifyError(); |
47 | 46 |
48 // Used for callbacks on the appropriate task runner to signal status changes. | 47 // Used for callbacks on the appropriate task runner to signal status changes. |
49 // These callbacks are invoked on |main_task_runner_|. | 48 // These callbacks are invoked on |main_task_runner_|. |
50 void InvokeMessageCallback(std::unique_ptr<SecurityKeyMessage> message); | 49 void InvokeMessageCallback(std::unique_ptr<SecurityKeyMessage> message); |
51 void InvokeErrorCallback(); | 50 void InvokeErrorCallback(); |
52 | 51 |
53 base::File read_stream_; | 52 base::File read_stream_; |
54 | 53 |
55 // Caller-supplied message and error callbacks. | 54 // Caller-supplied message and error callbacks. |
56 SecurityKeyMessageCallback message_callback_; | 55 SecurityKeyMessageCallback message_callback_; |
57 base::Closure error_callback_; | 56 base::Closure error_callback_; |
58 | 57 |
59 // Thread used for blocking IO operations. | 58 // Thread used for blocking IO operations. |
60 base::Thread reader_thread_; | 59 base::Thread reader_thread_; |
61 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 60 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
62 scoped_refptr<base::SingleThreadTaskRunner> read_task_runner_; | 61 scoped_refptr<base::SingleThreadTaskRunner> read_task_runner_; |
63 | 62 |
64 base::WeakPtr<RemoteSecurityKeyMessageReaderImpl> reader_; | 63 base::WeakPtr<SecurityKeyMessageReaderImpl> reader_; |
65 base::WeakPtrFactory<RemoteSecurityKeyMessageReaderImpl> weak_factory_; | 64 base::WeakPtrFactory<SecurityKeyMessageReaderImpl> weak_factory_; |
66 | 65 |
67 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageReaderImpl); | 66 DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessageReaderImpl); |
68 }; | 67 }; |
69 | 68 |
70 } // namespace remoting | 69 } // namespace remoting |
71 | 70 |
72 #endif // REMOTING_HOST_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_READER_IMPL_H_ | 71 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_READER_IMPL_H_ |
OLD | NEW |