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/channel_dispatcher_base.h" | 5 #include "remoting/protocol/channel_dispatcher_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/socket/stream_socket.h" | 8 #include "net/socket/stream_socket.h" |
| 9 #include "remoting/protocol/channel_factory.h" |
9 #include "remoting/protocol/session.h" | 10 #include "remoting/protocol/session.h" |
10 | 11 |
11 namespace remoting { | 12 namespace remoting { |
12 namespace protocol { | 13 namespace protocol { |
13 | 14 |
14 ChannelDispatcherBase::ChannelDispatcherBase(const char* channel_name) | 15 ChannelDispatcherBase::ChannelDispatcherBase(const char* channel_name) |
15 : channel_name_(channel_name), | 16 : channel_name_(channel_name), |
16 session_(NULL) { | 17 channel_factory_(NULL) { |
17 } | 18 } |
18 | 19 |
19 ChannelDispatcherBase::~ChannelDispatcherBase() { | 20 ChannelDispatcherBase::~ChannelDispatcherBase() { |
20 if (session_) | 21 if (channel_factory_) |
21 session_->CancelChannelCreation(channel_name_); | 22 channel_factory_->CancelChannelCreation(channel_name_); |
22 } | 23 } |
23 | 24 |
24 void ChannelDispatcherBase::Init(Session* session, | 25 void ChannelDispatcherBase::Init(Session* session, |
25 const InitializedCallback& callback) { | 26 const InitializedCallback& callback) { |
26 DCHECK(session); | 27 DCHECK(session); |
27 session_ = session; | 28 channel_factory_ = session->GetTransportChannelFactory(); |
28 initialized_callback_ = callback; | 29 initialized_callback_ = callback; |
29 | 30 |
30 session_->CreateStreamChannel(channel_name_, base::Bind( | 31 channel_factory_->CreateStreamChannel(channel_name_, base::Bind( |
31 &ChannelDispatcherBase::OnChannelReady, base::Unretained(this))); | 32 &ChannelDispatcherBase::OnChannelReady, base::Unretained(this))); |
32 } | 33 } |
33 | 34 |
34 void ChannelDispatcherBase::OnChannelReady( | 35 void ChannelDispatcherBase::OnChannelReady( |
35 scoped_ptr<net::StreamSocket> socket) { | 36 scoped_ptr<net::StreamSocket> socket) { |
36 if (!socket.get()) { | 37 if (!socket.get()) { |
37 initialized_callback_.Run(false); | 38 initialized_callback_.Run(false); |
38 return; | 39 return; |
39 } | 40 } |
40 | 41 |
41 channel_ = socket.Pass(); | 42 channel_ = socket.Pass(); |
42 | 43 |
43 OnInitialized(); | 44 OnInitialized(); |
44 | 45 |
45 initialized_callback_.Run(true); | 46 initialized_callback_.Run(true); |
46 } | 47 } |
47 | 48 |
48 } // namespace protocol | 49 } // namespace protocol |
49 } // namespace remoting | 50 } // namespace remoting |
OLD | NEW |