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

Side by Side Diff: remoting/protocol/connection_tester.cc

Issue 2104363004: Remove remaining calls to deprecated MessageLoop methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/protocol/connection_tester.h" 5 #include "remoting/protocol/connection_tester.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/threading/thread_task_runner_handle.h"
9 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "remoting/proto/video.pb.h" 12 #include "remoting/proto/video.pb.h"
12 #include "remoting/protocol/message_pipe.h" 13 #include "remoting/protocol/message_pipe.h"
13 #include "remoting/protocol/message_serialization.h" 14 #include "remoting/protocol/message_serialization.h"
14 #include "remoting/protocol/p2p_datagram_socket.h" 15 #include "remoting/protocol/p2p_datagram_socket.h"
15 #include "remoting/protocol/p2p_stream_socket.h" 16 #include "remoting/protocol/p2p_stream_socket.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace remoting { 19 namespace remoting {
19 namespace protocol { 20 namespace protocol {
20 21
21 StreamConnectionTester::StreamConnectionTester(P2PStreamSocket* client_socket, 22 StreamConnectionTester::StreamConnectionTester(P2PStreamSocket* client_socket,
22 P2PStreamSocket* host_socket, 23 P2PStreamSocket* host_socket,
23 int message_size, 24 int message_size,
24 int message_count) 25 int message_count)
25 : message_loop_(base::MessageLoop::current()), 26 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
26 host_socket_(host_socket), 27 host_socket_(host_socket),
27 client_socket_(client_socket), 28 client_socket_(client_socket),
28 message_size_(message_size), 29 message_size_(message_size),
29 test_data_size_(message_size * message_count), 30 test_data_size_(message_size * message_count),
30 done_(false), 31 done_(false),
31 write_errors_(0), 32 write_errors_(0),
32 read_errors_(0) { 33 read_errors_(0) {}
33 }
34 34
35 StreamConnectionTester::~StreamConnectionTester() { 35 StreamConnectionTester::~StreamConnectionTester() {
36 } 36 }
37 37
38 void StreamConnectionTester::Start() { 38 void StreamConnectionTester::Start() {
39 InitBuffers(); 39 InitBuffers();
40 DoRead(); 40 DoRead();
41 DoWrite(); 41 DoWrite();
42 } 42 }
43 43
44 void StreamConnectionTester::CheckResults() { 44 void StreamConnectionTester::CheckResults() {
45 EXPECT_EQ(0, write_errors_); 45 EXPECT_EQ(0, write_errors_);
46 EXPECT_EQ(0, read_errors_); 46 EXPECT_EQ(0, read_errors_);
47 47
48 ASSERT_EQ(test_data_size_, input_buffer_->offset()); 48 ASSERT_EQ(test_data_size_, input_buffer_->offset());
49 49
50 output_buffer_->SetOffset(0); 50 output_buffer_->SetOffset(0);
51 ASSERT_EQ(test_data_size_, output_buffer_->size()); 51 ASSERT_EQ(test_data_size_, output_buffer_->size());
52 52
53 EXPECT_EQ(0, memcmp(output_buffer_->data(), 53 EXPECT_EQ(0, memcmp(output_buffer_->data(),
54 input_buffer_->StartOfBuffer(), test_data_size_)); 54 input_buffer_->StartOfBuffer(), test_data_size_));
55 } 55 }
56 56
57 void StreamConnectionTester::Done() { 57 void StreamConnectionTester::Done() {
58 done_ = true; 58 done_ = true;
59 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 59 task_runner_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
60 } 60 }
61 61
62 void StreamConnectionTester::InitBuffers() { 62 void StreamConnectionTester::InitBuffers() {
63 output_buffer_ = new net::DrainableIOBuffer( 63 output_buffer_ = new net::DrainableIOBuffer(
64 new net::IOBuffer(test_data_size_), test_data_size_); 64 new net::IOBuffer(test_data_size_), test_data_size_);
65 for (int i = 0; i < test_data_size_; ++i) { 65 for (int i = 0; i < test_data_size_; ++i) {
66 output_buffer_->data()[i] = static_cast<char>(i); 66 output_buffer_->data()[i] = static_cast<char>(i);
67 } 67 }
68 68
69 input_buffer_ = new net::GrowableIOBuffer(); 69 input_buffer_ = new net::GrowableIOBuffer();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 Done(); 130 Done();
131 } 131 }
132 } 132 }
133 133
134 DatagramConnectionTester::DatagramConnectionTester( 134 DatagramConnectionTester::DatagramConnectionTester(
135 P2PDatagramSocket* client_socket, 135 P2PDatagramSocket* client_socket,
136 P2PDatagramSocket* host_socket, 136 P2PDatagramSocket* host_socket,
137 int message_size, 137 int message_size,
138 int message_count, 138 int message_count,
139 int delay_ms) 139 int delay_ms)
140 : message_loop_(base::MessageLoop::current()), 140 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
141 host_socket_(host_socket), 141 host_socket_(host_socket),
142 client_socket_(client_socket), 142 client_socket_(client_socket),
143 message_size_(message_size), 143 message_size_(message_size),
144 message_count_(message_count), 144 message_count_(message_count),
145 delay_ms_(delay_ms), 145 delay_ms_(delay_ms),
146 done_(false), 146 done_(false),
147 write_errors_(0), 147 write_errors_(0),
148 read_errors_(0), 148 read_errors_(0),
149 packets_sent_(0), 149 packets_sent_(0),
150 packets_received_(0), 150 packets_received_(0),
(...skipping 16 matching lines...) Expand all
167 EXPECT_EQ(0, bad_packets_received_); 167 EXPECT_EQ(0, bad_packets_received_);
168 168
169 // Verify that we've received at least one packet. 169 // Verify that we've received at least one packet.
170 EXPECT_GT(packets_received_, 0); 170 EXPECT_GT(packets_received_, 0);
171 VLOG(0) << "Received " << packets_received_ << " packets out of " 171 VLOG(0) << "Received " << packets_received_ << " packets out of "
172 << message_count_; 172 << message_count_;
173 } 173 }
174 174
175 void DatagramConnectionTester::Done() { 175 void DatagramConnectionTester::Done() {
176 done_ = true; 176 done_ = true;
177 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 177 task_runner_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
178 } 178 }
179 179
180 void DatagramConnectionTester::DoWrite() { 180 void DatagramConnectionTester::DoWrite() {
181 if (packets_sent_ >= message_count_) { 181 if (packets_sent_ >= message_count_) {
182 Done(); 182 Done();
183 return; 183 return;
184 } 184 }
185 185
186 scoped_refptr<net::IOBuffer> packet(new net::IOBuffer(message_size_)); 186 scoped_refptr<net::IOBuffer> packet(new net::IOBuffer(message_size_));
187 for (int i = 0; i < message_size_; ++i) { 187 for (int i = 0; i < message_size_; ++i) {
(...skipping 14 matching lines...) Expand all
202 } 202 }
203 203
204 void DatagramConnectionTester::HandleWriteResult(int result) { 204 void DatagramConnectionTester::HandleWriteResult(int result) {
205 if (result <= 0 && result != net::ERR_IO_PENDING) { 205 if (result <= 0 && result != net::ERR_IO_PENDING) {
206 LOG(ERROR) << "Received error " << result << " when trying to write"; 206 LOG(ERROR) << "Received error " << result << " when trying to write";
207 write_errors_++; 207 write_errors_++;
208 Done(); 208 Done();
209 } else if (result > 0) { 209 } else if (result > 0) {
210 EXPECT_EQ(message_size_, result); 210 EXPECT_EQ(message_size_, result);
211 packets_sent_++; 211 packets_sent_++;
212 message_loop_->PostDelayedTask( 212 task_runner_->PostDelayedTask(
213 FROM_HERE, 213 FROM_HERE,
214 base::Bind(&DatagramConnectionTester::DoWrite, base::Unretained(this)), 214 base::Bind(&DatagramConnectionTester::DoWrite, base::Unretained(this)),
215 base::TimeDelta::FromMilliseconds(delay_ms_)); 215 base::TimeDelta::FromMilliseconds(delay_ms_));
216 } 216 }
217 } 217 }
218 218
219 void DatagramConnectionTester::DoRead() { 219 void DatagramConnectionTester::DoRead() {
220 int result = 1; 220 int result = 1;
221 while (result > 0) { 221 while (result > 0) {
222 int kReadSize = message_size_ * 2; 222 int kReadSize = message_size_ * 2;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 void MessagePipeConnectionTester::OnMessageReceived( 296 void MessagePipeConnectionTester::OnMessageReceived(
297 std::unique_ptr<CompoundBuffer> message) { 297 std::unique_ptr<CompoundBuffer> message) {
298 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); 298 received_messages_.push_back(ParseMessage<VideoPacket>(message.get()));
299 if (received_messages_.size() >= sent_messages_.size()) { 299 if (received_messages_.size() >= sent_messages_.size()) {
300 run_loop_.Quit(); 300 run_loop_.Quit();
301 } 301 }
302 } 302 }
303 303
304 } // namespace protocol 304 } // namespace protocol
305 } // namespace remoting 305 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_tester.h ('k') | remoting/protocol/monitored_video_stub_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698