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

Unified Diff: chrome/common/safe_browsing/protobuf_message_param_traits.h

Issue 1004323003: Add support for sending protobuf messages over IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@zip
Patch Set: remove todo and enable for cros Created 5 years, 9 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
Index: chrome/common/safe_browsing/protobuf_message_param_traits.h
diff --git a/chrome/common/safe_browsing/protobuf_message_param_traits.h b/chrome/common/safe_browsing/protobuf_message_param_traits.h
new file mode 100644
index 0000000000000000000000000000000000000000..b2e5ef4490b79c52892a7ef728a9664c1396eaab
--- /dev/null
+++ b/chrome/common/safe_browsing/protobuf_message_param_traits.h
@@ -0,0 +1,56 @@
+// Copyright 2015 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_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
+#define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
+
+#include <string>
+
+#include "base/pickle.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_param_traits.h"
+#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
+
+namespace IPC {
+
+template <class Element>
+struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> {
+ typedef google::protobuf::RepeatedPtrField<Element> param_type;
+
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.size());
+ for (const auto& element : p)
+ WriteParam(m, element);
+ }
+
+ static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
+ int size;
+ if (!iter->ReadLength(&size) || size < 0)
+ return false;
+ if (INT_MAX / static_cast<int>(sizeof(void*)) <= size)
+ return false;
+ p->Clear();
+ p->Reserve(size);
+ while (size--) {
+ if (!ReadParam(m, iter, p->Add()))
+ return false;
+ }
+ return true;
+ }
+
+ static void Log(const param_type& p, std::string* l) {
+ bool logged_first = false;
+ for (const auto& element : p) {
+ if (logged_first)
+ l->push_back(' ');
+ else
+ logged_first = true;
+ LogParam(element, l);
+ }
+ }
+};
+
+} // namespace IPC
+
+#endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_

Powered by Google App Engine
This is Rietveld 408576698