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/json/json_writer.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 #include "base/values.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 scoped_ptr<base::Value> TracedValue::CreateIDRef(const void* id) { | 13 scoped_ptr<base::Value> TracedValue::CreateIDRef(const void* id) { |
14 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 14 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
15 res->SetString("id_ref", base::StringPrintf("%p", id)); | 15 res->SetString("id_ref", base::StringPrintf("%p", id)); |
16 return res.PassAs<base::Value>(); | 16 return res.PassAs<base::Value>(); |
17 } | 17 } |
18 | 18 |
19 void TracedValue::MakeDictIntoImplicitSnapshot( | 19 void TracedValue::MakeDictIntoImplicitSnapshot(const char* category, |
20 base::DictionaryValue* dict, const char* object_name, const void* id) { | 20 base::DictionaryValue* dict, |
| 21 const char* object_name, |
| 22 const void* id) { |
21 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); | 23 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); |
| 24 dict->SetString("cat", category); |
22 } | 25 } |
23 | 26 |
24 scoped_ptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( | 27 scoped_ptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( |
25 base::Value* value) { | 28 base::Value* value) { |
26 TracedValue* ptr = new TracedValue(value); | 29 TracedValue* ptr = new TracedValue(value); |
27 scoped_ptr<TracedValue> result(ptr); | 30 scoped_ptr<TracedValue> result(ptr); |
28 return result.PassAs<base::debug::ConvertableToTraceFormat>(); | 31 return result.PassAs<base::debug::ConvertableToTraceFormat>(); |
29 } | 32 } |
30 | 33 |
31 TracedValue::TracedValue(base::Value* value) | 34 TracedValue::TracedValue(base::Value* value) |
32 : value_(value) { | 35 : value_(value) { |
33 } | 36 } |
34 | 37 |
35 TracedValue::~TracedValue() { | 38 TracedValue::~TracedValue() { |
36 } | 39 } |
37 | 40 |
38 void TracedValue::AppendAsTraceFormat(std::string* out) const { | 41 void TracedValue::AppendAsTraceFormat(std::string* out) const { |
39 std::string tmp; | 42 std::string tmp; |
40 base::JSONWriter::Write(value_.get(), &tmp); | 43 base::JSONWriter::Write(value_.get(), &tmp); |
41 *out += tmp; | 44 *out += tmp; |
42 } | 45 } |
43 | 46 |
44 } // namespace cc | 47 } // namespace cc |
OLD | NEW |