Chromium Code Reviews| Index: remoting/protocol/channel_dispatcher_base.cc |
| diff --git a/remoting/protocol/channel_dispatcher_base.cc b/remoting/protocol/channel_dispatcher_base.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eb08818067b5485cc5e35053f0ca26ce228c8e86 |
| --- /dev/null |
| +++ b/remoting/protocol/channel_dispatcher_base.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/protocol/channel_dispatcher_base.h" |
| + |
| +#include "base/bind.h" |
| +#include "net/socket/stream_socket.h" |
| +#include "remoting/protocol/session.h" |
| + |
| +namespace remoting { |
| +namespace protocol { |
| + |
| +ChannelDispatcherBase::ChannelDispatcherBase(const char* name) |
| + : name_(name), |
| + session_(NULL) { |
| +} |
| + |
| +ChannelDispatcherBase::~ChannelDispatcherBase() { |
| + if (session_) |
| + session_->CancelChannelCreation(name_); |
| +} |
| + |
| +void ChannelDispatcherBase::Init(Session* session, |
| + const InitializedCallback& callback) { |
| + DCHECK(session); |
| + session_ = session; |
| + initialized_callback_ = callback; |
| + |
| + session_->CreateStreamChannel(name_, base::Bind( |
| + &ChannelDispatcherBase::OnChannelReady, base::Unretained(this))); |
| +} |
| + |
| +void ChannelDispatcherBase::OnChannelReady(net::StreamSocket* socket) { |
| + if (!socket) { |
| + initialized_callback_.Run(false); |
| + return; |
| + } |
| + |
| + channel_.reset(socket); |
| + |
| + OnInitialized(); |
| + |
| + 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.
|
| +} |
| + |
| +} // namespace protocol |
| +} // namespace remoting |