Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/fake_session.h" | 5 #include "remoting/protocol/fake_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace remoting { | 15 namespace remoting { |
| 16 namespace protocol { | 16 namespace protocol { |
| 17 | 17 |
| 18 const char kTestJid[] = "host1@gmail.com/chromoting123"; | 18 const char kTestJid[] = "host1@gmail.com/chromoting123"; |
| 19 | 19 |
| 20 FakeSocket::FakeSocket() | 20 FakeSocket::FakeSocket() |
| 21 : next_read_error_(net::OK), | 21 : async_write_(false), |
|
simonmorris
2012/07/31 20:19:50
Initialize write_pending_.
Sergey Ulanov
2012/07/31 21:37:53
Done.
| |
| 22 write_limit_(0), | |
| 23 next_write_error_(net::OK), | |
| 24 next_read_error_(net::OK), | |
| 22 read_pending_(false), | 25 read_pending_(false), |
| 23 read_buffer_size_(0), | 26 read_buffer_size_(0), |
| 24 input_pos_(0), | 27 input_pos_(0), |
| 25 message_loop_(MessageLoop::current()), | 28 message_loop_(MessageLoop::current()), |
| 26 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 27 } | 30 } |
| 28 | 31 |
| 29 FakeSocket::~FakeSocket() { | 32 FakeSocket::~FakeSocket() { |
| 30 EXPECT_EQ(message_loop_, MessageLoop::current()); | 33 EXPECT_EQ(message_loop_, MessageLoop::current()); |
| 31 } | 34 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 read_buffer_ = buf; | 77 read_buffer_ = buf; |
| 75 read_buffer_size_ = buf_len; | 78 read_buffer_size_ = buf_len; |
| 76 read_callback_ = callback; | 79 read_callback_ = callback; |
| 77 return net::ERR_IO_PENDING; | 80 return net::ERR_IO_PENDING; |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 int FakeSocket::Write(net::IOBuffer* buf, int buf_len, | 84 int FakeSocket::Write(net::IOBuffer* buf, int buf_len, |
| 82 const net::CompletionCallback& callback) { | 85 const net::CompletionCallback& callback) { |
| 83 EXPECT_EQ(message_loop_, MessageLoop::current()); | 86 EXPECT_EQ(message_loop_, MessageLoop::current()); |
| 87 EXPECT_FALSE(write_pending_); | |
| 88 | |
| 89 if (next_write_error_ != net::OK) { | |
| 90 int r = next_write_error_; | |
| 91 next_write_error_ = net::OK; | |
| 92 return r; | |
| 93 } | |
|
simonmorris
2012/07/31 20:19:50
Is next_write_error_ used anywhere else?
Sergey Ulanov
2012/07/31 21:37:53
It's set in set_next_write_error() and used only h
| |
| 94 | |
| 95 if (write_limit_ > 0) | |
| 96 buf_len = std::min(write_limit_, buf_len); | |
| 97 | |
| 98 if (async_write_) { | |
| 99 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 100 &FakeSocket::DoAsyncWrite, weak_factory_.GetWeakPtr(), | |
| 101 scoped_refptr<net::IOBuffer>(buf), buf_len, callback)); | |
| 102 write_pending_ = true; | |
| 103 return net::ERR_IO_PENDING; | |
| 104 } else { | |
| 105 DoWrite(buf, buf_len); | |
| 106 return buf_len; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, int buf_len, | |
| 111 const net::CompletionCallback& callback) { | |
| 112 write_pending_ = false; | |
| 113 DoWrite(buf, buf_len); | |
| 114 callback.Run(buf_len); | |
| 115 } | |
| 116 | |
| 117 void FakeSocket::DoWrite(net::IOBuffer* buf, int buf_len) { | |
| 84 written_data_.insert(written_data_.end(), | 118 written_data_.insert(written_data_.end(), |
| 85 buf->data(), buf->data() + buf_len); | 119 buf->data(), buf->data() + buf_len); |
| 86 | 120 |
| 87 if (peer_socket_) { | 121 if (peer_socket_) { |
| 88 message_loop_->PostTask(FROM_HERE, base::Bind( | 122 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 89 &FakeSocket::AppendInputData, peer_socket_, | 123 &FakeSocket::AppendInputData, peer_socket_, |
| 90 std::vector<char>(buf->data(), buf->data() + buf_len))); | 124 std::vector<char>(buf->data(), buf->data() + buf_len))); |
| 91 } | 125 } |
| 92 | |
| 93 return buf_len; | |
| 94 } | 126 } |
| 95 | 127 |
| 96 bool FakeSocket::SetReceiveBufferSize(int32 size) { | 128 bool FakeSocket::SetReceiveBufferSize(int32 size) { |
| 97 NOTIMPLEMENTED(); | 129 NOTIMPLEMENTED(); |
| 98 return false; | 130 return false; |
| 99 } | 131 } |
| 100 bool FakeSocket::SetSendBufferSize(int32 size) { | 132 bool FakeSocket::SetSendBufferSize(int32 size) { |
| 101 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
| 102 return false; | 134 return false; |
| 103 } | 135 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 void FakeSession::set_config(const SessionConfig& config) { | 331 void FakeSession::set_config(const SessionConfig& config) { |
| 300 config_ = config; | 332 config_ = config; |
| 301 } | 333 } |
| 302 | 334 |
| 303 void FakeSession::Close() { | 335 void FakeSession::Close() { |
| 304 closed_ = true; | 336 closed_ = true; |
| 305 } | 337 } |
| 306 | 338 |
| 307 } // namespace protocol | 339 } // namespace protocol |
| 308 } // namespace remoting | 340 } // namespace remoting |
| OLD | NEW |