In the new mojo world where generated bindings use stl string/vector
(or WTF variants), https://crbug.com/624136 , a mojom such as the
image_capture one saying [1]:
TakePhoto(string source_id)
=> (string mime_type, array<uint8> data);
generates a callback with a const std::vector<uint8_t>& for
second parameter, and that prevents std::move()ing things
around and into a base::Callback() (this came up during
https://crrev.com/2166713002/).
Instead of using an evil const_cast, yzshen@ proposed the
following alternative:
<quote>
(1) define a mojom struct
// in mojom:
struct SomeData {
array<uint8> data;
};
(2) create a custom typemapping between SomeData and
std::unique_ptr<std::vector<uint8_t>>, in the typemap config annotate that this
type is move-only:
type_mappings = [ "SomeData=std::unique_ptr<std::vector<uint8_t>>[move_only]" ]
</quote>
[1] https://cs.chromium.org/chromium/src/media/mojo/interfaces/image_capture.mojom?q=image_capture.mojom&sq=package:chromium&dr&l=51
Comment 1 by mcasas@chromium.org
, Jul 20 2016