| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 "content/browser/frame_host/traced_frame_tree_node.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/json/json_writer.h" | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "content/browser/frame_host/frame_tree.h" | |
| 11 #include "content/public/common/content_switches.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 TracedFrameTreeNode::TracedFrameTreeNode(const FrameTreeNode& node) | |
| 17 : parent_node_id_(-1), | |
| 18 process_id_(-1), | |
| 19 routing_id_(-1) { | |
| 20 FrameTreeNode* parent = node.parent(); | |
| 21 if (parent) | |
| 22 parent_node_id_ = parent->frame_tree_node_id(); | |
| 23 | |
| 24 RenderFrameHostImpl* current_frame_host = node.current_frame_host(); | |
| 25 if (!current_frame_host) | |
| 26 return; | |
| 27 | |
| 28 if (current_frame_host->last_committed_url().is_valid()) | |
| 29 url_ = current_frame_host->last_committed_url().spec(); | |
| 30 | |
| 31 base::ProcessHandle process_handle = | |
| 32 current_frame_host->GetProcess()->GetHandle(); | |
| 33 if (process_handle == base::kNullProcessHandle) | |
| 34 return; | |
| 35 | |
| 36 // On Windows, |rph->GetHandle()| does not duplicate ownership | |
| 37 // of the process handle and the render host still retains it. Therefore, we | |
| 38 // cannot create a base::Process object, which provides a proper way to get a | |
| 39 // process id, from the handle. For a stopgap, we use this deprecated | |
| 40 // function that does not require the ownership (http://crbug.com/417532). | |
| 41 process_id_ = base::GetProcId(process_handle); | |
| 42 | |
| 43 routing_id_ = current_frame_host->GetRoutingID(); | |
| 44 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | |
| 45 } | |
| 46 | |
| 47 TracedFrameTreeNode::~TracedFrameTreeNode() { | |
| 48 } | |
| 49 | |
| 50 void TracedFrameTreeNode::AppendAsTraceFormat(std::string* out) const { | |
| 51 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 52 | |
| 53 if (parent_node_id_ >= 0) { | |
| 54 scoped_ptr<base::DictionaryValue> ref(new base::DictionaryValue()); | |
| 55 ref->SetString("id_ref", base::StringPrintf("0x%x", parent_node_id_)); | |
| 56 ref->SetString("scope", "FrameTreeNode"); | |
| 57 value->Set("parent", std::move(ref)); | |
| 58 } | |
| 59 | |
| 60 if (process_id_ >= 0) { | |
| 61 scoped_ptr<base::DictionaryValue> ref(new base::DictionaryValue()); | |
| 62 ref->SetInteger("pid_ref", process_id_); | |
| 63 ref->SetString("id_ref", base::StringPrintf("0x%x", routing_id_)); | |
| 64 ref->SetString("scope", "RenderFrame"); | |
| 65 value->Set("RenderFrame", std::move(ref)); | |
| 66 } | |
| 67 | |
| 68 if (!url_.empty()) | |
| 69 value->SetString("url", url_); | |
| 70 | |
| 71 std::string tmp; | |
| 72 base::JSONWriter::Write(*value, &tmp); | |
| 73 *out += tmp; | |
| 74 } | |
| 75 | |
| 76 } // content | |
| OLD | NEW |