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

Side by Side Diff: chrome/common/safe_browsing/protobuf_message_param_traits.h

Issue 1149113006: Move Pickle to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ 5 #ifndef CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
6 #define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ 6 #define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/pickle.h" 10 #include "base/pickle.h"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_param_traits.h" 12 #include "ipc/ipc_param_traits.h"
13 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" 13 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
14 14
15 namespace IPC { 15 namespace IPC {
16 16
17 template <class Element> 17 template <class Element>
18 struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> { 18 struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> {
19 typedef google::protobuf::RepeatedPtrField<Element> param_type; 19 typedef google::protobuf::RepeatedPtrField<Element> param_type;
20 20
21 static void Write(Message* m, const param_type& p) { 21 static void Write(Message* m, const param_type& p) {
22 WriteParam(m, p.size()); 22 WriteParam(m, p.size());
23 for (const auto& element : p) 23 for (const auto& element : p)
24 WriteParam(m, element); 24 WriteParam(m, element);
25 } 25 }
26 26
27 static bool Read(const Message* m, PickleIterator* iter, param_type* p) { 27 static bool Read(const Message* m,
28 base::PickleIterator* iter,
29 param_type* p) {
28 int size; 30 int size;
29 if (!iter->ReadLength(&size) || size < 0) 31 if (!iter->ReadLength(&size) || size < 0)
30 return false; 32 return false;
31 if (INT_MAX / static_cast<int>(sizeof(void*)) <= size) 33 if (INT_MAX / static_cast<int>(sizeof(void*)) <= size)
32 return false; 34 return false;
33 p->Clear(); 35 p->Clear();
34 p->Reserve(size); 36 p->Reserve(size);
35 while (size--) { 37 while (size--) {
36 if (!ReadParam(m, iter, p->Add())) 38 if (!ReadParam(m, iter, p->Add()))
37 return false; 39 return false;
38 } 40 }
39 return true; 41 return true;
40 } 42 }
41 43
42 static void Log(const param_type& p, std::string* l) { 44 static void Log(const param_type& p, std::string* l) {
43 bool logged_first = false; 45 bool logged_first = false;
44 for (const auto& element : p) { 46 for (const auto& element : p) {
45 if (logged_first) 47 if (logged_first)
46 l->push_back(' '); 48 l->push_back(' ');
47 else 49 else
48 logged_first = true; 50 logged_first = true;
49 LogParam(element, l); 51 LogParam(element, l);
50 } 52 }
51 } 53 }
52 }; 54 };
53 55
54 } // namespace IPC 56 } // namespace IPC
55 57
56 #endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ 58 #endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_
OLDNEW
« no previous file with comments | « chrome/common/safe_browsing/ipc_protobuf_message_macros.h ('k') | chrome/common/safe_browsing/protobuf_message_read_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698