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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Array.h

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 Array_h 5 #ifndef Array_h
6 #define Array_h 6 #define Array_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/inspector_protocol/Collections.h" 9 #include "platform/inspector_protocol/Collections.h"
10 #include "platform/inspector_protocol/ErrorSupport.h" 10 #include "platform/inspector_protocol/ErrorSupport.h"
11 #include "platform/inspector_protocol/String16.h" 11 #include "platform/inspector_protocol/String16.h"
12 #include "platform/inspector_protocol/ValueConversions.h" 12 #include "platform/inspector_protocol/ValueConversions.h"
13 #include "platform/inspector_protocol/Values.h" 13 #include "platform/inspector_protocol/Values.h"
14 14
15 namespace blink { 15 namespace blink {
16 namespace protocol { 16 namespace protocol {
17 17
18 template<typename T> 18 template<typename T>
19 class ArrayBase { 19 class ArrayBase {
20 public: 20 public:
21 static PassOwnPtr<Array<T>> create() 21 static std::unique_ptr<Array<T>> create()
22 { 22 {
23 return adoptPtr(new Array<T>()); 23 return wrapUnique(new Array<T>());
24 } 24 }
25 25
26 static PassOwnPtr<Array<T>> parse(protocol::Value* value, ErrorSupport* erro rs) 26 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
27 { 27 {
28 protocol::ListValue* array = ListValue::cast(value); 28 protocol::ListValue* array = ListValue::cast(value);
29 if (!array) { 29 if (!array) {
30 errors->addError("array expected"); 30 errors->addError("array expected");
31 return nullptr; 31 return nullptr;
32 } 32 }
33 errors->push(); 33 errors->push();
34 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 34 std::unique_ptr<Array<T>> result(new Array<T>());
35 for (size_t i = 0; i < array->size(); ++i) { 35 for (size_t i = 0; i < array->size(); ++i) {
36 errors->setName(String16::number(i)); 36 errors->setName(String16::number(i));
37 T item = FromValue<T>::parse(array->at(i), errors); 37 T item = FromValue<T>::parse(array->at(i), errors);
38 result->m_vector.append(item); 38 result->m_vector.append(item);
39 } 39 }
40 errors->pop(); 40 errors->pop();
41 if (errors->hasErrors()) 41 if (errors->hasErrors())
42 return nullptr; 42 return nullptr;
43 return result; 43 return result;
44 } 44 }
45 45
46 void addItem(const T& value) 46 void addItem(const T& value)
47 { 47 {
48 m_vector.append(value); 48 m_vector.append(value);
49 } 49 }
50 50
51 size_t length() 51 size_t length()
52 { 52 {
53 return m_vector.size(); 53 return m_vector.size();
54 } 54 }
55 55
56 T get(size_t index) 56 T get(size_t index)
57 { 57 {
58 return m_vector[index]; 58 return m_vector[index];
59 } 59 }
60 60
61 PassOwnPtr<protocol::ListValue> serialize() 61 std::unique_ptr<protocol::ListValue> serialize()
62 { 62 {
63 OwnPtr<protocol::ListValue> result = ListValue::create(); 63 std::unique_ptr<protocol::ListValue> result = ListValue::create();
64 for (auto& item : m_vector) 64 for (auto& item : m_vector)
65 result->pushValue(toValue(item)); 65 result->pushValue(toValue(item));
66 return result; 66 return result;
67 } 67 }
68 68
69 private: 69 private:
70 protocol::Vector<T> m_vector; 70 protocol::Vector<T> m_vector;
71 }; 71 };
72 72
73 template<> class Array<String> : public ArrayBase<String> {}; 73 template<> class Array<String> : public ArrayBase<String> {};
74 template<> class Array<String16> : public ArrayBase<String16> {}; 74 template<> class Array<String16> : public ArrayBase<String16> {};
75 template<> class Array<int> : public ArrayBase<int> {}; 75 template<> class Array<int> : public ArrayBase<int> {};
76 template<> class Array<double> : public ArrayBase<double> {}; 76 template<> class Array<double> : public ArrayBase<double> {};
77 template<> class Array<bool> : public ArrayBase<bool> {}; 77 template<> class Array<bool> : public ArrayBase<bool> {};
78 78
79 template<typename T> 79 template<typename T>
80 class Array { 80 class Array {
81 public: 81 public:
82 static PassOwnPtr<Array<T>> create() 82 static std::unique_ptr<Array<T>> create()
83 { 83 {
84 return adoptPtr(new Array<T>()); 84 return wrapUnique(new Array<T>());
85 } 85 }
86 86
87 static PassOwnPtr<Array<T>> parse(protocol::Value* value, ErrorSupport* erro rs) 87 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
88 { 88 {
89 protocol::ListValue* array = ListValue::cast(value); 89 protocol::ListValue* array = ListValue::cast(value);
90 if (!array) { 90 if (!array) {
91 errors->addError("array expected"); 91 errors->addError("array expected");
92 return nullptr; 92 return nullptr;
93 } 93 }
94 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 94 std::unique_ptr<Array<T>> result(new Array<T>());
95 errors->push(); 95 errors->push();
96 for (size_t i = 0; i < array->size(); ++i) { 96 for (size_t i = 0; i < array->size(); ++i) {
97 errors->setName(String16::number(i)); 97 errors->setName(String16::number(i));
98 OwnPtr<T> item = FromValue<T>::parse(array->at(i), errors); 98 std::unique_ptr<T> item = FromValue<T>::parse(array->at(i), errors);
99 result->m_vector.append(std::move(item)); 99 result->m_vector.append(std::move(item));
100 } 100 }
101 errors->pop(); 101 errors->pop();
102 if (errors->hasErrors()) 102 if (errors->hasErrors())
103 return nullptr; 103 return nullptr;
104 return result; 104 return result;
105 } 105 }
106 106
107 void addItem(PassOwnPtr<T> value) 107 void addItem(std::unique_ptr<T> value)
108 { 108 {
109 m_vector.append(std::move(value)); 109 m_vector.append(std::move(value));
110 } 110 }
111 111
112 size_t length() 112 size_t length()
113 { 113 {
114 return m_vector.size(); 114 return m_vector.size();
115 } 115 }
116 116
117 T* get(size_t index) 117 T* get(size_t index)
118 { 118 {
119 return m_vector[index]; 119 return m_vector[index];
120 } 120 }
121 121
122 PassOwnPtr<protocol::ListValue> serialize() 122 std::unique_ptr<protocol::ListValue> serialize()
123 { 123 {
124 OwnPtr<protocol::ListValue> result = ListValue::create(); 124 std::unique_ptr<protocol::ListValue> result = ListValue::create();
125 for (auto& item : m_vector) 125 for (auto& item : m_vector)
126 result->pushValue(toValue(item.get())); 126 result->pushValue(toValue(item.get()));
127 return result; 127 return result;
128 } 128 }
129 129
130 private: 130 private:
131 protocol::Vector<OwnPtr<T>> m_vector; 131 protocol::Vector<std::unique_ptr<T>> m_vector;
132 }; 132 };
133 133
134 } // namespace platform 134 } // namespace platform
135 } // namespace blink 135 } // namespace blink
136 136
137 #endif // !defined(Array_h) 137 #endif // !defined(Array_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698