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

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

Issue 551173004: Move PseudoTCP and channel auth out of LibjingleTransportFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clean_dgrams
Patch Set: Created 6 years, 3 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/fake_authenticator.h" 5 #include "remoting/protocol/fake_authenticator.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h"
10 #include "net/socket/stream_socket.h" 11 #include "net/socket/stream_socket.h"
11 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
14 15
15 namespace remoting { 16 namespace remoting {
16 namespace protocol { 17 namespace protocol {
17 18
18 FakeChannelAuthenticator::FakeChannelAuthenticator(bool accept, bool async) 19 FakeChannelAuthenticator::FakeChannelAuthenticator(bool accept, bool async)
19 : result_(accept ? net::OK : net::ERR_FAILED), 20 : result_(accept ? net::OK : net::ERR_FAILED),
(...skipping 29 matching lines...) Expand all
49 50
50 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(1); 51 scoped_refptr<net::IOBuffer> read_buf = new net::IOBuffer(1);
51 result = 52 result =
52 socket_->Read(read_buf.get(), 53 socket_->Read(read_buf.get(),
53 1, 54 1,
54 base::Bind(&FakeChannelAuthenticator::OnAuthBytesRead, 55 base::Bind(&FakeChannelAuthenticator::OnAuthBytesRead,
55 weak_factory_.GetWeakPtr())); 56 weak_factory_.GetWeakPtr()));
56 if (result != net::ERR_IO_PENDING) 57 if (result != net::ERR_IO_PENDING)
57 OnAuthBytesRead(result); 58 OnAuthBytesRead(result);
58 } else { 59 } else {
59 if (result_ != net::OK) 60 CallDoneCallback();
60 socket_.reset();
61 done_callback.Run(result_, socket_.Pass());
62 } 61 }
63 } 62 }
64 63
65 void FakeChannelAuthenticator::OnAuthBytesWritten(int result) { 64 void FakeChannelAuthenticator::OnAuthBytesWritten(int result) {
66 EXPECT_EQ(1, result); 65 EXPECT_EQ(1, result);
67 EXPECT_FALSE(did_write_bytes_); 66 EXPECT_FALSE(did_write_bytes_);
68 did_write_bytes_ = true; 67 did_write_bytes_ = true;
69 if (did_read_bytes_) 68 if (did_read_bytes_)
70 done_callback_.Run(result_, socket_.Pass()); 69 CallDoneCallback();
71 } 70 }
72 71
73 void FakeChannelAuthenticator::OnAuthBytesRead(int result) { 72 void FakeChannelAuthenticator::OnAuthBytesRead(int result) {
74 EXPECT_EQ(1, result); 73 EXPECT_EQ(1, result);
75 EXPECT_FALSE(did_read_bytes_); 74 EXPECT_FALSE(did_read_bytes_);
76 did_read_bytes_ = true; 75 did_read_bytes_ = true;
77 if (did_write_bytes_) 76 if (did_write_bytes_)
78 done_callback_.Run(result_, socket_.Pass()); 77 CallDoneCallback();
78 }
79
80 void FakeChannelAuthenticator::CallDoneCallback() {
81 DoneCallback callback = done_callback_;
82 done_callback_.Reset();
83 if (result_ != net::OK)
84 socket_.reset();
85 callback.Run(result_, socket_.Pass());
79 } 86 }
80 87
81 FakeAuthenticator::FakeAuthenticator( 88 FakeAuthenticator::FakeAuthenticator(
82 Type type, int round_trips, Action action, bool async) 89 Type type, int round_trips, Action action, bool async)
83 : type_(type), 90 : type_(type),
84 round_trips_(round_trips), 91 round_trips_(round_trips),
85 action_(action), 92 action_(action),
86 async_(async), 93 async_(async),
87 messages_(0), 94 messages_(0),
88 messages_till_started_(0) { 95 messages_till_started_(0) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 FakeAuthenticator* authenticator = new FakeAuthenticator( 186 FakeAuthenticator* authenticator = new FakeAuthenticator(
180 FakeAuthenticator::HOST, round_trips_, action_, async_); 187 FakeAuthenticator::HOST, round_trips_, action_, async_);
181 authenticator->set_messages_till_started(messages_till_started_); 188 authenticator->set_messages_till_started(messages_till_started_);
182 189
183 scoped_ptr<Authenticator> result(authenticator); 190 scoped_ptr<Authenticator> result(authenticator);
184 return result.Pass(); 191 return result.Pass();
185 } 192 }
186 193
187 } // namespace protocol 194 } // namespace protocol
188 } // namespace remoting 195 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698