blob: 1e76e32c97975055c6b277ee37246d4af422f11b [file] [log] [blame]
[email protected]409ac612011-11-18 04:05:571// 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/client_control_dispatcher.h"
6
[email protected]409ac612011-11-18 04:05:577#include "base/message_loop_proxy.h"
[email protected]2e8b52c2011-11-22 00:07:138#include "net/socket/stream_socket.h"
9#include "remoting/base/constants.h"
[email protected]409ac612011-11-18 04:05:5710#include "remoting/proto/control.pb.h"
[email protected]409ac612011-11-18 04:05:5711#include "remoting/proto/internal.pb.h"
[email protected]2e8b52c2011-11-22 00:07:1312#include "remoting/protocol/buffered_socket_writer.h"
[email protected]409ac612011-11-18 04:05:5713#include "remoting/protocol/client_stub.h"
[email protected]409ac612011-11-18 04:05:5714
15namespace remoting {
16namespace protocol {
17
18ClientControlDispatcher::ClientControlDispatcher()
[email protected]2e8b52c2011-11-22 00:07:1319 : ChannelDispatcherBase(kControlChannelName),
20 client_stub_(NULL),
[email protected]409ac612011-11-18 04:05:5721 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) {
22}
23
24ClientControlDispatcher::~ClientControlDispatcher() {
25 writer_->Close();
26}
27
[email protected]2e8b52c2011-11-22 00:07:1328void ClientControlDispatcher::OnInitialized() {
[email protected]409ac612011-11-18 04:05:5729 // TODO(garykac): Set write failed callback.
[email protected]2e8b52c2011-11-22 00:07:1330 writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback());
31 reader_.Init(channel(), base::Bind(
[email protected]409ac612011-11-18 04:05:5732 &ClientControlDispatcher::OnMessageReceived, base::Unretained(this)));
33}
34
35void ClientControlDispatcher::OnMessageReceived(
36 ControlMessage* message, const base::Closure& done_task) {
37 DCHECK(client_stub_);
38
39 base::ScopedClosureRunner done_runner(done_task);
40
41 if (message->has_begin_session_deprecated()) {
42 // Host sends legacy BeginSession message for compatibility with
43 // older clients. Ignore it without warning.
44 } else {
45 LOG(WARNING) << "Unknown control message received.";
46 }
47}
48
49} // namespace protocol
50} // namespace remoting