| 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( |
| 20 base::DictionaryValue* dict, const char* object_name, const void* id) { | 20 base::DictionaryValue* dict, const char* object_name, const void* id) { |
| 21 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); | 21 dict->SetString("id", base::StringPrintf("%s/%p", object_name, id)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 25 const char* category, |
| 26 base::DictionaryValue* dict, |
| 27 const char* object_name, |
| 28 const void* id) { |
| 29 dict->SetString("cat", category); |
| 30 MakeDictIntoImplicitSnapshot(dict, object_name, id); |
| 31 } |
| 32 |
| 24 scoped_ptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( | 33 scoped_ptr<base::debug::ConvertableToTraceFormat> TracedValue::FromValue( |
| 25 base::Value* value) { | 34 base::Value* value) { |
| 26 TracedValue* ptr = new TracedValue(value); | 35 TracedValue* ptr = new TracedValue(value); |
| 27 scoped_ptr<TracedValue> result(ptr); | 36 scoped_ptr<TracedValue> result(ptr); |
| 28 return result.PassAs<base::debug::ConvertableToTraceFormat>(); | 37 return result.PassAs<base::debug::ConvertableToTraceFormat>(); |
| 29 } | 38 } |
| 30 | 39 |
| 31 TracedValue::TracedValue(base::Value* value) | 40 TracedValue::TracedValue(base::Value* value) |
| 32 : value_(value) { | 41 : value_(value) { |
| 33 } | 42 } |
| 34 | 43 |
| 35 TracedValue::~TracedValue() { | 44 TracedValue::~TracedValue() { |
| 36 } | 45 } |
| 37 | 46 |
| 38 void TracedValue::AppendAsTraceFormat(std::string* out) const { | 47 void TracedValue::AppendAsTraceFormat(std::string* out) const { |
| 39 std::string tmp; | 48 std::string tmp; |
| 40 base::JSONWriter::Write(value_.get(), &tmp); | 49 base::JSONWriter::Write(value_.get(), &tmp); |
| 41 *out += tmp; | 50 *out += tmp; |
| 42 } | 51 } |
| 43 | 52 |
| 44 } // namespace cc | 53 } // namespace cc |
| OLD | NEW |