Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / common / safe_browsing / protobuf_message_param_traits.h
blob46890e41aff2d4f20ba185605caad9b544f0bf4e
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.
5 #ifndef CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
6 #define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
8 #include <string>
10 #include "base/pickle.h"
11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_param_traits.h"
13 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
15 namespace IPC {
17 template <class Element>
18 struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> {
19 typedef google::protobuf::RepeatedPtrField<Element> param_type;
21 static void Write(Message* m, const param_type& p) {
22 WriteParam(m, p.size());
23 for (const auto& element : p)
24 WriteParam(m, element);
27 static bool Read(const Message* m,
28 base::PickleIterator* iter,
29 param_type* p) {
30 int size;
31 if (!iter->ReadLength(&size) || size < 0)
32 return false;
33 if (INT_MAX / static_cast<int>(sizeof(void*)) <= size)
34 return false;
35 p->Clear();
36 p->Reserve(size);
37 while (size--) {
38 if (!ReadParam(m, iter, p->Add()))
39 return false;
41 return true;
44 static void Log(const param_type& p, std::string* l) {
45 bool logged_first = false;
46 for (const auto& element : p) {
47 if (logged_first)
48 l->push_back(' ');
49 else
50 logged_first = true;
51 LogParam(element, l);
56 } // namespace IPC
58 #endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_