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_authenticator.h" | 5 #include "remoting/protocol/fake_authenticator.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/socket/stream_socket.h" | 10 #include "net/socket/stream_socket.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 void FakeChannelAuthenticator::SecureAndAuthenticate( | 29 void FakeChannelAuthenticator::SecureAndAuthenticate( |
30 scoped_ptr<net::StreamSocket> socket, | 30 scoped_ptr<net::StreamSocket> socket, |
31 const DoneCallback& done_callback) { | 31 const DoneCallback& done_callback) { |
32 socket_ = socket.Pass(); | 32 socket_ = socket.Pass(); |
33 | 33 |
34 if (async_) { | 34 if (async_) { |
35 done_callback_ = done_callback; | 35 done_callback_ = done_callback; |
36 | 36 |
37 scoped_refptr<net::IOBuffer> write_buf = new net::IOBuffer(1); | 37 scoped_refptr<net::IOBuffer> write_buf = new net::IOBuffer(1); |
38 write_buf->data()[0] = 0; | 38 write_buf->data()[0] = 0; |
39 int result = socket_->Write( | 39 int result = |
40 write_buf, 1, base::Bind(&FakeChannelAuthenticator::OnAuthBytesWritten, | 40 socket_->Write(write_buf.get(), |
41 weak_factory_.GetWeakPtr())); | 41 1, |
| 42 base::Bind(&FakeChannelAuthenticator::OnAuthBytesWritten, |
| 43 weak_factory_.GetWeakPtr())); |
42 if (result != net::ERR_IO_PENDING) { | 44 if (result != net::ERR_IO_PENDING) { |
43 // This will not call the callback because |did_read_bytes_| is | 45 // This will not call the callback because |did_read_bytes_| is |
44 // still set to false. | 46 // still set to false. |
45 OnAuthBytesWritten(result); | 47 OnAuthBytesWritten(result); |
46 } | 48 } |
47 | 49 |
48 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(1); | 50 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(1); |
49 result = socket_->Read( | 51 result = |
50 read_buf, 1, base::Bind(&FakeChannelAuthenticator::OnAuthBytesRead, | 52 socket_->Read(read_buf.get(), |
51 weak_factory_.GetWeakPtr())); | 53 1, |
| 54 base::Bind(&FakeChannelAuthenticator::OnAuthBytesRead, |
| 55 weak_factory_.GetWeakPtr())); |
52 if (result != net::ERR_IO_PENDING) | 56 if (result != net::ERR_IO_PENDING) |
53 OnAuthBytesRead(result); | 57 OnAuthBytesRead(result); |
54 } else { | 58 } else { |
55 if (result_ != net::OK) | 59 if (result_ != net::OK) |
56 socket_.reset(); | 60 socket_.reset(); |
57 done_callback.Run(result_, socket_.Pass()); | 61 done_callback.Run(result_, socket_.Pass()); |
58 } | 62 } |
59 } | 63 } |
60 | 64 |
61 void FakeChannelAuthenticator::OnAuthBytesWritten(int result) { | 65 void FakeChannelAuthenticator::OnAuthBytesWritten(int result) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( | 164 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( |
161 const std::string& local_jid, | 165 const std::string& local_jid, |
162 const std::string& remote_jid, | 166 const std::string& remote_jid, |
163 const buzz::XmlElement* first_message) { | 167 const buzz::XmlElement* first_message) { |
164 return scoped_ptr<Authenticator>(new FakeAuthenticator( | 168 return scoped_ptr<Authenticator>(new FakeAuthenticator( |
165 FakeAuthenticator::HOST, round_trips_, action_, async_)); | 169 FakeAuthenticator::HOST, round_trips_, action_, async_)); |
166 } | 170 } |
167 | 171 |
168 } // namespace protocol | 172 } // namespace protocol |
169 } // namespace remoting | 173 } // namespace remoting |
OLD | NEW |