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