Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: remoting/host/security_key/remote_security_key_message_reader.h

Issue 1818233005: Adding the message reading class used for remote_security_key STDIN communication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@writer
Patch Set: Addressing feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_H_
6 #define REMOTING_HOST_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_READER_H_
7
8 #include "base/callback.h"
9 #include "base/files/file.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread.h"
14 #include "remoting/host/security_key/security_key_message.h"
15
16 namespace base {
17 class SingleThreadTaskRunner;
18 } // namespace base
19
20 namespace remoting {
21
22 // Used for receiving remote security key messages using a file handle.
23 class RemoteSecurityKeyMessageReader {
24 public:
25 explicit RemoteSecurityKeyMessageReader(base::File input_file);
26 ~RemoteSecurityKeyMessageReader();
27
28 // Starts reading messages from the input file provided in the C'Tor.
29 // |message_callback| is called for each received message.
30 // |error_callback| is called in case of an error or the file is closed.
31 // This method is asynchronous, callbacks will be called on the thread this
32 // method is called on. These callbacks can be called up to the point this
33 // instance is destroyed and may be destroyed as a result of the callback
34 // being invoked.
35 void Start(SecurityKeyMessageCallback message_callback,
36 base::Closure error_callback);
37
38 private:
39 // Reads a message from the remote security key process and passes it to
40 // |message_callback_| on the originating thread. Run on |read_task_runner_|.
41 void ReadMessage();
42
43 // Callback run on |read_task_runner_| when an error occurs or EOF is reached.
44 void NotifyError();
45
46 // Used for callbacks on the appropriate task runner to signal status changes.
47 // These callbacks are invoked on |main_task_runner_|.
48 void InvokeMessageCallback(scoped_ptr<SecurityKeyMessage> message);
49 void InvokeErrorCallback();
50
51 base::File read_stream_;
52
53 // Caller-supplied message and error callbacks.
54 SecurityKeyMessageCallback message_callback_;
55 base::Closure error_callback_;
56
57 // Thread used for blocking IO operations.
58 base::Thread reader_thread_;
59 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
60 scoped_refptr<base::SingleThreadTaskRunner> read_task_runner_;
61
62 base::WeakPtr<RemoteSecurityKeyMessageReader> reader_;
63 base::WeakPtrFactory<RemoteSecurityKeyMessageReader> weak_factory_;
64
65 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageReader);
66 };
67
68 } // namespace remoting
69
70 #endif // REMOTING_HOST_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_READER_H_
OLDNEW
« no previous file with comments | « remoting/host/BUILD.gn ('k') | remoting/host/security_key/remote_security_key_message_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698