| 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 |
| 26 if (current_frame_host->last_committed_url().is_valid()) |
| 27 url_ = current_frame_host->last_committed_url().spec(); |
| 28 |
| 29 // On Windows, |rph->GetHandle()| does not duplicate ownership |
| 30 // of the process handle and the render host still retains it. Therefore, we |
| 31 // cannot create a base::Process object, which provides a proper way to get a |
| 32 // process id, from the handle. For a stopgap, we use this deprecated |
| 33 // function that does not require the ownership (http://crbug.com/417532). |
| 34 process_id_ = base::GetProcId(current_frame_host->GetProcess()->GetHandle()); |
| 35 |
| 36 routing_id_ = current_frame_host->GetRoutingID(); |
| 37 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| 38 } |
| 39 |
| 40 TracedFrameTreeNode::~TracedFrameTreeNode() { |
| 41 } |
| 42 |
| 43 void TracedFrameTreeNode::AppendAsTraceFormat(std::string* out) const { |
| 44 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 45 |
| 46 if (parent_node_id_ >= 0) { |
| 47 scoped_ptr<base::DictionaryValue> ref(new base::DictionaryValue()); |
| 48 ref->SetString("id_ref", base::StringPrintf("0x%x", parent_node_id_)); |
| 49 ref->SetString("scope", "FrameTreeNode"); |
| 50 value->Set("parent", std::move(ref)); |
| 51 } |
| 52 |
| 53 if (process_id_ >= 0) { |
| 54 scoped_ptr<base::DictionaryValue> ref(new base::DictionaryValue()); |
| 55 ref->SetInteger("pid_ref", process_id_); |
| 56 ref->SetString("id_ref", base::StringPrintf("0x%x", routing_id_)); |
| 57 ref->SetString("scope", "RenderFrame"); |
| 58 value->Set("RenderFrame", std::move(ref)); |
| 59 } |
| 60 |
| 61 if (!url_.empty()) |
| 62 value->SetString("url", url_); |
| 63 |
| 64 std::string tmp; |
| 65 base::JSONWriter::Write(*value, &tmp); |
| 66 *out += tmp; |
| 67 } |
| 68 |
| 69 } // content |
| OLD | NEW |