Chromium Code Reviews| Index: chrome/common/extensions/media_parser_struct_traits.h |
| diff --git a/chrome/common/extensions/media_parser_struct_traits.h b/chrome/common/extensions/media_parser_struct_traits.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bfdbdf23e303a4fa526ed7ba9c271b8f0f19d44d |
| --- /dev/null |
| +++ b/chrome/common/extensions/media_parser_struct_traits.h |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_COMMON_EXTENSIONS_MEDIA_PARSER_STRUCT_TRAITS_H_ |
| +#define CHROME_COMMON_EXTENSIONS_MEDIA_PARSER_STRUCT_TRAITS_H_ |
| + |
| +#include <string> |
| + |
| +#include "chrome/common/extensions/media_parser.mojom.h" |
| +#include "chrome/common/media_galleries/metadata_types.h" |
| +#include "mojo/public/cpp/bindings/array_data_view.h" |
| +#include "mojo/public/cpp/bindings/array_traits_carray.h" |
| + |
| +namespace mojo { |
| + |
| +template <> |
| +struct StructTraits<extensions::mojom::AttachedImageDataView, |
| + ::metadata::AttachedImage> { |
| + static const std::string& type(const ::metadata::AttachedImage& image) { |
| + return image.type; |
| + } |
| + |
| + static ConstCArray<uint8_t> data(const ::metadata::AttachedImage& image) { |
| + return ConstCArray<uint8_t>( |
| + image.data.size(), reinterpret_cast<const uint8_t*>(image.data.data())); |
|
dcheng
2017/01/11 09:09:59
Mind adding a TODO to pass the actual image data a
Noel Gordon
2017/01/12 14:11:20
Good idea, done.
|
| + } |
| + |
| + static bool Read(extensions::mojom::AttachedImageDataView view, |
| + ::metadata::AttachedImage* out) { |
|
dcheng
2017/01/11 09:09:59
Nit: please out-of-line this into a .cc file
Noel Gordon
2017/01/12 14:11:20
Done. Added chrome/common/extensions/media_parser
|
| + if (!view.ReadType(&out->type)) |
| + return false; |
| + |
| + ArrayDataView<uint8_t> data; |
| + view.GetDataDataView(&data); |
| + |
| + out->data.assign(reinterpret_cast<const char*>(data.data()), data.size()); |
| + return true; |
| + } |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // CHROME_COMMON_EXTENSIONS_MEDIA_PARSER_STRUCT_TRAITS_H_ |