Chromium Code Reviews| Index: content/browser/frame_host/traced_frame_tree.cc |
| diff --git a/content/browser/frame_host/traced_frame_tree.cc b/content/browser/frame_host/traced_frame_tree.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..70ed199626883b024fb4534940e5bfefda39b9bd |
| --- /dev/null |
| +++ b/content/browser/frame_host/traced_frame_tree.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/frame_host/traced_frame_tree.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/json/json_writer.h" |
| +#include "content/browser/frame_host/frame_tree.h" |
| +#include "content/public/common/content_switches.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +scoped_ptr<base::DictionaryValue> GetFrameTreeNodeAsValue(FrameTreeNode* node) { |
| + scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| + value->SetString("url", node->current_url().spec()); |
| + value->SetInteger("nodeId", node->frame_tree_node_id()); |
| + |
| + RenderFrameHostImpl* current_frame_host = |
| + node->render_manager()->current_frame_host(); |
| + if (current_frame_host) { |
|
clamy
2015/10/29 17:17:16
We should always have a current RFH, so I think we
|
| + value->SetInteger("processId", current_frame_host->GetProcess()->GetID()); |
| + value->SetInteger("routingId", current_frame_host->GetRoutingID()); |
| + } |
| + |
| + if (node->child_count() > 0) { |
| + scoped_ptr<base::ListValue> subframes(new base::ListValue()); |
| + for (size_t i = 0; i < node->child_count(); ++i) { |
| + subframes->Append(GetFrameTreeNodeAsValue(node->child_at(i))); |
| + } |
| + value->Set("children", subframes.Pass()); |
| + } |
| + return value.Pass(); |
| +} |
| + |
| +} // namespace |
| + |
| +scoped_refptr<TracedFrameTree> TracedFrameTree::Create(const FrameTree& tree) { |
| + return scoped_refptr<TracedFrameTree>(new TracedFrameTree( |
| + GetFrameTreeNodeAsValue(tree.root()))); |
| +} |
| + |
| +TracedFrameTree::TracedFrameTree(scoped_ptr<base::DictionaryValue> value) |
| + : value_(value.Pass()) { |
| +} |
| + |
| +TracedFrameTree::~TracedFrameTree() { |
| +} |
| + |
| +void TracedFrameTree::AppendAsTraceFormat(std::string* out) const { |
| + std::string tmp; |
| + base::JSONWriter::Write(*value_, &tmp); |
| + *out += tmp; |
| +} |
| + |
| +} // content |