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

Side by Side Diff: dbus/values_util.cc

Issue 1867253002: Convert //dbus from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU fixes in //device Created 4 years, 8 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
« no previous file with comments | « dbus/test_service.cc ('k') | dbus/values_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "dbus/values_util.h" 5 #include "dbus/values_util.h"
6 6
7 #include <memory>
8
7 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "dbus/message.h" 12 #include "dbus/message.h"
12 13
13 namespace dbus { 14 namespace dbus {
14 15
15 namespace { 16 namespace {
16 17
17 // Returns whether |value| is exactly representable by double or not. 18 // Returns whether |value| is exactly representable by double or not.
18 template<typename T> 19 template<typename T>
19 bool IsExactlyRepresentableByDouble(T value) { 20 bool IsExactlyRepresentableByDouble(T value) {
(...skipping 20 matching lines...) Expand all
40 if (!reader->PopDictEntry(&entry_reader)) 41 if (!reader->PopDictEntry(&entry_reader))
41 return false; 42 return false;
42 // Get key as a string. 43 // Get key as a string.
43 std::string key_string; 44 std::string key_string;
44 if (entry_reader.GetDataType() == Message::STRING) { 45 if (entry_reader.GetDataType() == Message::STRING) {
45 // If the type of keys is STRING, pop it directly. 46 // If the type of keys is STRING, pop it directly.
46 if (!entry_reader.PopString(&key_string)) 47 if (!entry_reader.PopString(&key_string))
47 return false; 48 return false;
48 } else { 49 } else {
49 // If the type of keys is not STRING, convert it to string. 50 // If the type of keys is not STRING, convert it to string.
50 scoped_ptr<base::Value> key(PopDataAsValue(&entry_reader)); 51 std::unique_ptr<base::Value> key(PopDataAsValue(&entry_reader));
51 if (!key) 52 if (!key)
52 return false; 53 return false;
53 // Use JSONWriter to convert an arbitrary value to a string. 54 // Use JSONWriter to convert an arbitrary value to a string.
54 base::JSONWriter::Write(*key, &key_string); 55 base::JSONWriter::Write(*key, &key_string);
55 } 56 }
56 // Get the value and set the key-value pair. 57 // Get the value and set the key-value pair.
57 base::Value* value = PopDataAsValue(&entry_reader); 58 base::Value* value = PopDataAsValue(&entry_reader);
58 if (!value) 59 if (!value)
59 return false; 60 return false;
60 dictionary_value->SetWithoutPathExpansion(key_string, value); 61 dictionary_value->SetWithoutPathExpansion(key_string, value);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Cannot distinguish a file descriptor from an int 170 // Cannot distinguish a file descriptor from an int
170 NOTREACHED(); 171 NOTREACHED();
171 break; 172 break;
172 } 173 }
173 case Message::ARRAY: { 174 case Message::ARRAY: {
174 MessageReader sub_reader(NULL); 175 MessageReader sub_reader(NULL);
175 if (reader->PopArray(&sub_reader)) { 176 if (reader->PopArray(&sub_reader)) {
176 // If the type of the array's element is DICT_ENTRY, create a 177 // If the type of the array's element is DICT_ENTRY, create a
177 // DictionaryValue, otherwise create a ListValue. 178 // DictionaryValue, otherwise create a ListValue.
178 if (sub_reader.GetDataType() == Message::DICT_ENTRY) { 179 if (sub_reader.GetDataType() == Message::DICT_ENTRY) {
179 scoped_ptr<base::DictionaryValue> dictionary_value( 180 std::unique_ptr<base::DictionaryValue> dictionary_value(
180 new base::DictionaryValue); 181 new base::DictionaryValue);
181 if (PopDictionaryEntries(&sub_reader, dictionary_value.get())) 182 if (PopDictionaryEntries(&sub_reader, dictionary_value.get()))
182 result = dictionary_value.release(); 183 result = dictionary_value.release();
183 } else { 184 } else {
184 scoped_ptr<base::ListValue> list_value(new base::ListValue); 185 std::unique_ptr<base::ListValue> list_value(new base::ListValue);
185 if (PopListElements(&sub_reader, list_value.get())) 186 if (PopListElements(&sub_reader, list_value.get()))
186 result = list_value.release(); 187 result = list_value.release();
187 } 188 }
188 } 189 }
189 break; 190 break;
190 } 191 }
191 case Message::STRUCT: { 192 case Message::STRUCT: {
192 MessageReader sub_reader(NULL); 193 MessageReader sub_reader(NULL);
193 if (reader->PopStruct(&sub_reader)) { 194 if (reader->PopStruct(&sub_reader)) {
194 scoped_ptr<base::ListValue> list_value(new base::ListValue); 195 std::unique_ptr<base::ListValue> list_value(new base::ListValue);
195 if (PopListElements(&sub_reader, list_value.get())) 196 if (PopListElements(&sub_reader, list_value.get()))
196 result = list_value.release(); 197 result = list_value.release();
197 } 198 }
198 break; 199 break;
199 } 200 }
200 case Message::DICT_ENTRY: 201 case Message::DICT_ENTRY:
201 // DICT_ENTRY must be popped as an element of an array. 202 // DICT_ENTRY must be popped as an element of an array.
202 NOTREACHED(); 203 NOTREACHED();
203 break; 204 break;
204 case Message::VARIANT: { 205 case Message::VARIANT: {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 299 }
299 300
300 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) { 301 void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) {
301 MessageWriter variant_writer(NULL); 302 MessageWriter variant_writer(NULL);
302 writer->OpenVariant(GetTypeSignature(value), &variant_writer); 303 writer->OpenVariant(GetTypeSignature(value), &variant_writer);
303 AppendValueData(&variant_writer, value); 304 AppendValueData(&variant_writer, value);
304 writer->CloseContainer(&variant_writer); 305 writer->CloseContainer(&variant_writer);
305 } 306 }
306 307
307 } // namespace dbus 308 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/test_service.cc ('k') | dbus/values_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698