| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "cc/debug/traced_value.h" | 5 #include "cc/debug/traced_value.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event_argument.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/values.h" |
| 9 | 10 |
| 10 namespace cc { | 11 namespace cc { |
| 11 | 12 |
| 12 void TracedValue::AppendIDRef(const void* id, base::debug::TracedValue* state) { | 13 scoped_ptr<base::Value> TracedValue::CreateIDRef(const void* id) { |
| 13 state->BeginDictionary(); | 14 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 14 state->SetString("id_ref", base::StringPrintf("%p", id)); | 15 res->SetString("id_ref", base::StringPrintf("%p", id)); |
| 15 state->EndDictionary(); | 16 return res.PassAs<base::Value>(); |
| 16 } | 17 } |
| 17 | 18 |
| 18 void TracedValue::SetIDRef(const void* id, | 19 void TracedValue::MakeDictIntoImplicitSnapshot( |
| 19 base::debug::TracedValue* state, | 20 base::DictionaryValue* dict, const char* object_name, const void* id) { |
| 20 const char* name) { | |
| 21 state->BeginDictionary(name); | |
| 22 state->SetString("id_ref", base::StringPrintf("%p", id)); | |
| 23 state->EndDictionary(); | |
| 24 } | |
| 25 | |
| 26 void TracedValue::MakeDictIntoImplicitSnapshot(base::debug::TracedValue* dict, | |
| 27 const char* object_name, | |
| 28 const void* id) { | |
| 29 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); | 21 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); |
| 30 } | 22 } |
| 31 | 23 |
| 32 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( | 24 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 33 const char* category, | 25 const char* category, |
| 34 base::debug::TracedValue* dict, | 26 base::DictionaryValue* dict, |
| 35 const char* object_name, | 27 const char* object_name, |
| 36 const void* id) { | 28 const void* id) { |
| 37 dict->SetString("cat", category); | 29 dict->SetString("cat", category); |
| 38 MakeDictIntoImplicitSnapshot(dict, object_name, id); | 30 MakeDictIntoImplicitSnapshot(dict, object_name, id); |
| 39 } | 31 } |
| 40 | 32 |
| 41 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( | 33 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 42 const char* category, | 34 const char* category, |
| 43 base::debug::TracedValue* dict, | 35 base::DictionaryValue* dict, |
| 44 const char* object_base_type_name, | 36 const char* object_base_type_name, |
| 45 const char* object_name, | 37 const char* object_name, |
| 46 const void* id) { | 38 const void* id) { |
| 47 dict->SetString("cat", category); | 39 dict->SetString("cat", category); |
| 48 dict->SetString("base_type", object_base_type_name); | 40 dict->SetString("base_type", object_base_type_name); |
| 49 MakeDictIntoImplicitSnapshot(dict, object_name, id); | 41 MakeDictIntoImplicitSnapshot(dict, object_name, id); |
| 50 } | 42 } |
| 51 | 43 |
| 44 scoped_refptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( |
| 45 base::Value* value) { |
| 46 return scoped_refptr<base::debug::ConvertableToTraceFormat>( |
| 47 new TracedValue(value)); |
| 48 } |
| 49 |
| 50 TracedValue::TracedValue(base::Value* value) |
| 51 : value_(value) { |
| 52 } |
| 53 |
| 54 TracedValue::~TracedValue() { |
| 55 } |
| 56 |
| 57 void TracedValue::AppendAsTraceFormat(std::string* out) const { |
| 58 std::string tmp; |
| 59 base::JSONWriter::Write(value_.get(), &tmp); |
| 60 *out += tmp; |
| 61 } |
| 62 |
| 52 } // namespace cc | 63 } // namespace cc |
| OLD | NEW |