OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/host/chromoting_param_traits.h" | 5 #include "remoting/host/chromoting_param_traits.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "ipc/ipc_message_utils.h" | 10 #include "ipc/ipc_message_utils.h" |
11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
12 | 12 |
13 namespace IPC { | 13 namespace IPC { |
14 | 14 |
15 // static | 15 // static |
| 16 void ParamTraits<webrtc::DesktopVector>::GetSize(base::PickleSizer* s, |
| 17 const param_type& p) { |
| 18 GetParamSize(s, p.x()); |
| 19 GetParamSize(s, p.y()); |
| 20 } |
| 21 |
| 22 // static |
16 void ParamTraits<webrtc::DesktopVector>::Write(base::Pickle* m, | 23 void ParamTraits<webrtc::DesktopVector>::Write(base::Pickle* m, |
17 const webrtc::DesktopVector& p) { | 24 const webrtc::DesktopVector& p) { |
18 m->WriteInt(p.x()); | 25 m->WriteInt(p.x()); |
19 m->WriteInt(p.y()); | 26 m->WriteInt(p.y()); |
20 } | 27 } |
21 | 28 |
22 // static | 29 // static |
23 bool ParamTraits<webrtc::DesktopVector>::Read(const base::Pickle* m, | 30 bool ParamTraits<webrtc::DesktopVector>::Read(const base::Pickle* m, |
24 base::PickleIterator* iter, | 31 base::PickleIterator* iter, |
25 webrtc::DesktopVector* r) { | 32 webrtc::DesktopVector* r) { |
26 int x, y; | 33 int x, y; |
27 if (!iter->ReadInt(&x) || !iter->ReadInt(&y)) | 34 if (!iter->ReadInt(&x) || !iter->ReadInt(&y)) |
28 return false; | 35 return false; |
29 *r = webrtc::DesktopVector(x, y); | 36 *r = webrtc::DesktopVector(x, y); |
30 return true; | 37 return true; |
31 } | 38 } |
32 | 39 |
33 // static | 40 // static |
34 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p, | 41 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p, |
35 std::string* l) { | 42 std::string* l) { |
36 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)", | 43 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)", |
37 p.x(), p.y())); | 44 p.x(), p.y())); |
38 } | 45 } |
39 | 46 |
40 // static | 47 // static |
| 48 void ParamTraits<webrtc::DesktopSize>::GetSize(base::PickleSizer* s, |
| 49 const param_type& p) { |
| 50 GetParamSize(s, p.width()); |
| 51 GetParamSize(s, p.height()); |
| 52 } |
| 53 |
| 54 // static |
41 void ParamTraits<webrtc::DesktopSize>::Write(base::Pickle* m, | 55 void ParamTraits<webrtc::DesktopSize>::Write(base::Pickle* m, |
42 const webrtc::DesktopSize& p) { | 56 const webrtc::DesktopSize& p) { |
43 m->WriteInt(p.width()); | 57 m->WriteInt(p.width()); |
44 m->WriteInt(p.height()); | 58 m->WriteInt(p.height()); |
45 } | 59 } |
46 | 60 |
47 // static | 61 // static |
48 bool ParamTraits<webrtc::DesktopSize>::Read(const base::Pickle* m, | 62 bool ParamTraits<webrtc::DesktopSize>::Read(const base::Pickle* m, |
49 base::PickleIterator* iter, | 63 base::PickleIterator* iter, |
50 webrtc::DesktopSize* r) { | 64 webrtc::DesktopSize* r) { |
51 int width, height; | 65 int width, height; |
52 if (!iter->ReadInt(&width) || !iter->ReadInt(&height)) | 66 if (!iter->ReadInt(&width) || !iter->ReadInt(&height)) |
53 return false; | 67 return false; |
54 *r = webrtc::DesktopSize(width, height); | 68 *r = webrtc::DesktopSize(width, height); |
55 return true; | 69 return true; |
56 } | 70 } |
57 | 71 |
58 // static | 72 // static |
59 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p, | 73 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p, |
60 std::string* l) { | 74 std::string* l) { |
61 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)", | 75 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)", |
62 p.width(), p.height())); | 76 p.width(), p.height())); |
63 } | 77 } |
64 | 78 |
65 // static | 79 // static |
| 80 void ParamTraits<webrtc::DesktopRect>::GetSize(base::PickleSizer* s, |
| 81 const param_type& p) { |
| 82 GetParamSize(s, p.left()); |
| 83 GetParamSize(s, p.top()); |
| 84 GetParamSize(s, p.right()); |
| 85 GetParamSize(s, p.bottom()); |
| 86 } |
| 87 |
| 88 // static |
66 void ParamTraits<webrtc::DesktopRect>::Write(base::Pickle* m, | 89 void ParamTraits<webrtc::DesktopRect>::Write(base::Pickle* m, |
67 const webrtc::DesktopRect& p) { | 90 const webrtc::DesktopRect& p) { |
68 m->WriteInt(p.left()); | 91 m->WriteInt(p.left()); |
69 m->WriteInt(p.top()); | 92 m->WriteInt(p.top()); |
70 m->WriteInt(p.right()); | 93 m->WriteInt(p.right()); |
71 m->WriteInt(p.bottom()); | 94 m->WriteInt(p.bottom()); |
72 } | 95 } |
73 | 96 |
74 // static | 97 // static |
75 bool ParamTraits<webrtc::DesktopRect>::Read(const base::Pickle* m, | 98 bool ParamTraits<webrtc::DesktopRect>::Read(const base::Pickle* m, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // static | 206 // static |
184 void ParamTraits<remoting::ScreenResolution>::Log( | 207 void ParamTraits<remoting::ScreenResolution>::Log( |
185 const remoting::ScreenResolution& p, | 208 const remoting::ScreenResolution& p, |
186 std::string* l) { | 209 std::string* l) { |
187 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", | 210 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", |
188 p.dimensions().width(), p.dimensions().height(), | 211 p.dimensions().width(), p.dimensions().height(), |
189 p.dpi().x(), p.dpi().y())); | 212 p.dpi().x(), p.dpi().y())); |
190 } | 213 } |
191 | 214 |
192 // static | 215 // static |
| 216 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s, |
| 217 const param_type& p) { |
| 218 GetParamSize(s, p.bytes()); |
| 219 } |
| 220 |
| 221 // static |
193 void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) { | 222 void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) { |
194 WriteParam(m, p.bytes()); | 223 WriteParam(m, p.bytes()); |
195 } | 224 } |
196 | 225 |
197 // static | 226 // static |
198 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, | 227 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, |
199 base::PickleIterator* iter, | 228 base::PickleIterator* iter, |
200 param_type* p) { | 229 param_type* p) { |
201 std::vector<uint8_t> bytes; | 230 std::vector<uint8_t> bytes; |
202 if (!ReadParam(m, iter, &bytes)) | 231 if (!ReadParam(m, iter, &bytes)) |
203 return false; | 232 return false; |
204 | 233 |
205 net::IPAddress address(bytes); | 234 net::IPAddress address(bytes); |
206 if (address.empty() || address.IsValid()) { | 235 if (address.empty() || address.IsValid()) { |
207 *p = address; | 236 *p = address; |
208 return true; | 237 return true; |
209 } | 238 } |
210 return false; | 239 return false; |
211 } | 240 } |
212 | 241 |
213 // static | 242 // static |
214 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) { | 243 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) { |
215 l->append("IPAddress:" + (p.empty() ? "(empty)" : p.ToString())); | 244 l->append("IPAddress:" + (p.empty() ? "(empty)" : p.ToString())); |
216 } | 245 } |
217 | 246 |
218 // static | 247 // static |
| 248 void ParamTraits<net::IPEndPoint>::GetSize(base::PickleSizer* s, |
| 249 const param_type& p) { |
| 250 GetParamSize(s, p.address()); |
| 251 GetParamSize(s, p.port()); |
| 252 } |
| 253 |
| 254 // static |
219 void ParamTraits<net::IPEndPoint>::Write(base::Pickle* m, const param_type& p) { | 255 void ParamTraits<net::IPEndPoint>::Write(base::Pickle* m, const param_type& p) { |
220 WriteParam(m, p.address()); | 256 WriteParam(m, p.address()); |
221 WriteParam(m, p.port()); | 257 WriteParam(m, p.port()); |
222 } | 258 } |
223 | 259 |
224 // static | 260 // static |
225 bool ParamTraits<net::IPEndPoint>::Read(const base::Pickle* m, | 261 bool ParamTraits<net::IPEndPoint>::Read(const base::Pickle* m, |
226 base::PickleIterator* iter, | 262 base::PickleIterator* iter, |
227 param_type* p) { | 263 param_type* p) { |
228 net::IPAddress address; | 264 net::IPAddress address; |
229 uint16_t port; | 265 uint16_t port; |
230 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) | 266 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) |
231 return false; | 267 return false; |
232 | 268 |
233 *p = net::IPEndPoint(address, port); | 269 *p = net::IPEndPoint(address, port); |
234 return true; | 270 return true; |
235 } | 271 } |
236 | 272 |
237 // static | 273 // static |
238 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { | 274 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { |
239 l->append("IPEndPoint: " + p.ToString()); | 275 l->append("IPEndPoint: " + p.ToString()); |
240 } | 276 } |
241 | 277 |
242 } // namespace IPC | 278 } // namespace IPC |
243 | 279 |
OLD | NEW |