Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: content/browser/frame_host/frame_tree_node_blame_context.cc

Issue 1901023003: Introduce browser side FrameTreeNodeBlameContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/frame_tree_node_blame_context.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "base/trace_event/trace_event_argument.h"
9 #include "content/browser/frame_host/frame_tree.h"
10 #include "url/gurl.h"
11
12 namespace content {
13
14 const char kFrameTreeNodeBlameContextCategory[] = "navigation";
15 const char kFrameTreeNodeBlameContextName[] = "FrameTreeNode";
16 const char kFrameTreeNodeBlameContextType[] = "Frame";
17 const char kFrameTreeNodeBlameContextScope[] = "FrameTreeNode";
18
19 FrameTreeNodeBlameContext::FrameTreeNodeBlameContext(FrameTreeNode* node)
20 : base::trace_event::BlameContext(kFrameTreeNodeBlameContextCategory,
21 kFrameTreeNodeBlameContextName,
22 kFrameTreeNodeBlameContextType,
23 kFrameTreeNodeBlameContextScope,
24 node->frame_tree_node_id(),
25 node->parent()
26 ? node->parent()->blame_context()
27 : nullptr) {
28 UpdateArguments(node);
29 }
30
31 FrameTreeNodeBlameContext::~FrameTreeNodeBlameContext() {}
32
33 void FrameTreeNodeBlameContext::ClearArguments() {
34 process_id_ = -1;
35 routing_id_ = -1;
36 url_.clear();
37 }
38
39 void FrameTreeNodeBlameContext::UpdateArguments(FrameTreeNode* node) {
40 RenderFrameHostImpl* current_frame_host = node->current_frame_host();
41 if (!current_frame_host) {
42 ClearArguments();
43 return;
44 }
45
46 // On Windows, |rph->GetHandle()| does not duplicate ownership of the
47 // process handle and the render host still retains it. Therefore, we
48 // cannot create a base::Process object, which provides a proper way to get
49 // a process id, from the handle. For a stopgap, we use this deprecated
50 // function that does not require the ownership (http://crbug.com/417532).
51 process_id_ = base::GetProcId(current_frame_host->GetProcess()->GetHandle());
52
53 routing_id_ = current_frame_host->GetRoutingID();
54 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
55
56 if (current_frame_host->last_committed_url().is_valid())
57 url_ = current_frame_host->last_committed_url().spec();
58 else
59 url_.clear();
60 }
61
62 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
63 base::trace_event::TracedValue* value) {
64 BlameContext::AsValueInto(value);
65
66 if (process_id_ >= 0) {
67 value->BeginDictionary("RenderFrame");
68 value->SetInteger("pid_ref", process_id_);
69 value->SetString("id_ref", base::StringPrintf("0x%x", routing_id_));
70 value->SetString("scope", "RenderFrame");
71 value->EndDictionary();
72 }
73
74 if (!url_.empty())
75 value->SetString("url", url_);
76 }
77
78 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698