Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: remoting/protocol/client_control_dispatcher.cc

Issue 1654513003: Simplify message parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_done
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_control_dispatcher.h" 5 #include "remoting/protocol/client_control_dispatcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 << cursor_shape.data().size() << " bytes"; 52 << cursor_shape.data().size() << " bytes";
53 return false; 53 return false;
54 } 54 }
55 55
56 return true; 56 return true;
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 ClientControlDispatcher::ClientControlDispatcher() 61 ClientControlDispatcher::ClientControlDispatcher()
62 : ChannelDispatcherBase(kControlChannelName), 62 : ChannelDispatcherBase(kControlChannelName) {}
63 client_stub_(nullptr),
64 clipboard_stub_(nullptr),
65 parser_(base::Bind(&ClientControlDispatcher::OnMessageReceived,
66 base::Unretained(this)),
67 reader()) {}
68
69 ClientControlDispatcher::~ClientControlDispatcher() {} 63 ClientControlDispatcher::~ClientControlDispatcher() {}
70 64
71 void ClientControlDispatcher::InjectClipboardEvent( 65 void ClientControlDispatcher::InjectClipboardEvent(
72 const ClipboardEvent& event) { 66 const ClipboardEvent& event) {
73 ControlMessage message; 67 ControlMessage message;
74 message.mutable_clipboard_event()->CopyFrom(event); 68 message.mutable_clipboard_event()->CopyFrom(event);
75 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); 69 writer()->Write(SerializeAndFrameMessage(message), base::Closure());
76 } 70 }
77 71
78 void ClientControlDispatcher::NotifyClientResolution( 72 void ClientControlDispatcher::NotifyClientResolution(
(...skipping 29 matching lines...) Expand all
108 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); 102 writer()->Write(SerializeAndFrameMessage(message), base::Closure());
109 } 103 }
110 104
111 void ClientControlDispatcher::DeliverClientMessage( 105 void ClientControlDispatcher::DeliverClientMessage(
112 const ExtensionMessage& message) { 106 const ExtensionMessage& message) {
113 ControlMessage control_message; 107 ControlMessage control_message;
114 control_message.mutable_extension_message()->CopyFrom(message); 108 control_message.mutable_extension_message()->CopyFrom(message);
115 writer()->Write(SerializeAndFrameMessage(control_message), base::Closure()); 109 writer()->Write(SerializeAndFrameMessage(control_message), base::Closure());
116 } 110 }
117 111
118 void ClientControlDispatcher::OnMessageReceived( 112 void ClientControlDispatcher::OnIncomingMessage(
119 scoped_ptr<ControlMessage> message) { 113 scoped_ptr<CompoundBuffer> buffer) {
120 DCHECK(client_stub_); 114 DCHECK(client_stub_);
121 DCHECK(clipboard_stub_); 115 DCHECK(clipboard_stub_);
122 116
117 scoped_ptr<ControlMessage> message =
118 ParseMessage<ControlMessage>(buffer.get());
119 if (!message)
120 return;
121
123 if (message->has_clipboard_event()) { 122 if (message->has_clipboard_event()) {
124 clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); 123 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
125 } else if (message->has_capabilities()) { 124 } else if (message->has_capabilities()) {
126 client_stub_->SetCapabilities(message->capabilities()); 125 client_stub_->SetCapabilities(message->capabilities());
127 } else if (message->has_cursor_shape()) { 126 } else if (message->has_cursor_shape()) {
128 if (CursorShapeIsValid(message->cursor_shape())) 127 if (CursorShapeIsValid(message->cursor_shape()))
129 client_stub_->SetCursorShape(message->cursor_shape()); 128 client_stub_->SetCursorShape(message->cursor_shape());
130 } else if (message->has_pairing_response()) { 129 } else if (message->has_pairing_response()) {
131 client_stub_->SetPairingResponse(message->pairing_response()); 130 client_stub_->SetPairingResponse(message->pairing_response());
132 } else if (message->has_extension_message()) { 131 } else if (message->has_extension_message()) {
133 client_stub_->DeliverHostMessage(message->extension_message()); 132 client_stub_->DeliverHostMessage(message->extension_message());
134 } else { 133 } else {
135 LOG(WARNING) << "Unknown control message received."; 134 LOG(WARNING) << "Unknown control message received.";
136 } 135 }
137 } 136 }
138 137
139 } // namespace protocol 138 } // namespace protocol
140 } // namespace remoting 139 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/client_control_dispatcher.h ('k') | remoting/protocol/client_event_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698