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..aab735f64ea33817c5a67d87a6a3675b8ad77897 |
| --- /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), |
| + owner_(node) { |
| + UpdateArguments(); |
| +} |
| + |
| +FrameTreeNodeBlameContext::~FrameTreeNodeBlameContext() {} |
| + |
| +void FrameTreeNodeBlameContext::ClearArguments() { |
| + process_id_ = -1; |
|
benjhayden
2016/04/22 20:34:15
lock?
Xiaocheng
2016/04/25 00:56:28
You're right, this part should also be protected b
|
| + routing_id_ = -1; |
| + url_ = GURL(); |
| +} |
| + |
| +void FrameTreeNodeBlameContext::UpdateArguments() { |
| + RenderFrameHostImpl* current_frame_host = owner_->current_frame_host(); |
| + if (!current_frame_host) { |
| + ClearArguments(); |
| + return; |
| + } |
| + |
| + base::AutoLock lock(lock_); |
| + |
| + // 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); |
| + |
| + url_ = current_frame_host->last_committed_url(); |
| +} |
| + |
| +void FrameTreeNodeBlameContext::AsValueInto( |
| + base::trace_event::TracedValue* value) { |
| + base::AutoLock lock(lock_); |
| + |
| + 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_.is_valid()) |
| + value->SetString("url", url_.spec()); |
| +} |
| + |
| +} // content |