OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_COMMON_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 5 #ifndef CHROME_COMMON_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
6 #define CHROME_COMMON_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 6 #define CHROME_COMMON_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/common/media_router/discovery/media_sink_internal.h" | 10 #include "chrome/common/media_router/discovery/media_sink_internal.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 const media_router::CastSinkExtraData& extra_data) { | 150 const media_router::CastSinkExtraData& extra_data) { |
151 return extra_data.cast_channel_id; | 151 return extra_data.cast_channel_id; |
152 } | 152 } |
153 | 153 |
154 static bool Read(media_router::mojom::CastMediaSinkDataView data, | 154 static bool Read(media_router::mojom::CastMediaSinkDataView data, |
155 media_router::CastSinkExtraData* out); | 155 media_router::CastSinkExtraData* out); |
156 }; | 156 }; |
157 | 157 |
158 template <> | 158 template <> |
159 struct StructTraits<media_router::mojom::RouteMessageDataView, | 159 struct StructTraits<media_router::mojom::RouteMessageDataView, |
160 media_router::RouteMessage> { | 160 content::PresentationConnectionMessage> { |
161 static media_router::mojom::RouteMessage::Type type( | 161 static media_router::mojom::RouteMessage::Type type( |
162 const media_router::RouteMessage& msg) { | 162 const content::PresentationConnectionMessage& msg) { |
163 switch (msg.type) { | 163 if (msg.message) |
164 case media_router::RouteMessage::TEXT: | 164 return media_router::mojom::RouteMessage::Type::TEXT; |
165 return media_router::mojom::RouteMessage::Type::TEXT; | 165 else if (msg.data) |
166 case media_router::RouteMessage::BINARY: | 166 return media_router::mojom::RouteMessage::Type::BINARY; |
167 return media_router::mojom::RouteMessage::Type::BINARY; | |
168 } | |
169 NOTREACHED(); | 167 NOTREACHED(); |
170 return media_router::mojom::RouteMessage::Type::TEXT; | 168 return media_router::mojom::RouteMessage::Type::TEXT; |
171 } | 169 } |
172 | 170 |
173 static const base::Optional<std::string>& message( | 171 static const base::Optional<std::string>& message( |
174 const media_router::RouteMessage& msg) { | 172 const content::PresentationConnectionMessage& msg) { |
175 return msg.text; | 173 return msg.message; |
176 } | 174 } |
177 | 175 |
178 static const base::Optional<std::vector<uint8_t>>& data( | 176 static const base::Optional<std::vector<uint8_t>>& data( |
179 const media_router::RouteMessage& msg) { | 177 const content::PresentationConnectionMessage& msg) { |
180 return msg.binary; | 178 return msg.data; |
181 } | 179 } |
182 | 180 |
183 static bool Read(media_router::mojom::RouteMessageDataView data, | 181 static bool Read(media_router::mojom::RouteMessageDataView data, |
184 media_router::RouteMessage* out) { | 182 content::PresentationConnectionMessage* out) { |
185 media_router::mojom::RouteMessage::Type type; | 183 media_router::mojom::RouteMessage::Type type; |
186 if (!data.ReadType(&type)) | 184 if (!data.ReadType(&type)) |
187 return false; | 185 return false; |
188 switch (type) { | 186 switch (type) { |
189 case media_router::mojom::RouteMessage::Type::TEXT: { | 187 case media_router::mojom::RouteMessage::Type::TEXT: { |
190 out->type = media_router::RouteMessage::TEXT; | |
191 base::Optional<std::string> text; | 188 base::Optional<std::string> text; |
192 if (!data.ReadMessage(&text) || !text) | 189 if (!data.ReadMessage(&text) || !text) |
dcheng
2017/07/06 08:18:05
Here and below, just read directly into out->messa
imcheng
2017/07/06 20:26:49
Done.
| |
193 return false; | 190 return false; |
194 out->text = std::move(text); | 191 out->message = std::move(text); |
195 break; | 192 break; |
196 } | 193 } |
197 case media_router::mojom::RouteMessage::Type::BINARY: { | 194 case media_router::mojom::RouteMessage::Type::BINARY: { |
198 out->type = media_router::RouteMessage::BINARY; | |
199 base::Optional<std::vector<uint8_t>> binary; | 195 base::Optional<std::vector<uint8_t>> binary; |
200 if (!data.ReadData(&binary) || !binary) | 196 if (!data.ReadData(&binary) || !binary) |
201 return false; | 197 return false; |
202 out->binary = std::move(binary); | 198 out->data = std::move(binary); |
203 break; | 199 break; |
204 } | 200 } |
205 default: | 201 default: |
dcheng
2017/07/06 08:18:05
Also, consider removing default: that way the comp
imcheng
2017/07/06 20:26:49
Done.
| |
206 return false; | 202 return false; |
207 } | 203 } |
208 return true; | 204 return true; |
209 } | 205 } |
210 }; | 206 }; |
211 | 207 |
212 template <> | 208 template <> |
213 struct StructTraits<media_router::mojom::IssueDataView, | 209 struct StructTraits<media_router::mojom::IssueDataView, |
214 media_router::IssueInfo> { | 210 media_router::IssueInfo> { |
215 static bool Read(media_router::mojom::IssueDataView data, | 211 static bool Read(media_router::mojom::IssueDataView data, |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 *output = media_router::RouteRequestResult::CANCELLED; | 562 *output = media_router::RouteRequestResult::CANCELLED; |
567 return true; | 563 return true; |
568 } | 564 } |
569 return false; | 565 return false; |
570 } | 566 } |
571 }; | 567 }; |
572 | 568 |
573 } // namespace mojo | 569 } // namespace mojo |
574 | 570 |
575 #endif // CHROME_COMMON_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ | 571 #endif // CHROME_COMMON_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_STRUCT_TRAITS_H_ |
OLD | NEW |