[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 1 | // Copyright 2013 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/host/chromoting_param_traits.h" |
| 6 | |
avi | c5960f3 | 2015-12-22 22:49:48 | [diff] [blame] | 7 | #include <stdint.h> |
Erik Jensen | 8f1acc1 | 2019-01-14 20:18:31 | [diff] [blame] | 8 | #include <sstream> |
avi | c5960f3 | 2015-12-22 22:49:48 | [diff] [blame] | 9 | |
[email protected] | eaf9253 | 2013-06-11 07:39:19 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 11 | #include "ipc/ipc_message_protobuf_utils.h" |
martijn | a46bd47a | 2016-04-06 18:05:48 | [diff] [blame] | 12 | #include "ipc/ipc_message_utils.h" |
Erik Jensen | 8f1acc1 | 2019-01-14 20:18:31 | [diff] [blame] | 13 | #include "remoting/protocol/file_transfer_helpers.h" |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 14 | #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 15 | |
| 16 | namespace IPC { |
| 17 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 18 | // webrtc::DesktopVector |
| 19 | |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 20 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 21 | void ParamTraits<webrtc::DesktopVector>::Write(base::Pickle* m, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 22 | const webrtc::DesktopVector& p) { |
| 23 | m->WriteInt(p.x()); |
| 24 | m->WriteInt(p.y()); |
| 25 | } |
| 26 | |
| 27 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 28 | bool ParamTraits<webrtc::DesktopVector>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 29 | base::PickleIterator* iter, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 30 | webrtc::DesktopVector* r) { |
| 31 | int x, y; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 32 | if (!iter->ReadInt(&x) || !iter->ReadInt(&y)) |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 33 | return false; |
| 34 | *r = webrtc::DesktopVector(x, y); |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | // static |
| 39 | void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p, |
| 40 | std::string* l) { |
| 41 | l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)", |
| 42 | p.x(), p.y())); |
| 43 | } |
| 44 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 45 | // webrtc::DesktopSize |
| 46 | |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 47 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 48 | void ParamTraits<webrtc::DesktopSize>::Write(base::Pickle* m, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 49 | const webrtc::DesktopSize& p) { |
| 50 | m->WriteInt(p.width()); |
| 51 | m->WriteInt(p.height()); |
| 52 | } |
| 53 | |
| 54 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 55 | bool ParamTraits<webrtc::DesktopSize>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 56 | base::PickleIterator* iter, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 57 | webrtc::DesktopSize* r) { |
| 58 | int width, height; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 59 | if (!iter->ReadInt(&width) || !iter->ReadInt(&height)) |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 60 | return false; |
| 61 | *r = webrtc::DesktopSize(width, height); |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | // static |
| 66 | void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p, |
| 67 | std::string* l) { |
| 68 | l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)", |
| 69 | p.width(), p.height())); |
| 70 | } |
| 71 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 72 | // webrtc::DesktopRect |
| 73 | |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 74 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 75 | void ParamTraits<webrtc::DesktopRect>::Write(base::Pickle* m, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 76 | const webrtc::DesktopRect& p) { |
| 77 | m->WriteInt(p.left()); |
| 78 | m->WriteInt(p.top()); |
| 79 | m->WriteInt(p.right()); |
| 80 | m->WriteInt(p.bottom()); |
| 81 | } |
| 82 | |
| 83 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 84 | bool ParamTraits<webrtc::DesktopRect>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 85 | base::PickleIterator* iter, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 86 | webrtc::DesktopRect* r) { |
| 87 | int left, right, top, bottom; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 88 | if (!iter->ReadInt(&left) || !iter->ReadInt(&top) || |
| 89 | !iter->ReadInt(&right) || !iter->ReadInt(&bottom)) { |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 90 | return false; |
| 91 | } |
| 92 | *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom); |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | // static |
| 97 | void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, |
| 98 | std::string* l) { |
| 99 | l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)", |
| 100 | p.left(), p.top(), p.right(), p.bottom())); |
| 101 | } |
| 102 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 103 | // webrtc::MouseCursor |
| 104 | |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 105 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 106 | void ParamTraits<webrtc::MouseCursor>::Write(base::Pickle* m, |
| 107 | const webrtc::MouseCursor& p) { |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 108 | ParamTraits<webrtc::DesktopSize>::Write(m, p.image()->size()); |
| 109 | |
| 110 | // Data is serialized in such a way that size is exactly width * height * |
| 111 | // |kBytesPerPixel|. |
| 112 | std::string data; |
| 113 | uint8_t* current_row = p.image()->data(); |
| 114 | for (int y = 0; y < p.image()->size().height(); ++y) { |
| 115 | data.append(current_row, |
| 116 | current_row + p.image()->size().width() * |
| 117 | webrtc::DesktopFrame::kBytesPerPixel); |
| 118 | current_row += p.image()->stride(); |
| 119 | } |
| 120 | m->WriteData(reinterpret_cast<const char*>(p.image()->data()), data.size()); |
| 121 | |
| 122 | ParamTraits<webrtc::DesktopVector>::Write(m, p.hotspot()); |
| 123 | } |
| 124 | |
| 125 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 126 | bool ParamTraits<webrtc::MouseCursor>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 127 | base::PickleIterator* iter, |
| 128 | webrtc::MouseCursor* r) { |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 129 | webrtc::DesktopSize size; |
| 130 | if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || |
| 131 | size.width() <= 0 || size.width() > (SHRT_MAX / 2) || |
| 132 | size.height() <= 0 || size.height() > (SHRT_MAX / 2)) { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | const int expected_length = |
| 137 | size.width() * size.height() * webrtc::DesktopFrame::kBytesPerPixel; |
| 138 | |
| 139 | const char* data; |
| 140 | int data_length; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 141 | if (!iter->ReadData(&data, &data_length) || data_length != expected_length) |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 142 | return false; |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 143 | |
| 144 | webrtc::DesktopVector hotspot; |
| 145 | if (!ParamTraits<webrtc::DesktopVector>::Read(m, iter, &hotspot)) |
| 146 | return false; |
| 147 | |
| 148 | webrtc::BasicDesktopFrame* image = new webrtc::BasicDesktopFrame(size); |
| 149 | memcpy(image->data(), data, data_length); |
| 150 | |
| 151 | r->set_image(image); |
| 152 | r->set_hotspot(hotspot); |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | // static |
| 157 | void ParamTraits<webrtc::MouseCursor>::Log( |
| 158 | const webrtc::MouseCursor& p, |
| 159 | std::string* l) { |
| 160 | l->append(base::StringPrintf( |
| 161 | "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}", |
| 162 | p.image()->size().width(), p.image()->size().height(), |
| 163 | p.hotspot().x(), p.hotspot().y())); |
| 164 | } |
| 165 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 166 | // remoting::ScreenResolution |
[email protected] | 2001320 | 2014-08-08 06:33:50 | [diff] [blame] | 167 | |
| 168 | // static |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 169 | void ParamTraits<remoting::ScreenResolution>::Write( |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 170 | base::Pickle* m, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 171 | const remoting::ScreenResolution& p) { |
| 172 | ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); |
| 173 | ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); |
| 174 | } |
| 175 | |
| 176 | // static |
| 177 | bool ParamTraits<remoting::ScreenResolution>::Read( |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 178 | const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 179 | base::PickleIterator* iter, |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 180 | remoting::ScreenResolution* r) { |
| 181 | webrtc::DesktopSize size; |
| 182 | webrtc::DesktopVector dpi; |
| 183 | if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || |
| 184 | !ParamTraits<webrtc::DesktopVector>::Read(m, iter, &dpi)) { |
| 185 | return false; |
| 186 | } |
| 187 | if (size.width() < 0 || size.height() < 0 || |
| 188 | dpi.x() < 0 || dpi.y() < 0) { |
| 189 | return false; |
| 190 | } |
| 191 | *r = remoting::ScreenResolution(size, dpi); |
| 192 | return true; |
| 193 | } |
| 194 | |
| 195 | // static |
| 196 | void ParamTraits<remoting::ScreenResolution>::Log( |
| 197 | const remoting::ScreenResolution& p, |
| 198 | std::string* l) { |
| 199 | l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", |
| 200 | p.dimensions().width(), p.dimensions().height(), |
| 201 | p.dpi().x(), p.dpi().y())); |
| 202 | } |
| 203 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 204 | // remoting::DesktopEnvironmentOptions |
| 205 | |
sergeyu | c986f52 | 2016-11-28 22:51:01 | [diff] [blame] | 206 | // static |
| 207 | void ParamTraits<remoting::DesktopEnvironmentOptions>::Write( |
| 208 | base::Pickle* m, |
| 209 | const remoting::DesktopEnvironmentOptions& p) { |
| 210 | m->WriteBool(p.enable_curtaining()); |
| 211 | m->WriteBool(p.enable_user_interface()); |
| 212 | m->WriteBool(p.desktop_capture_options()->use_update_notifications()); |
| 213 | m->WriteBool(p.desktop_capture_options()->disable_effects()); |
| 214 | m->WriteBool(p.desktop_capture_options()->detect_updated_region()); |
| 215 | #if defined(WEBRTC_WIN) |
| 216 | m->WriteBool(p.desktop_capture_options()->allow_use_magnification_api()); |
| 217 | m->WriteBool(p.desktop_capture_options()->allow_directx_capturer()); |
| 218 | #endif // defined(WEBRTC_WIN) |
| 219 | } |
| 220 | |
| 221 | // static |
| 222 | bool ParamTraits<remoting::DesktopEnvironmentOptions>::Read( |
| 223 | const base::Pickle* m, |
| 224 | base::PickleIterator* iter, |
| 225 | remoting::DesktopEnvironmentOptions* r) { |
| 226 | *r = remoting::DesktopEnvironmentOptions::CreateDefault(); |
| 227 | bool enable_curtaining; |
| 228 | bool enable_user_interface; |
| 229 | bool use_update_notifications; |
| 230 | bool disable_effects; |
| 231 | bool detect_updated_region; |
| 232 | |
| 233 | if (!iter->ReadBool(&enable_curtaining) || |
| 234 | !iter->ReadBool(&enable_user_interface) || |
| 235 | !iter->ReadBool(&use_update_notifications) || |
| 236 | !iter->ReadBool(&disable_effects) || |
| 237 | !iter->ReadBool(&detect_updated_region)) { |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | r->set_enable_curtaining(enable_curtaining); |
| 242 | r->set_enable_user_interface(enable_user_interface); |
| 243 | r->desktop_capture_options()->set_use_update_notifications( |
| 244 | use_update_notifications); |
| 245 | r->desktop_capture_options()->set_detect_updated_region( |
| 246 | detect_updated_region); |
| 247 | r->desktop_capture_options()->set_disable_effects(disable_effects); |
| 248 | |
| 249 | #if defined(WEBRTC_WIN) |
| 250 | bool allow_use_magnification_api; |
| 251 | bool allow_directx_capturer; |
| 252 | |
| 253 | if (!iter->ReadBool(&allow_use_magnification_api) || |
| 254 | !iter->ReadBool(&allow_directx_capturer)) { |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | r->desktop_capture_options()->set_allow_use_magnification_api( |
| 259 | allow_use_magnification_api); |
| 260 | r->desktop_capture_options()->set_allow_directx_capturer( |
| 261 | allow_directx_capturer); |
| 262 | #endif // defined(WEBRTC_WIN) |
| 263 | |
| 264 | return true; |
| 265 | } |
| 266 | |
| 267 | // static |
| 268 | void ParamTraits<remoting::DesktopEnvironmentOptions>::Log( |
| 269 | const remoting::DesktopEnvironmentOptions& p, |
| 270 | std::string* l) { |
| 271 | l->append("DesktopEnvironmentOptions()"); |
| 272 | } |
| 273 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 274 | // remoting::protocol::ProcessResourceUsage |
| 275 | |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 276 | // static |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 277 | void ParamTraits<remoting::protocol::ProcessResourceUsage>::Write( |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 278 | base::Pickle* m, |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 279 | const param_type& p) { |
| 280 | m->WriteString(p.process_name()); |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 281 | m->WriteDouble(p.processor_usage()); |
| 282 | m->WriteUInt64(p.working_set_size()); |
| 283 | m->WriteUInt64(p.pagefile_size()); |
| 284 | } |
| 285 | |
| 286 | // static |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 287 | bool ParamTraits<remoting::protocol::ProcessResourceUsage>::Read( |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 288 | const base::Pickle* m, |
| 289 | base::PickleIterator* iter, |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 290 | param_type* p) { |
| 291 | std::string process_name; |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 292 | double processor_usage; |
| 293 | uint64_t working_set_size; |
| 294 | uint64_t pagefile_size; |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 295 | if (!iter->ReadString(&process_name) || |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 296 | !iter->ReadDouble(&processor_usage) || |
| 297 | !iter->ReadUInt64(&working_set_size) || |
| 298 | !iter->ReadUInt64(&pagefile_size)) { |
| 299 | return false; |
| 300 | } |
| 301 | |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 302 | p->set_process_name(process_name); |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 303 | p->set_processor_usage(processor_usage); |
| 304 | p->set_working_set_size(working_set_size); |
| 305 | p->set_pagefile_size(pagefile_size); |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | // static |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 310 | void ParamTraits<remoting::protocol::ProcessResourceUsage>::Log( |
| 311 | const param_type& p, |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 312 | std::string* l) { |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 313 | l->append("ProcessResourceUsage(").append(p.process_name()).append(")"); |
| 314 | } |
| 315 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 316 | // remoting::protocol::AggregatedProcessResourceUsage |
| 317 | |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 318 | // static |
zijiehe | f401c518 | 2017-07-19 00:21:46 | [diff] [blame] | 319 | void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Write( |
| 320 | base::Pickle* m, |
| 321 | const param_type& p) { |
| 322 | WriteParam(m, p.usages()); |
| 323 | } |
| 324 | |
| 325 | // static |
| 326 | bool ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Read( |
| 327 | const base::Pickle* m, |
| 328 | base::PickleIterator* iter, |
| 329 | param_type* p) { |
| 330 | return ReadParam(m, iter, p->mutable_usages()); |
| 331 | } |
| 332 | |
| 333 | // static |
| 334 | void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Log( |
| 335 | const param_type& p, |
| 336 | std::string* l) { |
| 337 | l->append("AggregatedProcessResourceUsage("); |
| 338 | LogParam(p.usages(), l); |
| 339 | l->append(")"); |
zijiehe | 36763d8 | 2017-06-19 23:52:31 | [diff] [blame] | 340 | } |
| 341 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 342 | // remoting::protocol::ActionRequest |
| 343 | |
Joe Downing | 505ae0d0 | 2018-10-17 17:47:30 | [diff] [blame] | 344 | // static |
| 345 | void ParamTraits<remoting::protocol::ActionRequest>::Write( |
| 346 | base::Pickle* m, |
| 347 | const param_type& p) { |
| 348 | std::string serialized_action_request; |
| 349 | bool result = p.SerializeToString(&serialized_action_request); |
| 350 | DCHECK(result); |
| 351 | m->WriteString(serialized_action_request); |
| 352 | } |
| 353 | |
| 354 | // static |
| 355 | bool ParamTraits<remoting::protocol::ActionRequest>::Read( |
| 356 | const base::Pickle* m, |
| 357 | base::PickleIterator* iter, |
| 358 | param_type* p) { |
| 359 | std::string serialized_action_request; |
| 360 | if (!iter->ReadString(&serialized_action_request)) |
| 361 | return false; |
| 362 | |
| 363 | return p->ParseFromString(serialized_action_request); |
| 364 | } |
| 365 | |
| 366 | // static |
| 367 | void ParamTraits<remoting::protocol::ActionRequest>::Log(const param_type& p, |
| 368 | std::string* l) { |
| 369 | l->append(base::StringPrintf("ActionRequest action: %d, id: %u", p.action(), |
| 370 | p.request_id())); |
| 371 | } |
| 372 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 373 | // remoting::protocol::VideoLayout |
[email protected] | b9ed58f | 2013-05-16 10:45:24 | [diff] [blame] | 374 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 375 | // static |
| 376 | void ParamTraits<remoting::protocol::VideoLayout>::Write( |
| 377 | base::Pickle* m, |
| 378 | const remoting::protocol::VideoLayout& p) { |
| 379 | std::string serialized_video_layout; |
| 380 | bool result = p.SerializeToString(&serialized_video_layout); |
| 381 | DCHECK(result); |
| 382 | m->WriteString(serialized_video_layout); |
| 383 | } |
| 384 | |
| 385 | // static |
| 386 | bool ParamTraits<remoting::protocol::VideoLayout>::Read( |
| 387 | const base::Pickle* m, |
| 388 | base::PickleIterator* iter, |
| 389 | remoting::protocol::VideoLayout* p) { |
| 390 | std::string serialized_video_layout; |
| 391 | if (!iter->ReadString(&serialized_video_layout)) |
| 392 | return false; |
| 393 | |
| 394 | return p->ParseFromString(serialized_video_layout); |
| 395 | } |
| 396 | |
| 397 | // static |
| 398 | void ParamTraits<remoting::protocol::VideoLayout>::Log( |
| 399 | const remoting::protocol::VideoLayout& p, |
| 400 | std::string* l) { |
| 401 | l->append(base::StringPrintf("protocol::VideoLayout([")); |
| 402 | for (int i = 0; i < p.video_track_size(); i++) { |
| 403 | remoting::protocol::VideoTrackLayout track = p.video_track(i); |
| 404 | l->append("])"); |
| 405 | if (i != 0) |
| 406 | l->append(","); |
| 407 | l->append(base::StringPrintf("{(%d,%d) %dx%d}", track.position_x(), |
| 408 | track.position_y(), track.width(), |
| 409 | track.height())); |
| 410 | } |
| 411 | l->append("])"); |
| 412 | } |
| 413 | |
Erik Jensen | c08ecf11 | 2019-12-19 00:29:49 | [diff] [blame] | 414 | // remoting::protocol::KeyboardLayout |
| 415 | |
| 416 | // static |
| 417 | void ParamTraits<remoting::protocol::KeyboardLayout>::Write( |
| 418 | base::Pickle* m, |
| 419 | const remoting::protocol::KeyboardLayout& p) { |
| 420 | std::string serialized_keyboard_layout; |
| 421 | bool result = p.SerializeToString(&serialized_keyboard_layout); |
| 422 | DCHECK(result); |
| 423 | m->WriteString(serialized_keyboard_layout); |
| 424 | } |
| 425 | |
| 426 | // static |
| 427 | bool ParamTraits<remoting::protocol::KeyboardLayout>::Read( |
| 428 | const base::Pickle* m, |
| 429 | base::PickleIterator* iter, |
| 430 | remoting::protocol::KeyboardLayout* p) { |
| 431 | std::string serialized_keyboard_layout; |
| 432 | if (!iter->ReadString(&serialized_keyboard_layout)) |
| 433 | return false; |
| 434 | |
| 435 | return p->ParseFromString(serialized_keyboard_layout); |
| 436 | } |
| 437 | |
| 438 | // static |
| 439 | void ParamTraits<remoting::protocol::KeyboardLayout>::Log( |
| 440 | const remoting::protocol::KeyboardLayout& p, |
| 441 | std::string* l) { |
| 442 | l->append("[protocol::KeyboardLayout]"); |
| 443 | } |
| 444 | |
Erik Jensen | 8f1acc1 | 2019-01-14 20:18:31 | [diff] [blame] | 445 | // remoting::protocol::FileTransfer_Error |
| 446 | |
| 447 | // static |
| 448 | void IPC::ParamTraits<remoting::protocol::FileTransfer_Error>::Write( |
| 449 | base::Pickle* m, |
| 450 | const param_type& p) { |
| 451 | std::string serialized_file_transfer_error; |
| 452 | bool result = p.SerializeToString(&serialized_file_transfer_error); |
| 453 | DCHECK(result); |
| 454 | m->WriteString(serialized_file_transfer_error); |
| 455 | } |
| 456 | |
| 457 | // static |
| 458 | bool ParamTraits<remoting::protocol::FileTransfer_Error>::Read( |
| 459 | const base::Pickle* m, |
| 460 | base::PickleIterator* iter, |
| 461 | param_type* p) { |
| 462 | std::string serialized_file_transfer_error; |
| 463 | if (!iter->ReadString(&serialized_file_transfer_error)) |
| 464 | return false; |
| 465 | |
| 466 | return p->ParseFromString(serialized_file_transfer_error); |
| 467 | } |
| 468 | |
| 469 | // static |
| 470 | void ParamTraits<remoting::protocol::FileTransfer_Error>::Log( |
| 471 | const param_type& p, |
| 472 | std::string* l) { |
| 473 | std::ostringstream formatted; |
| 474 | formatted << p; |
| 475 | l->append( |
| 476 | base::StringPrintf("FileTransfer Error: %s", formatted.str().c_str())); |
| 477 | } |
| 478 | |
Erik Jensen | 042b439 | 2019-01-17 20:32:31 | [diff] [blame] | 479 | // remoting::Monostate |
| 480 | |
| 481 | // static |
| 482 | void IPC::ParamTraits<remoting::Monostate>::Write(base::Pickle*, |
| 483 | const param_type&) {} |
| 484 | |
| 485 | // static |
| 486 | bool ParamTraits<remoting::Monostate>::Read(const base::Pickle*, |
| 487 | base::PickleIterator*, |
| 488 | param_type*) { |
| 489 | return true; |
| 490 | } |
| 491 | |
| 492 | // static |
| 493 | void ParamTraits<remoting::Monostate>::Log(const param_type&, std::string* l) { |
| 494 | l->append("()"); |
| 495 | } |
| 496 | |
Gary Kacmarcik | 91f5ed4 | 2018-11-29 22:24:14 | [diff] [blame] | 497 | } // namespace IPC |