summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/channel_dispatcher_base.cc
blob: 21f118784803eff251aec88f7d6ea9cbeb661358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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* channel_name)
    : channel_name_(channel_name),
      session_(NULL) {
}

ChannelDispatcherBase::~ChannelDispatcherBase() {
  if (session_)
    session_->CancelChannelCreation(channel_name_);
}

void ChannelDispatcherBase::Init(Session* session,
                                 const InitializedCallback& callback) {
  DCHECK(session);
  session_ = session;
  initialized_callback_ = callback;

  session_->CreateStreamChannel(channel_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);
}

}  // namespace protocol
}  // namespace remoting