| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/client_event_dispatcher.h" | 5 #include "remoting/protocol/client_event_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "net/socket/stream_socket.h" |
| 10 #include "remoting/base/constants.h" |
| 9 #include "remoting/proto/event.pb.h" | 11 #include "remoting/proto/event.pb.h" |
| 10 #include "remoting/proto/internal.pb.h" | 12 #include "remoting/proto/internal.pb.h" |
| 11 #include "remoting/protocol/buffered_socket_writer.h" | 13 #include "remoting/protocol/buffered_socket_writer.h" |
| 12 #include "remoting/protocol/session.h" | |
| 13 #include "remoting/protocol/util.h" | 14 #include "remoting/protocol/util.h" |
| 14 | 15 |
| 15 namespace remoting { | 16 namespace remoting { |
| 16 namespace protocol { | 17 namespace protocol { |
| 17 | 18 |
| 18 ClientEventDispatcher::ClientEventDispatcher() | 19 ClientEventDispatcher::ClientEventDispatcher() |
| 19 : writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { | 20 : ChannelDispatcherBase(kEventChannelName), |
| 21 writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 ClientEventDispatcher::~ClientEventDispatcher() { | 24 ClientEventDispatcher::~ClientEventDispatcher() { |
| 23 writer_->Close(); | 25 writer_->Close(); |
| 24 } | 26 } |
| 25 | 27 |
| 26 void ClientEventDispatcher::Init(Session* session) { | 28 void ClientEventDispatcher::OnInitialized() { |
| 27 DCHECK(session); | |
| 28 | |
| 29 // TODO(garykac): Set write failed callback. | 29 // TODO(garykac): Set write failed callback. |
| 30 writer_->Init(session->event_channel(), | 30 writer_->Init(channel(), |
| 31 BufferedSocketWriter::WriteFailedCallback()); | 31 BufferedSocketWriter::WriteFailedCallback()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void ClientEventDispatcher::InjectKeyEvent(const KeyEvent& event) { | 34 void ClientEventDispatcher::InjectKeyEvent(const KeyEvent& event) { |
| 35 EventMessage message; | 35 EventMessage message; |
| 36 message.set_sequence_number(base::Time::Now().ToInternalValue()); | 36 message.set_sequence_number(base::Time::Now().ToInternalValue()); |
| 37 message.mutable_key_event()->CopyFrom(event); | 37 message.mutable_key_event()->CopyFrom(event); |
| 38 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); | 38 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ClientEventDispatcher::InjectMouseEvent(const MouseEvent& event) { | 41 void ClientEventDispatcher::InjectMouseEvent(const MouseEvent& event) { |
| 42 EventMessage message; | 42 EventMessage message; |
| 43 message.set_sequence_number(base::Time::Now().ToInternalValue()); | 43 message.set_sequence_number(base::Time::Now().ToInternalValue()); |
| 44 message.mutable_mouse_event()->CopyFrom(event); | 44 message.mutable_mouse_event()->CopyFrom(event); |
| 45 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); | 45 writer_->Write(SerializeAndFrameMessage(message), base::Closure()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace protocol | 48 } // namespace protocol |
| 49 } // namespace remoting | 49 } // namespace remoting |
| OLD | NEW |