Chromium Code Reviews| 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/client_control_dispatcher.h" | |
| 6 | |
| 7 #include "base/memory/ref_counted.h" | |
| 8 #include "net/base/io_buffer.h" | |
| 9 #include "remoting/proto/control.pb.h" | |
| 10 #include "remoting/proto/event.pb.h" | |
| 11 #include "remoting/proto/internal.pb.h" | |
| 12 #include "remoting/protocol/client_stub.h" | |
| 13 #include "remoting/protocol/input_stub.h" | |
| 14 #include "remoting/protocol/message_reader.h" | |
| 15 #include "remoting/protocol/session.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 namespace protocol { | |
| 19 | |
| 20 ClientControlDispatcher::ClientControlDispatcher( | |
| 21 base::MessageLoopProxy* message_loop) | |
| 22 : client_stub_(NULL), | |
| 23 writer_(new BufferedSocketWriter(message_loop)) { | |
| 24 } | |
| 25 | |
| 26 ClientControlDispatcher::~ClientControlDispatcher() { | |
| 27 Close(); | |
| 28 } | |
| 29 | |
| 30 void ClientControlDispatcher::Init( | |
| 31 protocol::Session* session, ClientStub* client_stub) { | |
| 32 DCHECK(session); | |
| 33 DCHECK(client_stub); | |
| 34 | |
| 35 client_stub_ = client_stub; | |
| 36 | |
| 37 writer_->Init(session->control_channel(), | |
| 38 BufferedSocketWriter::WriteFailedCallback()); | |
|
Wez
2011/11/17 01:51:56
Seems strange to ignore write errors?
Sergey Ulanov
2011/11/17 19:29:06
Write may fail only when the channel is disconnect
| |
| 39 | |
| 40 reader_.Init(session->control_channel(), base::Bind( | |
| 41 &ClientControlDispatcher::OnMessageReceived, base::Unretained(this))); | |
|
Wez
2011/11/17 01:51:56
Can either of these Init() calls fail?
Sergey Ulanov
2011/11/17 19:29:06
No.
| |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 void ClientControlDispatcher::OnMessageReceived( | |
| 46 ControlMessage* message, const base::Closure& done_task) { | |
| 47 if (message->has_begin_session_deprecated()) { | |
| 48 // Host sends legacy BeginSession message for compatibility with | |
| 49 // older clients. Ignore it. | |
| 50 } else { | |
| 51 LOG(WARNING) << "Invalid control message received."; | |
|
Wez
2011/11/17 01:51:56
nit: The message isn't necessarily "invalid", just
Sergey Ulanov
2011/11/17 19:29:06
Done.
| |
| 52 } | |
| 53 done_task.Run(); | |
| 54 } | |
| 55 | |
| 56 void ClientControlDispatcher::Close() { | |
| 57 writer_->Close(); | |
|
Wez
2011/11/17 01:51:56
Fold this in to the destructor? Do we even need t
Sergey Ulanov
2011/11/17 19:29:06
Done.
| |
| 58 } | |
| 59 | |
| 60 } // namespace protocol | |
| 61 } // namespace remoting | |
| OLD | NEW |