Index: remoting/protocol/fake_authenticator.cc |
diff --git a/remoting/protocol/fake_authenticator.cc b/remoting/protocol/fake_authenticator.cc |
index bf06c56c6a8b61b0a7389d1424b46a793b4100d4..9f2b4f6f08a2afa3982be5dfeb845fac8ad83559 100644 |
--- a/remoting/protocol/fake_authenticator.cc |
+++ b/remoting/protocol/fake_authenticator.cc |
@@ -7,6 +7,7 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/strings/string_number_conversions.h" |
#include "net/base/io_buffer.h" |
+#include "net/base/net_errors.h" |
#include "net/socket/stream_socket.h" |
#include "remoting/base/constants.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -34,31 +35,33 @@ void FakeChannelAuthenticator::SecureAndAuthenticate( |
if (async_) { |
done_callback_ = done_callback; |
- scoped_refptr<net::IOBuffer> write_buf = new net::IOBuffer(1); |
- write_buf->data()[0] = 0; |
- int result = |
- socket_->Write(write_buf.get(), |
- 1, |
- base::Bind(&FakeChannelAuthenticator::OnAuthBytesWritten, |
- weak_factory_.GetWeakPtr())); |
- if (result != net::ERR_IO_PENDING) { |
- // This will not call the callback because |did_read_bytes_| is |
- // still set to false. |
- OnAuthBytesWritten(result); |
+ if (result_ != net::OK) { |
+ // Don't write anything if we are going to reject auth to make test |
+ // ordering deterministic. |
+ did_write_bytes_ = true; |
+ } else { |
+ scoped_refptr<net::IOBuffer> write_buf = new net::IOBuffer(1); |
+ write_buf->data()[0] = 0; |
+ int result = socket_->Write( |
+ write_buf.get(), 1, |
+ base::Bind(&FakeChannelAuthenticator::OnAuthBytesWritten, |
+ weak_factory_.GetWeakPtr())); |
+ if (result != net::ERR_IO_PENDING) { |
+ // This will not call the callback because |did_read_bytes_| is |
+ // still set to false. |
+ OnAuthBytesWritten(result); |
+ } |
} |
scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(1); |
- result = |
- socket_->Read(read_buf.get(), |
- 1, |
+ int result = |
+ socket_->Read(read_buf.get(), 1, |
base::Bind(&FakeChannelAuthenticator::OnAuthBytesRead, |
weak_factory_.GetWeakPtr())); |
if (result != net::ERR_IO_PENDING) |
OnAuthBytesRead(result); |
} else { |
- if (result_ != net::OK) |
- socket_.reset(); |
- done_callback.Run(result_, socket_.Pass()); |
+ CallDoneCallback(); |
} |
} |
@@ -67,7 +70,7 @@ void FakeChannelAuthenticator::OnAuthBytesWritten(int result) { |
EXPECT_FALSE(did_write_bytes_); |
did_write_bytes_ = true; |
if (did_read_bytes_) |
- done_callback_.Run(result_, socket_.Pass()); |
+ CallDoneCallback(); |
} |
void FakeChannelAuthenticator::OnAuthBytesRead(int result) { |
@@ -75,7 +78,15 @@ void FakeChannelAuthenticator::OnAuthBytesRead(int result) { |
EXPECT_FALSE(did_read_bytes_); |
did_read_bytes_ = true; |
if (did_write_bytes_) |
- done_callback_.Run(result_, socket_.Pass()); |
+ CallDoneCallback(); |
+} |
+ |
+void FakeChannelAuthenticator::CallDoneCallback() { |
+ DoneCallback callback = done_callback_; |
+ done_callback_.Reset(); |
+ if (result_ != net::OK) |
+ socket_.reset(); |
+ callback.Run(result_, socket_.Pass()); |
} |
FakeAuthenticator::FakeAuthenticator( |