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* channel_name) |
| 15 : channel_name_(channel_name), |
| 16 session_(NULL) { |
| 17 } |
| 18 |
| 19 ChannelDispatcherBase::~ChannelDispatcherBase() { |
| 20 if (session_) |
| 21 session_->CancelChannelCreation(channel_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(channel_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); |
| 45 } |
| 46 |
| 47 } // namespace protocol |
| 48 } // namespace remoting |
OLD | NEW |