1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_PICKLED_TYPES_CHROMIUM_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_PICKLED_TYPES_CHROMIUM_H_ 7 8 #include <stddef.h> 9 10 #include <string> 11 12 #include "base/macros.h" 13 #include "ipc/ipc_message_macros.h" 14 #include "ipc/ipc_param_traits.h" 15 16 namespace base { 17 class Pickle; 18 class PickleIterator; 19 class PickleSizer; 20 } 21 22 namespace mojo { 23 namespace test { 24 25 // Implementation of types with IPC::ParamTraits for consumers in the greater 26 // Chromium tree. 27 28 enum class PickledEnumChromium { VALUE_0, VALUE_1, VALUE_2 }; 29 30 class PickledStructChromium { 31 public: 32 PickledStructChromium(); 33 PickledStructChromium(int foo, int bar); 34 PickledStructChromium(PickledStructChromium&& other) = default; 35 ~PickledStructChromium(); 36 37 PickledStructChromium& operator=(PickledStructChromium&& other) = default; 38 39 int foo() const { return foo_; } 40 void set_foo(int foo) { foo_ = foo; } 41 42 int bar() const { return bar_; } 43 void set_bar(int bar) { bar_ = bar; } 44 45 // The |baz| field should never be serialized. 46 int baz() const { return baz_; } 47 void set_baz(int baz) { baz_ = baz; } 48 49 private: 50 int foo_ = 0; 51 int bar_ = 0; 52 int baz_ = 0; 53 54 DISALLOW_COPY_AND_ASSIGN(PickledStructChromium); 55 }; 56 57 bool operator==(const PickledStructChromium& a, const PickledStructChromium& b); 58 59 } // namespace test 60 } // namespace mojo 61 62 namespace IPC { 63 64 template <> 65 struct ParamTraits<mojo::test::PickledStructChromium> { 66 using param_type = mojo::test::PickledStructChromium; 67 68 static void GetSize(base::PickleSizer* sizer, const param_type& p); 69 static void Write(base::Pickle* m, const param_type& p); 70 static bool Read(const base::Pickle* m, 71 base::PickleIterator* iter, 72 param_type* r); 73 static void Log(const param_type& p, std::string* l) {} 74 }; 75 76 } // namespace IPC 77 78 IPC_ENUM_TRAITS_MAX_VALUE(mojo::test::PickledEnumChromium, 79 mojo::test::PickledEnumChromium::VALUE_2) 80 81 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_PICKLED_TYPES_CHROMIUM_H_ 82