OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/protocol/authenticated_channel_factory.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "net/socket/stream_socket.h" | |
9 #include "remoting/protocol/authenticator.h" | |
10 #include "remoting/protocol/channel_authenticator.h" | |
11 | |
12 namespace remoting { | |
13 namespace protocol { | |
14 | |
15 AuthenticatedChannelFactory::AuthenticatedChannelFactory( | |
16 ChannelFactory* channel_factory, | |
17 Authenticator* authenticator) | |
18 : channel_factory_(channel_factory), | |
19 authenticator_(authenticator) { | |
20 DCHECK_EQ(authenticator_->state(), Authenticator::ACCEPTED); | |
21 } | |
22 | |
23 AuthenticatedChannelFactory::~AuthenticatedChannelFactory() { | |
24 // CancelChannelCreation() is expected to be called before destruction. | |
Wez
2014/09/10 02:29:25
Is that a part of the ChannelFactory interface con
Sergey Ulanov
2014/09/10 21:50:57
I think it's still useful to make it clear what th
Wez
2014/09/10 22:19:41
You have an equivalent check in the PseudoTcpChann
Sergey Ulanov
2014/09/10 22:49:30
Done.
| |
25 DCHECK(channels_.empty()); | |
26 } | |
27 | |
28 void AuthenticatedChannelFactory::CreateChannel( | |
29 const std::string& name, | |
30 const ChannelCreatedCallback& callback) { | |
31 DCHECK(!callback.is_null()); | |
32 channel_factory_->CreateChannel( | |
33 name, | |
34 base::Bind(&AuthenticatedChannelFactory::OnBaseChannelCreated, | |
35 base::Unretained(this), name, callback)); | |
36 } | |
37 | |
38 void AuthenticatedChannelFactory::CancelChannelCreation( | |
39 const std::string& name) { | |
40 ChannelsMap::iterator it = channels_.find(name); | |
41 if (it == channels_.end()) { | |
42 channel_factory_->CancelChannelCreation(name); | |
43 } else { | |
44 delete it->second; | |
45 channels_.erase(it); | |
46 } | |
47 } | |
48 | |
49 void AuthenticatedChannelFactory::OnBaseChannelCreated( | |
50 const std::string& name, | |
51 const ChannelCreatedCallback& callback, | |
52 scoped_ptr<net::StreamSocket> socket) { | |
53 if (!socket) { | |
54 callback.Run(socket.Pass()); | |
Wez
2014/09/10 02:29:25
It reads oddly to socket.Pass() only if socket is
Sergey Ulanov
2014/09/10 21:50:57
yes, but it's more to type :(. Done.
| |
55 return; | |
56 } | |
57 | |
58 scoped_ptr<ChannelAuthenticator> channel_authenticator = | |
59 authenticator_->CreateChannelAuthenticator(); | |
60 ChannelAuthenticator* channel_authenticator_ptr = | |
61 channel_authenticator.release(); | |
Wez
2014/09/10 02:29:25
nit: Can you just .release() the CreateChannelAuth
Sergey Ulanov
2014/09/10 21:50:57
Done.
| |
62 channels_[name] = channel_authenticator_ptr; | |
63 channel_authenticator_ptr->SecureAndAuthenticate( | |
64 socket.Pass(), | |
65 base::Bind(&AuthenticatedChannelFactory::OnAuthenticated, | |
66 base::Unretained(this), name, callback)); | |
67 } | |
68 | |
69 void AuthenticatedChannelFactory::OnAuthenticated( | |
70 const std::string& name, | |
71 const ChannelCreatedCallback& callback, | |
72 net::Error error, | |
73 scoped_ptr<net::StreamSocket> socket) { | |
74 scoped_ptr<ChannelAuthenticator> authenticator; | |
75 | |
76 ChannelsMap::iterator it = channels_.find(name); | |
77 DCHECK(it != channels_.end()); | |
78 authenticator.reset(it->second); | |
Wez
2014/09/10 02:29:25
Why not just delete it->second, like you do in the
Sergey Ulanov
2014/09/10 21:50:57
Done.
| |
79 channels_.erase(it); | |
80 | |
81 DCHECK(error == net::OK || socket); | |
Wez
2014/09/10 02:29:25
Do you mean (socket || error != net::OK), i.e. tha
Sergey Ulanov
2014/09/10 21:50:57
Yes. Replaced it with a stricter DCHECK and fixed
| |
82 if (error != net::OK) { | |
83 socket.reset(); | |
84 } | |
85 | |
86 callback.Run(socket.Pass()); | |
87 | |
Wez
2014/09/10 02:29:26
nit: Lose this blank line.
Sergey Ulanov
2014/09/10 21:50:57
Done.
| |
88 } | |
89 | |
90 } // namespace protocol | |
91 } // namespace remoting | |
OLD | NEW |