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

Unified Diff: ipc/ipc_message_utils.h

Issue 2098823003: Add IPC serialization support for base::Optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_message_utils.h
diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h
index 98485493511f279822dcf4a0907a041187a13969..6712d3ca69363e8a1e48a416304a1e54bb0c55d9 100644
--- a/ipc/ipc_message_utils.h
+++ b/ipc/ipc_message_utils.h
@@ -22,6 +22,7 @@
#include "base/files/file.h"
#include "base/format_macros.h"
#include "base/memory/scoped_vector.h"
+#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -374,7 +375,7 @@ struct IPC_EXPORT ParamTraits<std::vector<bool> > {
};
template <class P>
-struct ParamTraits<std::vector<P> > {
+struct ParamTraits<std::vector<P>> {
typedef std::vector<P> param_type;
static void GetSize(base::PickleSizer* sizer, const param_type& p) {
GetParamSize(sizer, static_cast<int>(p.size()));
@@ -984,6 +985,43 @@ struct ParamTraits<std::unique_ptr<P>> {
}
};
+template <class P>
+struct ParamTraits<base::Optional<P>> {
+ typedef base::Optional<P> param_type;
+ static void GetSize(base::PickleSizer* sizer, const param_type& p) {
+ const bool is_set = static_cast<bool>(p);
+ GetParamSize(sizer, is_set);
+ if (is_set)
+ GetParamSize(sizer, p.value());
+ }
+ static void Write(base::Pickle* m, const param_type& p) {
+ const bool is_set = static_cast<bool>(p);
+ WriteParam(m, is_set);
+ if (is_set)
+ WriteParam(m, p.value());
+ }
+ static bool Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r) {
+ bool is_set = false;
+ if (!iter->ReadBool(&is_set))
+ return false;
+ if (is_set) {
+ P value;
+ if (!ReadParam(m, iter, &value))
+ return false;
+ *r = std::move(value);
+ }
+ return true;
+ }
+ static void Log(const param_type& p, std::string* l) {
+ if (p)
+ LogParam(p.value(), l);
+ else
+ l->append("(unset)");
+ }
+};
+
// IPC types ParamTraits -------------------------------------------------------
// A ChannelHandle is basically a platform-inspecific wrapper around the
« no previous file with comments | « no previous file | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698