Chromium Code Reviews| Index: content/browser/frame_host/frame_tree_node_blame_context.h |
| diff --git a/content/browser/frame_host/frame_tree_node_blame_context.h b/content/browser/frame_host/frame_tree_node_blame_context.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9042ef31021c6a2abcadf21d24e3baedfaaff852 |
| --- /dev/null |
| +++ b/content/browser/frame_host/frame_tree_node_blame_context.h |
| @@ -0,0 +1,79 @@ |
| +// 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. |
| + |
| +#ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_BLAME_CONTEXT_H |
| +#define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_BLAME_CONTEXT_H |
| + |
| +#include "base/macros.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/trace_event/blame_context.h" |
| +#include "url/gurl.h" |
| + |
| +namespace base { |
| +namespace trace_event { |
| +class TracedValue; |
| +} |
| +} |
| + |
| +namespace content { |
| + |
| +class FrameTreeNode; |
| + |
| +// FrameTreeNodeBlameContext is a helper class for tracing snapshots of each |
| +// FrameTreeNode and attributing browser activities to frames (when possible), |
| +// in the framework of FrameBlamer (crbug.com/546021). |
| +// |
| +// |
| +// *** LIFECYCLE *** |
| +// |
| +// Each FrameTreeNodeBlameContext is owned by a FrameTreeNode, and each |
| +// FrameTreeNode owns at most one FrameTreeNodeBlameContext. The lifecycle |
| +// of each FrameTreeNodeBlameContext is managed by its owner node. |
| +// Creation: For each root FrameTreeNode, its blame context is created right |
| +// after the node's intialization. For each other node, its blame context is |
| +// created after the node is attached to a parent node. If the owner node is |
| +// reattached to a different parent node, its original blame context gets |
| +// destroyed and replaced by a new one. |
| +// Update: Whenever the owner node navigates, it calls UpdateArguments() of |
| +// its blame context to update its value. The is the only way to update the |
| +// value of a FrameTreeNodeBlameContext. |
| +// Deletion: A FrameTreeNodeBlameContext is deleted when its owner node is |
| +// deleted or reattached to a different parent node. |
| +// |
| +// |
| +// *** THREAD SAFETY *** |
| +// |
| +// FrameTreeNodeBlameContexts live in the main thread, with their lifecycle |
| +// managed by their owner FrameTreeNodes. The creation, update and deletion |
| +// can only be done in the main thread. However, a FrameTreeNodeBlameContext |
| +// can be read from a different thread, e.g., from the File thread at tracing |
| +// startup. To prevent data race while minimizing architectural impact, locks |
| +// are applied so that AsValueInto() will be blocked when the main thread is |
| +// running UpdateArguments(). |
| + |
| +class FrameTreeNodeBlameContext : public base::trace_event::BlameContext { |
| + public: |
| + // Public functions are callable only from the main thread by the owner node. |
| + FrameTreeNodeBlameContext(FrameTreeNode* node); |
|
dcheng
2016/04/26 20:06:29
Nit: explicit
|
| + ~FrameTreeNodeBlameContext() override; |
| + void UpdateArguments(); |
| + |
| + private: |
| + void AsValueInto(base::trace_event::TracedValue* value) override; |
| + |
| + // Buffered information of the owner node, maintained by UpdateArguments(). |
| + int process_id_; |
| + int routing_id_; |
| + GURL url_; |
| + |
| + FrameTreeNode* const owner_; |
| + |
| + mutable base::Lock lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FrameTreeNodeBlameContext); |
| +}; |
| + |
| +} // content |
| + |
| +#endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_BLAME_CONTEXT_H |