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

Side by Side Diff: remoting/host/native_messaging/native_messaging_reader.cc

Issue 2962443002: Rename TaskRunner::RunsTasksOnCurrentThread() in //remoting, //android_webview (Closed)
Patch Set: Created 3 years, 5 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 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 #include "remoting/host/native_messaging/native_messaging_reader.h" 5 #include "remoting/host/native_messaging/native_messaging_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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 base::WeakPtr<NativeMessagingReader> reader) 81 base::WeakPtr<NativeMessagingReader> reader)
82 : read_stream_(std::move(file)), 82 : read_stream_(std::move(file)),
83 reader_(reader), 83 reader_(reader),
84 caller_task_runner_(caller_task_runner), 84 caller_task_runner_(caller_task_runner),
85 read_task_runner_(read_task_runner) { 85 read_task_runner_(read_task_runner) {
86 } 86 }
87 87
88 NativeMessagingReader::Core::~Core() {} 88 NativeMessagingReader::Core::~Core() {}
89 89
90 void NativeMessagingReader::Core::ReadMessage() { 90 void NativeMessagingReader::Core::ReadMessage() {
91 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); 91 DCHECK(read_task_runner_->RunsTasksInCurrentSequence());
92 92
93 // Keep reading messages until the stream is closed or an error occurs. 93 // Keep reading messages until the stream is closed or an error occurs.
94 while (true) { 94 while (true) {
95 MessageLengthType message_length; 95 MessageLengthType message_length;
96 int read_result = read_stream_.ReadAtCurrentPos( 96 int read_result = read_stream_.ReadAtCurrentPos(
97 reinterpret_cast<char*>(&message_length), kMessageHeaderSize); 97 reinterpret_cast<char*>(&message_length), kMessageHeaderSize);
98 if (read_result != kMessageHeaderSize) { 98 if (read_result != kMessageHeaderSize) {
99 // 0 means EOF which is normal and should not be logged as an error. 99 // 0 means EOF which is normal and should not be logged as an error.
100 if (read_result != 0) { 100 if (read_result != 0) {
101 LOG(ERROR) << "Failed to read message header, read returned " 101 LOG(ERROR) << "Failed to read message header, read returned "
(...skipping 27 matching lines...) Expand all
129 } 129 }
130 130
131 // Notify callback of new message. 131 // Notify callback of new message.
132 caller_task_runner_->PostTask( 132 caller_task_runner_->PostTask(
133 FROM_HERE, base::Bind(&NativeMessagingReader::InvokeMessageCallback, 133 FROM_HERE, base::Bind(&NativeMessagingReader::InvokeMessageCallback,
134 reader_, base::Passed(&message))); 134 reader_, base::Passed(&message)));
135 } 135 }
136 } 136 }
137 137
138 void NativeMessagingReader::Core::NotifyEof() { 138 void NativeMessagingReader::Core::NotifyEof() {
139 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); 139 DCHECK(read_task_runner_->RunsTasksInCurrentSequence());
140 caller_task_runner_->PostTask( 140 caller_task_runner_->PostTask(
141 FROM_HERE, 141 FROM_HERE,
142 base::Bind(&NativeMessagingReader::InvokeEofCallback, reader_)); 142 base::Bind(&NativeMessagingReader::InvokeEofCallback, reader_));
143 } 143 }
144 144
145 NativeMessagingReader::NativeMessagingReader(base::File file) 145 NativeMessagingReader::NativeMessagingReader(base::File file)
146 : reader_thread_("Reader"), 146 : reader_thread_("Reader"),
147 weak_factory_(this) { 147 weak_factory_(this) {
148 reader_thread_.StartWithOptions( 148 reader_thread_.StartWithOptions(
149 base::Thread::Options(base::MessageLoop::TYPE_IO, /*size=*/0)); 149 base::Thread::Options(base::MessageLoop::TYPE_IO, /*size=*/0));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void NativeMessagingReader::InvokeMessageCallback( 195 void NativeMessagingReader::InvokeMessageCallback(
196 std::unique_ptr<base::Value> message) { 196 std::unique_ptr<base::Value> message) {
197 message_callback_.Run(std::move(message)); 197 message_callback_.Run(std::move(message));
198 } 198 }
199 199
200 void NativeMessagingReader::InvokeEofCallback() { 200 void NativeMessagingReader::InvokeEofCallback() {
201 eof_callback_.Run(); 201 eof_callback_.Run();
202 } 202 }
203 203
204 } // namespace remoting 204 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_unittest.cc ('k') | remoting/host/security_key/security_key_message_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698