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

Side by Side Diff: content/common/presentation/presentation_struct_traits.h

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Fix compile error in presentation_connection_message Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ 5 #ifndef CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_
6 #define CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ 6 #define CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/optional.h"
11 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "content/public/common/presentation_connection_message.h"
12 #include "content/public/common/presentation_session.h" 15 #include "content/public/common/presentation_session.h"
13 #include "mojo/common/common_custom_types_struct_traits.h" 16 #include "mojo/common/common_custom_types_struct_traits.h"
14 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" 17 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
15 #include "url/mojo/url.mojom.h" 18 #include "url/mojo/url.mojom.h"
16 19
17 namespace mojo { 20 namespace mojo {
18 21
19 template <> 22 template <>
20 struct EnumTraits<blink::mojom::PresentationErrorType, 23 struct EnumTraits<blink::mojom::PresentationErrorType,
21 content::PresentationErrorType> { 24 content::PresentationErrorType> {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return false; 193 return false;
191 194
192 if (!base::IsStringUTF8(out->message) || 195 if (!base::IsStringUTF8(out->message) ||
193 out->message.length() > content::PresentationError::kMaxMessageLength) 196 out->message.length() > content::PresentationError::kMaxMessageLength)
194 return false; 197 return false;
195 198
196 return true; 199 return true;
197 } 200 }
198 }; 201 };
199 202
203 template <>
204 struct UnionTraits<blink::mojom::PresentationConnectionMessageDataView,
205 content::PresentationConnectionMessage> {
206 static blink::mojom::PresentationConnectionMessageDataView::Tag GetTag(
207 const content::PresentationConnectionMessage& message) {
208 return message.is_binary()
209 ? blink::mojom::PresentationConnectionMessageDataView::Tag::DATA
210 : blink::mojom::PresentationConnectionMessageDataView::Tag::
211 MESSAGE;
212 }
213
214 static const std::string& message(
215 const content::PresentationConnectionMessage& message) {
216 DCHECK(!message.is_binary());
217 return message.message.value();
218 }
219
220 static const std::vector<uint8_t>& data(
221 const content::PresentationConnectionMessage& message) {
222 DCHECK(message.is_binary());
223 return message.data.value();
224 }
225
226 static bool Read(blink::mojom::PresentationConnectionMessageDataView data,
227 content::PresentationConnectionMessage* out) {
dcheng 2017/02/25 07:17:27 Please out-of-line this method.
228 if (data.is_message()) {
229 out->message = std::string();
dcheng 2017/02/25 07:17:27 This is unnecessary.
230 if (!data.ReadMessage(&(out->message)))
231 return false;
232
233 if (out->message->length() >
234 content::kMaxPresentationConnectionMessageSize)
235 return false;
236 } else {
237 out->data = std::vector<uint8_t>();
dcheng 2017/02/25 07:17:27 Nit: please omit this.
238 if (!data.ReadData(&(out->data)))
239 return false;
240
241 if (out->data->size() > content::kMaxPresentationConnectionMessageSize)
242 return false;
243 }
244
245 return true;
246 }
247 };
248
200 } // namespace mojo 249 } // namespace mojo
201 250
202 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ 251 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698