OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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/channel_dispatcher_base.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "net/socket/stream_socket.h" | |
9 #include "remoting/protocol/session.h" | |
10 | |
11 namespace remoting { | |
12 namespace protocol { | |
13 | |
14 ChannelDispatcherBase::ChannelDispatcherBase(const char* name) | |
15 : name_(name), | |
16 session_(NULL) { | |
17 } | |
18 | |
19 ChannelDispatcherBase::~ChannelDispatcherBase() { | |
20 if (session_) | |
21 session_->CancelChannelCreation(name_); | |
22 } | |
23 | |
24 void ChannelDispatcherBase::Init(Session* session, | |
25 const InitializedCallback& callback) { | |
26 DCHECK(session); | |
27 session_ = session; | |
28 initialized_callback_ = callback; | |
29 | |
30 session_->CreateStreamChannel(name_, base::Bind( | |
31 &ChannelDispatcherBase::OnChannelReady, base::Unretained(this))); | |
32 } | |
33 | |
34 void ChannelDispatcherBase::OnChannelReady(net::StreamSocket* socket) { | |
35 if (!socket) { | |
36 initialized_callback_.Run(false); | |
37 return; | |
38 } | |
39 | |
40 channel_.reset(socket); | |
41 | |
42 OnInitialized(); | |
43 | |
44 initialized_callback_.Run(true); | |
Wez
2011/11/17 22:39:41
Should we take a copy of the callback, in case OnI
Sergey Ulanov
2011/11/17 23:10:38
It's not allowed. Added comments about it.
| |
45 } | |
46 | |
47 } // namespace protocol | |
48 } // namespace remoting | |
OLD | NEW |