Index: ui/gfx/mojo/icc_profile_struct_traits.h |
diff --git a/ui/gfx/mojo/icc_profile_struct_traits.h b/ui/gfx/mojo/icc_profile_struct_traits.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ef0bb0361d54ed995196e1c9146d928f3e4515e |
--- /dev/null |
+++ b/ui/gfx/mojo/icc_profile_struct_traits.h |
@@ -0,0 +1,45 @@ |
+// Copyright 2016 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 UI_GFX_MOJO_ICC_PROFILE_STRUCT_TRAITS_H_ |
+#define UI_GFX_MOJO_ICC_PROFILE_STRUCT_TRAITS_H_ |
+ |
+#include <algorithm> |
+#include <memory> |
+ |
+#include "base/memory/ptr_util.h" |
+#include "mojo/public/cpp/bindings/struct_traits.h" |
+#include "ui/gfx/icc_profile.h" |
+#include "ui/gfx/mojo/icc_profile.mojom.h" |
+ |
+namespace mojo { |
+ |
+template <> |
+struct StructTraits<gfx::mojom::ICCProfileDataView, gfx::ICCProfile> { |
+ static bool valid(const gfx::ICCProfile& profile) { return profile.valid_; } |
+ static const std::vector<int8_t>& data(const gfx::ICCProfile& profile, |
+ void* context) { |
+ return *static_cast<std::vector<int8_t>*>(context); |
+ } |
+ static uint64_t id(const gfx::ICCProfile& profile) { return profile.id_; } |
+ |
+ static void* SetUpContext(const gfx::ICCProfile& profile) { |
+ std::unique_ptr<std::vector<int8_t>> data = |
dcheng
2016/09/30 06:30:37
Nit: out of line SetUpContext / TearDownContext.
Ken Rockot(use gerrit already)
2016/09/30 20:02:54
Better: I removed these and eliminated the extra c
|
+ base::MakeUnique<std::vector<int8_t>>(profile.GetData().size()); |
+ std::copy(profile.GetData().begin(), profile.GetData().end(), |
+ data->begin()); |
+ return data.release(); |
+ } |
+ |
+ static void TearDownContext(const gfx::ICCProfile& profile, void* context) { |
+ delete static_cast<std::vector<uint8_t>*>(context); |
+ } |
+ |
+ static bool Read(gfx::mojom::ICCProfileDataView data, |
+ gfx::ICCProfile* profile); |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif // UI_GFX_MOJO_ICC_PROFILE_STRUCT_TRAITS_H_ |