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

Unified Diff: remoting/protocol/fake_authenticator.cc

Issue 9433027: Delete Session and SessionManager object synchronously. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add tests Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/fake_authenticator.cc
diff --git a/remoting/protocol/fake_authenticator.cc b/remoting/protocol/fake_authenticator.cc
index 1790464b78c9ab9c005d9d0b9004d699f0c60a0b..acaadd7091a0d8ef43673bfc18db3ebbcda54b55 100644
--- a/remoting/protocol/fake_authenticator.cc
+++ b/remoting/protocol/fake_authenticator.cc
@@ -6,6 +6,7 @@
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
+#include "net/base/io_buffer.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,6 +18,9 @@ namespace protocol {
FakeChannelAuthenticator::FakeChannelAuthenticator(bool accept, bool async)
: accept_(accept),
async_(async),
+ error_(net::OK),
+ read_(false),
+ written_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
@@ -26,29 +30,52 @@ FakeChannelAuthenticator::~FakeChannelAuthenticator() {
void FakeChannelAuthenticator::SecureAndAuthenticate(
scoped_ptr<net::StreamSocket> socket,
const DoneCallback& done_callback) {
- net::Error error;
+ socket_ = socket.Pass();
if (accept_) {
- error = net::OK;
+ error_ = net::OK;
} else {
- error = net::ERR_FAILED;
- socket.reset();
+ error_ = net::ERR_FAILED;
Wez 2012/02/22 22:51:38 nit: Now that |error_| is a member, you could rena
Sergey Ulanov 2012/02/22 23:36:32 Done.
}
if (async_) {
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- &FakeChannelAuthenticator::CallCallback, weak_factory_.GetWeakPtr(),
- done_callback, error, base::Passed(&socket)));
+ 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, 1, base::Bind(&FakeChannelAuthenticator::OnAuthBytesWritten,
+ base::Unretained(this)));
Wez 2012/02/22 22:51:38 Why not continue to use |weak_factory_| here?
Sergey Ulanov 2012/02/22 23:36:32 It is not necessary because socket_ will be delete
Wez 2012/02/23 19:33:42 The old code was using a |weak_factory_| member, s
Sergey Ulanov 2012/02/23 22:10:06 You are right, changed it to use weak_factory_
+ if (result != net::ERR_IO_PENDING)
+ OnAuthBytesWritten(result);
Wez 2012/02/22 22:51:38 nit: At this point |read_| is never true, so we ca
Sergey Ulanov 2012/02/22 23:36:32 Added comment.
+
+ scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(1);
+ result = socket_->Read(
+ read_buf, 1, base::Bind(&FakeChannelAuthenticator::OnAuthBytesRead,
+ base::Unretained(this)));
+ if (result != net::ERR_IO_PENDING)
+ OnAuthBytesRead(result);
} else {
- done_callback.Run(error, socket.Pass());
+ if (error_ != net::OK)
+ socket_.reset();
+ done_callback.Run(error_, socket_.Pass());
}
}
-void FakeChannelAuthenticator::CallCallback(
- const DoneCallback& done_callback,
- net::Error error,
- scoped_ptr<net::StreamSocket> socket) {
- done_callback.Run(error, socket.Pass());
+void FakeChannelAuthenticator::OnAuthBytesWritten(int result) {
+ EXPECT_EQ(1, result);
+ EXPECT_FALSE(written_);
+ written_ = true;
+ if (read_)
+ done_callback_.Run(error_, socket_.Pass());
+}
+
+void FakeChannelAuthenticator::OnAuthBytesRead(int result) {
+ EXPECT_EQ(1, result);
+ EXPECT_FALSE(read_);
+ read_ = true;
+ if (written_)
+ done_callback_.Run(error_, socket_.Pass());
}
FakeAuthenticator::FakeAuthenticator(

Powered by Google App Engine
This is Rietveld 408576698