Chromium Code Reviews| Index: content/browser/frame_host/frame_tree_node_blame_context.cc |
| diff --git a/content/browser/frame_host/frame_tree_node_blame_context.cc b/content/browser/frame_host/frame_tree_node_blame_context.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ea74c2d29efb7d8782f538f3c59d8bb7ceb0e0e |
| --- /dev/null |
| +++ b/content/browser/frame_host/frame_tree_node_blame_context.cc |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2016 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/frame_tree_node_blame_context.h" |
| + |
| +#include "base/strings/stringprintf.h" |
| +#include "base/trace_event/trace_event_argument.h" |
| +#include "content/browser/frame_host/frame_tree.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +const char kFrameTreeNodeBlameContextCategory[] = "navigation"; |
| +const char kFrameTreeNodeBlameContextName[] = "FrameTreeNode"; |
| +const char kFrameTreeNodeBlameContextType[] = "Frame"; |
| +const char kFrameTreeNodeBlameContextScope[] = "FrameTreeNode"; |
| + |
| +FrameTreeNodeBlameContext::FrameTreeNodeBlameContext(FrameTreeNode* node) |
| + : base::trace_event::BlameContext(kFrameTreeNodeBlameContextCategory, |
| + kFrameTreeNodeBlameContextName, |
| + kFrameTreeNodeBlameContextType, |
| + kFrameTreeNodeBlameContextScope, |
| + node->frame_tree_node_id(), |
| + node->parent() |
| + ? node->parent()->blame_context() |
| + : nullptr) { |
| + UpdateArguments(node); |
| +} |
| + |
| +FrameTreeNodeBlameContext::~FrameTreeNodeBlameContext() {} |
| + |
| +void FrameTreeNodeBlameContext::ClearArguments() { |
| + process_id_ = -1; |
| + routing_id_ = -1; |
| + url_.clear(); |
| +} |
| + |
| +void FrameTreeNodeBlameContext::UpdateArguments(FrameTreeNode* node) { |
| + RenderFrameHostImpl* current_frame_host = node->current_frame_host(); |
| + if (!current_frame_host) { |
| + ClearArguments(); |
| + return; |
| + } |
| + |
| + // On Windows, |rph->GetHandle()| does not duplicate ownership of the |
| + // process handle and the render host still retains it. Therefore, we |
| + // cannot create a base::Process object, which provides a proper way to get |
| + // a process id, from the handle. For a stopgap, we use this deprecated |
| + // function that does not require the ownership (http://crbug.com/417532). |
| + process_id_ = base::GetProcId(current_frame_host->GetProcess()->GetHandle()); |
| + |
| + routing_id_ = current_frame_host->GetRoutingID(); |
| + DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
| + |
| + if (current_frame_host->last_committed_url().is_valid()) |
| + url_ = current_frame_host->last_committed_url().spec(); |
| + else |
| + url_.clear(); |
| +} |
| + |
| +void FrameTreeNodeBlameContext::AsValueInto( |
|
benjhayden
2016/04/20 01:37:34
Hm, it looks like there might be a gotcha here: th
Xiaocheng
2016/04/20 02:01:05
Thanks for pointing out the gotcha and let me thin
Sami
2016/04/20 12:15:08
IMO the most straightforward way to avoid threadin
benjhayden
2016/04/20 17:29:45
If re-creating the BlameContext when the url chang
Xiaocheng
2016/04/21 08:01:31
To me, adding a lock seems to be the most painless
|
| + base::trace_event::TracedValue* value) { |
| + BlameContext::AsValueInto(value); |
| + |
| + if (process_id_ >= 0) { |
| + value->BeginDictionary("RenderFrame"); |
| + value->SetInteger("pid_ref", process_id_); |
| + value->SetString("id_ref", base::StringPrintf("0x%x", routing_id_)); |
| + value->SetString("scope", "RenderFrame"); |
| + value->EndDictionary(); |
| + } |
| + |
| + if (!url_.empty()) |
| + value->SetString("url", url_); |
| +} |
| + |
| +} // content |