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

Side by Side Diff: remoting/host/security_key/security_key_message_reader.cc

Issue 2962443002: Rename TaskRunner::RunsTasksOnCurrentThread() in //remoting, //android_webview (Closed)
Patch Set: Created 3 years, 6 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
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 #include "remoting/host/security_key/security_key_message_reader.h" 5 #include "remoting/host/security_key/security_key_message_reader.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 14 matching lines...) Expand all
25 weak_factory_(this) { 25 weak_factory_(this) {
26 base::Thread::Options options; 26 base::Thread::Options options;
27 options.message_loop_type = base::MessageLoop::TYPE_IO; 27 options.message_loop_type = base::MessageLoop::TYPE_IO;
28 reader_thread_.StartWithOptions(options); 28 reader_thread_.StartWithOptions(options);
29 29
30 read_task_runner_ = reader_thread_.task_runner(); 30 read_task_runner_ = reader_thread_.task_runner();
31 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 31 main_task_runner_ = base::ThreadTaskRunnerHandle::Get();
32 } 32 }
33 33
34 SecurityKeyMessageReader::~SecurityKeyMessageReader() { 34 SecurityKeyMessageReader::~SecurityKeyMessageReader() {
35 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); 35 DCHECK(main_task_runner_->RunsTasksInCurrentSequence());
36 36
37 // In order to ensure the reader thread is stopped cleanly, we close the 37 // In order to ensure the reader thread is stopped cleanly, we close the
38 // stream it is blocking on and then wait for the thread to exit. 38 // stream it is blocking on and then wait for the thread to exit.
39 read_stream_.Close(); 39 read_stream_.Close();
40 reader_thread_.Stop(); 40 reader_thread_.Stop();
41 } 41 }
42 42
43 void SecurityKeyMessageReader::Start( 43 void SecurityKeyMessageReader::Start(
44 SecurityKeyMessageCallback message_callback, 44 SecurityKeyMessageCallback message_callback,
45 base::Closure error_callback) { 45 base::Closure error_callback) {
46 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); 46 DCHECK(main_task_runner_->RunsTasksInCurrentSequence());
47 47
48 message_callback_ = message_callback; 48 message_callback_ = message_callback;
49 error_callback_ = error_callback; 49 error_callback_ = error_callback;
50 50
51 // base::Unretained is safe since this class owns the thread running this task 51 // base::Unretained is safe since this class owns the thread running this task
52 // which will be destroyed before this instance is. 52 // which will be destroyed before this instance is.
53 read_task_runner_->PostTask(FROM_HERE, 53 read_task_runner_->PostTask(FROM_HERE,
54 base::Bind(&SecurityKeyMessageReader::ReadMessage, 54 base::Bind(&SecurityKeyMessageReader::ReadMessage,
55 base::Unretained(this))); 55 base::Unretained(this)));
56 } 56 }
57 57
58 void SecurityKeyMessageReader::ReadMessage() { 58 void SecurityKeyMessageReader::ReadMessage() {
59 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); 59 DCHECK(read_task_runner_->RunsTasksInCurrentSequence());
60 60
61 while (true) { 61 while (true) {
62 if (!read_stream_.IsValid()) { 62 if (!read_stream_.IsValid()) {
63 LOG(ERROR) << "Cannot read from invalid stream."; 63 LOG(ERROR) << "Cannot read from invalid stream.";
64 NotifyError(); 64 NotifyError();
65 return; 65 return;
66 } 66 }
67 67
68 // Read the message header to retrieve the remaining message length. 68 // Read the message header to retrieve the remaining message length.
69 uint32_t total_message_size_bytes; 69 uint32_t total_message_size_bytes;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 // Notify callback of the new message received. 106 // Notify callback of the new message received.
107 main_task_runner_->PostTask( 107 main_task_runner_->PostTask(
108 FROM_HERE, 108 FROM_HERE,
109 base::Bind(&SecurityKeyMessageReader::InvokeMessageCallback, 109 base::Bind(&SecurityKeyMessageReader::InvokeMessageCallback,
110 weak_factory_.GetWeakPtr(), base::Passed(&message))); 110 weak_factory_.GetWeakPtr(), base::Passed(&message)));
111 } 111 }
112 } 112 }
113 113
114 void SecurityKeyMessageReader::NotifyError() { 114 void SecurityKeyMessageReader::NotifyError() {
115 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); 115 DCHECK(read_task_runner_->RunsTasksInCurrentSequence());
116 116
117 main_task_runner_->PostTask( 117 main_task_runner_->PostTask(
118 FROM_HERE, base::Bind(&SecurityKeyMessageReader::InvokeErrorCallback, 118 FROM_HERE, base::Bind(&SecurityKeyMessageReader::InvokeErrorCallback,
119 weak_factory_.GetWeakPtr())); 119 weak_factory_.GetWeakPtr()));
120 } 120 }
121 121
122 void SecurityKeyMessageReader::InvokeMessageCallback( 122 void SecurityKeyMessageReader::InvokeMessageCallback(
123 std::unique_ptr<SecurityKeyMessage> message) { 123 std::unique_ptr<SecurityKeyMessage> message) {
124 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); 124 DCHECK(main_task_runner_->RunsTasksInCurrentSequence());
125 message_callback_.Run(std::move(message)); 125 message_callback_.Run(std::move(message));
126 } 126 }
127 127
128 void SecurityKeyMessageReader::InvokeErrorCallback() { 128 void SecurityKeyMessageReader::InvokeErrorCallback() {
129 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); 129 DCHECK(main_task_runner_->RunsTasksInCurrentSequence());
130 error_callback_.Run(); 130 error_callback_.Run();
131 } 131 }
132 132
133 } // namespace remoting 133 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698