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

Side by Side Diff: base/trace_event/trace_event_argument.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 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
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "base/trace_event/trace_event_argument.h" 5 #include "base/trace_event/trace_event_argument.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bits.h" 11 #include "base/bits.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/trace_event/trace_event_memory_overhead.h" 14 #include "base/trace_event/trace_event_memory_overhead.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 16
16 namespace base { 17 namespace base {
17 namespace trace_event { 18 namespace trace_event {
18 19
19 namespace { 20 namespace {
20 const char kTypeStartDict = '{'; 21 const char kTypeStartDict = '{';
21 const char kTypeEndDict = '}'; 22 const char kTypeEndDict = '}';
22 const char kTypeStartArray = '['; 23 const char kTypeStartArray = '[';
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DEBUG_PUSH_CONTAINER(kStackTypeDict); 228 DEBUG_PUSH_CONTAINER(kStackTypeDict);
228 pickle_.WriteBytes(&kTypeStartDict, 1); 229 pickle_.WriteBytes(&kTypeStartDict, 1);
229 } 230 }
230 231
231 void TracedValue::EndArray() { 232 void TracedValue::EndArray() {
232 DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray); 233 DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray);
233 DEBUG_POP_CONTAINER(); 234 DEBUG_POP_CONTAINER();
234 pickle_.WriteBytes(&kTypeEndArray, 1); 235 pickle_.WriteBytes(&kTypeEndArray, 1);
235 } 236 }
236 237
237 void TracedValue::SetValue(const char* name, scoped_ptr<base::Value> value) { 238 void TracedValue::SetValue(const char* name,
239 std::unique_ptr<base::Value> value) {
238 SetBaseValueWithCopiedName(name, *value); 240 SetBaseValueWithCopiedName(name, *value);
239 } 241 }
240 242
241 void TracedValue::SetBaseValueWithCopiedName(base::StringPiece name, 243 void TracedValue::SetBaseValueWithCopiedName(base::StringPiece name,
242 const base::Value& value) { 244 const base::Value& value) {
243 DCHECK_CURRENT_CONTAINER_IS(kStackTypeDict); 245 DCHECK_CURRENT_CONTAINER_IS(kStackTypeDict);
244 switch (value.GetType()) { 246 switch (value.GetType()) {
245 case base::Value::TYPE_NULL: 247 case base::Value::TYPE_NULL:
246 case base::Value::TYPE_BINARY: 248 case base::Value::TYPE_BINARY:
247 NOTREACHED(); 249 NOTREACHED();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 const ListValue* list_value; 342 const ListValue* list_value;
341 value.GetAsList(&list_value); 343 value.GetAsList(&list_value);
342 BeginArray(); 344 BeginArray();
343 for (base::Value* base_value : *list_value) 345 for (base::Value* base_value : *list_value)
344 AppendBaseValue(*base_value); 346 AppendBaseValue(*base_value);
345 EndArray(); 347 EndArray();
346 } break; 348 } break;
347 } 349 }
348 } 350 }
349 351
350 scoped_ptr<base::Value> TracedValue::ToBaseValue() const { 352 std::unique_ptr<base::Value> TracedValue::ToBaseValue() const {
351 scoped_ptr<DictionaryValue> root(new DictionaryValue); 353 std::unique_ptr<DictionaryValue> root(new DictionaryValue);
352 DictionaryValue* cur_dict = root.get(); 354 DictionaryValue* cur_dict = root.get();
353 ListValue* cur_list = nullptr; 355 ListValue* cur_list = nullptr;
354 std::vector<Value*> stack; 356 std::vector<Value*> stack;
355 PickleIterator it(pickle_); 357 PickleIterator it(pickle_);
356 const char* type; 358 const char* type;
357 359
358 while (it.ReadBytes(&type, 1)) { 360 while (it.ReadBytes(&type, 1)) {
359 DCHECK((cur_dict && !cur_list) || (cur_list && !cur_dict)); 361 DCHECK((cur_dict && !cur_list) || (cur_list && !cur_dict));
360 switch (*type) { 362 switch (*type) {
361 case kTypeStartDict: { 363 case kTypeStartDict: {
362 auto new_dict = new DictionaryValue(); 364 auto new_dict = new DictionaryValue();
363 if (cur_dict) { 365 if (cur_dict) {
364 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), 366 cur_dict->SetWithoutPathExpansion(ReadKeyName(it),
365 make_scoped_ptr(new_dict)); 367 WrapUnique(new_dict));
366 stack.push_back(cur_dict); 368 stack.push_back(cur_dict);
367 cur_dict = new_dict; 369 cur_dict = new_dict;
368 } else { 370 } else {
369 cur_list->Append(make_scoped_ptr(new_dict)); 371 cur_list->Append(WrapUnique(new_dict));
370 stack.push_back(cur_list); 372 stack.push_back(cur_list);
371 cur_list = nullptr; 373 cur_list = nullptr;
372 cur_dict = new_dict; 374 cur_dict = new_dict;
373 } 375 }
374 } break; 376 } break;
375 377
376 case kTypeEndArray: 378 case kTypeEndArray:
377 case kTypeEndDict: { 379 case kTypeEndDict: {
378 if (stack.back()->GetAsDictionary(&cur_dict)) { 380 if (stack.back()->GetAsDictionary(&cur_dict)) {
379 cur_list = nullptr; 381 cur_list = nullptr;
380 } else if (stack.back()->GetAsList(&cur_list)) { 382 } else if (stack.back()->GetAsList(&cur_list)) {
381 cur_dict = nullptr; 383 cur_dict = nullptr;
382 } 384 }
383 stack.pop_back(); 385 stack.pop_back();
384 } break; 386 } break;
385 387
386 case kTypeStartArray: { 388 case kTypeStartArray: {
387 auto new_list = new ListValue(); 389 auto new_list = new ListValue();
388 if (cur_dict) { 390 if (cur_dict) {
389 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), 391 cur_dict->SetWithoutPathExpansion(ReadKeyName(it),
390 make_scoped_ptr(new_list)); 392 WrapUnique(new_list));
391 stack.push_back(cur_dict); 393 stack.push_back(cur_dict);
392 cur_dict = nullptr; 394 cur_dict = nullptr;
393 cur_list = new_list; 395 cur_list = new_list;
394 } else { 396 } else {
395 cur_list->Append(make_scoped_ptr(new_list)); 397 cur_list->Append(WrapUnique(new_list));
396 stack.push_back(cur_list); 398 stack.push_back(cur_list);
397 cur_list = new_list; 399 cur_list = new_list;
398 } 400 }
399 } break; 401 } break;
400 402
401 case kTypeBool: { 403 case kTypeBool: {
402 bool value; 404 bool value;
403 CHECK(it.ReadBool(&value)); 405 CHECK(it.ReadBool(&value));
404 if (cur_dict) { 406 if (cur_dict) {
405 cur_dict->SetBooleanWithoutPathExpansion(ReadKeyName(it), value); 407 cur_dict->SetBooleanWithoutPathExpansion(ReadKeyName(it), value);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 467
466 /* allocated size */ 468 /* allocated size */
467 bits::Align(pickle_.GetTotalAllocatedSize(), kPickleHeapAlign), 469 bits::Align(pickle_.GetTotalAllocatedSize(), kPickleHeapAlign),
468 470
469 /* resident size */ 471 /* resident size */
470 bits::Align(pickle_.size(), kPickleHeapAlign)); 472 bits::Align(pickle_.size(), kPickleHeapAlign));
471 } 473 }
472 474
473 } // namespace trace_event 475 } // namespace trace_event
474 } // namespace base 476 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_argument.h ('k') | base/trace_event/trace_event_argument_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698