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

Side by Side Diff: remoting/host/chromoting_param_traits.cc

Issue 1659003003: IPC::Message -> base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more mac fix 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
« no previous file with comments | « remoting/host/chromoting_param_traits.h ('k') | ui/events/ipc/latency_info_param_traits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
11 11
12 namespace IPC { 12 namespace IPC {
13 13
14 // static 14 // static
15 void ParamTraits<webrtc::DesktopVector>::Write(Message* m, 15 void ParamTraits<webrtc::DesktopVector>::Write(base::Pickle* m,
16 const webrtc::DesktopVector& p) { 16 const webrtc::DesktopVector& p) {
17 m->WriteInt(p.x()); 17 m->WriteInt(p.x());
18 m->WriteInt(p.y()); 18 m->WriteInt(p.y());
19 } 19 }
20 20
21 // static 21 // static
22 bool ParamTraits<webrtc::DesktopVector>::Read(const Message* m, 22 bool ParamTraits<webrtc::DesktopVector>::Read(const base::Pickle* m,
23 base::PickleIterator* iter, 23 base::PickleIterator* iter,
24 webrtc::DesktopVector* r) { 24 webrtc::DesktopVector* r) {
25 int x, y; 25 int x, y;
26 if (!iter->ReadInt(&x) || !iter->ReadInt(&y)) 26 if (!iter->ReadInt(&x) || !iter->ReadInt(&y))
27 return false; 27 return false;
28 *r = webrtc::DesktopVector(x, y); 28 *r = webrtc::DesktopVector(x, y);
29 return true; 29 return true;
30 } 30 }
31 31
32 // static 32 // static
33 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p, 33 void ParamTraits<webrtc::DesktopVector>::Log(const webrtc::DesktopVector& p,
34 std::string* l) { 34 std::string* l) {
35 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)", 35 l->append(base::StringPrintf("webrtc::DesktopVector(%d, %d)",
36 p.x(), p.y())); 36 p.x(), p.y()));
37 } 37 }
38 38
39 // static 39 // static
40 void ParamTraits<webrtc::DesktopSize>::Write(Message* m, 40 void ParamTraits<webrtc::DesktopSize>::Write(base::Pickle* m,
41 const webrtc::DesktopSize& p) { 41 const webrtc::DesktopSize& p) {
42 m->WriteInt(p.width()); 42 m->WriteInt(p.width());
43 m->WriteInt(p.height()); 43 m->WriteInt(p.height());
44 } 44 }
45 45
46 // static 46 // static
47 bool ParamTraits<webrtc::DesktopSize>::Read(const Message* m, 47 bool ParamTraits<webrtc::DesktopSize>::Read(const base::Pickle* m,
48 base::PickleIterator* iter, 48 base::PickleIterator* iter,
49 webrtc::DesktopSize* r) { 49 webrtc::DesktopSize* r) {
50 int width, height; 50 int width, height;
51 if (!iter->ReadInt(&width) || !iter->ReadInt(&height)) 51 if (!iter->ReadInt(&width) || !iter->ReadInt(&height))
52 return false; 52 return false;
53 *r = webrtc::DesktopSize(width, height); 53 *r = webrtc::DesktopSize(width, height);
54 return true; 54 return true;
55 } 55 }
56 56
57 // static 57 // static
58 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p, 58 void ParamTraits<webrtc::DesktopSize>::Log(const webrtc::DesktopSize& p,
59 std::string* l) { 59 std::string* l) {
60 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)", 60 l->append(base::StringPrintf("webrtc::DesktopSize(%d, %d)",
61 p.width(), p.height())); 61 p.width(), p.height()));
62 } 62 }
63 63
64 // static 64 // static
65 void ParamTraits<webrtc::DesktopRect>::Write(Message* m, 65 void ParamTraits<webrtc::DesktopRect>::Write(base::Pickle* m,
66 const webrtc::DesktopRect& p) { 66 const webrtc::DesktopRect& p) {
67 m->WriteInt(p.left()); 67 m->WriteInt(p.left());
68 m->WriteInt(p.top()); 68 m->WriteInt(p.top());
69 m->WriteInt(p.right()); 69 m->WriteInt(p.right());
70 m->WriteInt(p.bottom()); 70 m->WriteInt(p.bottom());
71 } 71 }
72 72
73 // static 73 // static
74 bool ParamTraits<webrtc::DesktopRect>::Read(const Message* m, 74 bool ParamTraits<webrtc::DesktopRect>::Read(const base::Pickle* m,
75 base::PickleIterator* iter, 75 base::PickleIterator* iter,
76 webrtc::DesktopRect* r) { 76 webrtc::DesktopRect* r) {
77 int left, right, top, bottom; 77 int left, right, top, bottom;
78 if (!iter->ReadInt(&left) || !iter->ReadInt(&top) || 78 if (!iter->ReadInt(&left) || !iter->ReadInt(&top) ||
79 !iter->ReadInt(&right) || !iter->ReadInt(&bottom)) { 79 !iter->ReadInt(&right) || !iter->ReadInt(&bottom)) {
80 return false; 80 return false;
81 } 81 }
82 *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom); 82 *r = webrtc::DesktopRect::MakeLTRB(left, top, right, bottom);
83 return true; 83 return true;
84 } 84 }
85 85
86 // static 86 // static
87 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p, 87 void ParamTraits<webrtc::DesktopRect>::Log(const webrtc::DesktopRect& p,
88 std::string* l) { 88 std::string* l) {
89 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)", 89 l->append(base::StringPrintf("webrtc::DesktopRect(%d, %d, %d, %d)",
90 p.left(), p.top(), p.right(), p.bottom())); 90 p.left(), p.top(), p.right(), p.bottom()));
91 } 91 }
92 92
93 // static 93 // static
94 void ParamTraits<webrtc::MouseCursor>::Write( 94 void ParamTraits<webrtc::MouseCursor>::Write(base::Pickle* m,
95 Message* m, 95 const webrtc::MouseCursor& p) {
96 const webrtc::MouseCursor& p) {
97 ParamTraits<webrtc::DesktopSize>::Write(m, p.image()->size()); 96 ParamTraits<webrtc::DesktopSize>::Write(m, p.image()->size());
98 97
99 // Data is serialized in such a way that size is exactly width * height * 98 // Data is serialized in such a way that size is exactly width * height *
100 // |kBytesPerPixel|. 99 // |kBytesPerPixel|.
101 std::string data; 100 std::string data;
102 uint8_t* current_row = p.image()->data(); 101 uint8_t* current_row = p.image()->data();
103 for (int y = 0; y < p.image()->size().height(); ++y) { 102 for (int y = 0; y < p.image()->size().height(); ++y) {
104 data.append(current_row, 103 data.append(current_row,
105 current_row + p.image()->size().width() * 104 current_row + p.image()->size().width() *
106 webrtc::DesktopFrame::kBytesPerPixel); 105 webrtc::DesktopFrame::kBytesPerPixel);
107 current_row += p.image()->stride(); 106 current_row += p.image()->stride();
108 } 107 }
109 m->WriteData(reinterpret_cast<const char*>(p.image()->data()), data.size()); 108 m->WriteData(reinterpret_cast<const char*>(p.image()->data()), data.size());
110 109
111 ParamTraits<webrtc::DesktopVector>::Write(m, p.hotspot()); 110 ParamTraits<webrtc::DesktopVector>::Write(m, p.hotspot());
112 } 111 }
113 112
114 // static 113 // static
115 bool ParamTraits<webrtc::MouseCursor>::Read(const Message* m, 114 bool ParamTraits<webrtc::MouseCursor>::Read(const base::Pickle* m,
116 base::PickleIterator* iter, 115 base::PickleIterator* iter,
117 webrtc::MouseCursor* r) { 116 webrtc::MouseCursor* r) {
118 webrtc::DesktopSize size; 117 webrtc::DesktopSize size;
119 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || 118 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) ||
120 size.width() <= 0 || size.width() > (SHRT_MAX / 2) || 119 size.width() <= 0 || size.width() > (SHRT_MAX / 2) ||
121 size.height() <= 0 || size.height() > (SHRT_MAX / 2)) { 120 size.height() <= 0 || size.height() > (SHRT_MAX / 2)) {
122 return false; 121 return false;
123 } 122 }
124 123
125 const int expected_length = 124 const int expected_length =
(...skipping 22 matching lines...) Expand all
148 std::string* l) { 147 std::string* l) {
149 l->append(base::StringPrintf( 148 l->append(base::StringPrintf(
150 "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}", 149 "webrtc::DesktopRect{image(%d, %d), hotspot(%d, %d)}",
151 p.image()->size().width(), p.image()->size().height(), 150 p.image()->size().width(), p.image()->size().height(),
152 p.hotspot().x(), p.hotspot().y())); 151 p.hotspot().x(), p.hotspot().y()));
153 } 152 }
154 153
155 154
156 // static 155 // static
157 void ParamTraits<remoting::ScreenResolution>::Write( 156 void ParamTraits<remoting::ScreenResolution>::Write(
158 Message* m, 157 base::Pickle* m,
159 const remoting::ScreenResolution& p) { 158 const remoting::ScreenResolution& p) {
160 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions()); 159 ParamTraits<webrtc::DesktopSize>::Write(m, p.dimensions());
161 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi()); 160 ParamTraits<webrtc::DesktopVector>::Write(m, p.dpi());
162 } 161 }
163 162
164 // static 163 // static
165 bool ParamTraits<remoting::ScreenResolution>::Read( 164 bool ParamTraits<remoting::ScreenResolution>::Read(
166 const Message* m, 165 const base::Pickle* m,
167 base::PickleIterator* iter, 166 base::PickleIterator* iter,
168 remoting::ScreenResolution* r) { 167 remoting::ScreenResolution* r) {
169 webrtc::DesktopSize size; 168 webrtc::DesktopSize size;
170 webrtc::DesktopVector dpi; 169 webrtc::DesktopVector dpi;
171 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) || 170 if (!ParamTraits<webrtc::DesktopSize>::Read(m, iter, &size) ||
172 !ParamTraits<webrtc::DesktopVector>::Read(m, iter, &dpi)) { 171 !ParamTraits<webrtc::DesktopVector>::Read(m, iter, &dpi)) {
173 return false; 172 return false;
174 } 173 }
175 if (size.width() < 0 || size.height() < 0 || 174 if (size.width() < 0 || size.height() < 0 ||
176 dpi.x() < 0 || dpi.y() < 0) { 175 dpi.x() < 0 || dpi.y() < 0) {
177 return false; 176 return false;
178 } 177 }
179 *r = remoting::ScreenResolution(size, dpi); 178 *r = remoting::ScreenResolution(size, dpi);
180 return true; 179 return true;
181 } 180 }
182 181
183 // static 182 // static
184 void ParamTraits<remoting::ScreenResolution>::Log( 183 void ParamTraits<remoting::ScreenResolution>::Log(
185 const remoting::ScreenResolution& p, 184 const remoting::ScreenResolution& p,
186 std::string* l) { 185 std::string* l) {
187 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)", 186 l->append(base::StringPrintf("webrtc::ScreenResolution(%d, %d, %d, %d)",
188 p.dimensions().width(), p.dimensions().height(), 187 p.dimensions().width(), p.dimensions().height(),
189 p.dpi().x(), p.dpi().y())); 188 p.dpi().x(), p.dpi().y()));
190 } 189 }
191 190
192 } // namespace IPC 191 } // namespace IPC
193 192
OLDNEW
« no previous file with comments | « remoting/host/chromoting_param_traits.h ('k') | ui/events/ipc/latency_info_param_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698