• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "cc/debug/traced_value.h"
6 
7 #include "base/json/json_writer.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/values.h"
10 
11 namespace cc {
12 
CreateIDRef(const void * id)13 scoped_ptr<base::Value> TracedValue::CreateIDRef(const void* id) {
14   scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
15   res->SetString("id_ref", base::StringPrintf("%p", id));
16   return res.PassAs<base::Value>();
17 }
18 
MakeDictIntoImplicitSnapshot(base::DictionaryValue * dict,const char * object_name,const void * id)19 void TracedValue::MakeDictIntoImplicitSnapshot(
20     base::DictionaryValue* dict, const char* object_name, const void* id) {
21   dict->SetString("id", base::StringPrintf("%s/%p", object_name, id));
22 }
23 
MakeDictIntoImplicitSnapshotWithCategory(const char * category,base::DictionaryValue * dict,const char * object_name,const void * id)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 
MakeDictIntoImplicitSnapshotWithCategory(const char * category,base::DictionaryValue * dict,const char * object_base_type_name,const char * object_name,const void * id)33 void TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
34     const char* category,
35     base::DictionaryValue* dict,
36     const char* object_base_type_name,
37     const char* object_name,
38     const void* id) {
39   dict->SetString("cat", category);
40   dict->SetString("base_type", object_base_type_name);
41   MakeDictIntoImplicitSnapshot(dict, object_name, id);
42 }
43 
FromValue(base::Value * value)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 
TracedValue(base::Value * value)50 TracedValue::TracedValue(base::Value* value)
51   : value_(value) {
52 }
53 
~TracedValue()54 TracedValue::~TracedValue() {
55 }
56 
AppendAsTraceFormat(std::string * out) const57 void TracedValue::AppendAsTraceFormat(std::string* out) const {
58   std::string tmp;
59   base::JSONWriter::Write(value_.get(), &tmp);
60   *out += tmp;
61 }
62 
63 }  // namespace cc
64