| 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 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_BLAME_CONTEXT_H |
| 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_BLAME_CONTEXT_H |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "base/trace_event/blame_context.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace base { |
| 14 namespace trace_event { |
| 15 class TracedValue; |
| 16 } |
| 17 } |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class FrameTreeNode; |
| 22 |
| 23 // FrameTreeNodeBlameContext is a helper class for tracing snapshots of each |
| 24 // FrameTreeNode and attributing browser activities to frames (when possible), |
| 25 // in the framework of FrameBlamer (crbug.com/546021). |
| 26 // |
| 27 // |
| 28 // *** LIFECYCLE *** |
| 29 // |
| 30 // Each FrameTreeNodeBlameContext is owned by a FrameTreeNode, and each |
| 31 // FrameTreeNode owns at most one FrameTreeNodeBlameContext. The lifecycle |
| 32 // of each FrameTreeNodeBlameContext is managed by its owner node. |
| 33 // Creation: For each root FrameTreeNode, its blame context is created right |
| 34 // after the node's intialization. For each other node, its blame context is |
| 35 // created after the node is attached to a parent node. If the owner node is |
| 36 // reattached to a different parent node, its original blame context gets |
| 37 // destroyed and replaced by a new one. |
| 38 // Update: Whenever the owner node navigates, it calls UpdateArguments() of |
| 39 // its blame context to update its value. The is the only way to update the |
| 40 // value of a FrameTreeNodeBlameContext. |
| 41 // Deletion: A FrameTreeNodeBlameContext is deleted when its owner node is |
| 42 // deleted or reattached to a different parent node. |
| 43 // |
| 44 // |
| 45 // *** THREAD SAFETY *** |
| 46 // |
| 47 // FrameTreeNodeBlameContexts live in the main thread, with their lifecycle |
| 48 // managed by their owner FrameTreeNodes. The creation, update and deletion |
| 49 // can only be done in the main thread. However, a FrameTreeNodeBlameContext |
| 50 // can be read from a different thread, e.g., from the File thread at tracing |
| 51 // startup. To prevent data race while minimizing architectural impact, locks |
| 52 // are applied so that AsValueInto() will be blocked when the main thread is |
| 53 // running UpdateArguments(). |
| 54 |
| 55 class FrameTreeNodeBlameContext : public base::trace_event::BlameContext { |
| 56 public: |
| 57 // Public functions are callable only from the main thread by the owner node. |
| 58 FrameTreeNodeBlameContext(FrameTreeNode* node); |
| 59 ~FrameTreeNodeBlameContext() override; |
| 60 void UpdateArguments(); |
| 61 |
| 62 private: |
| 63 void AsValueInto(base::trace_event::TracedValue* value) override; |
| 64 |
| 65 void ClearArguments(); |
| 66 |
| 67 // Buffered information of the owner node, maintained by UpdateArguments(). |
| 68 int process_id_; |
| 69 int routing_id_; |
| 70 GURL url_; |
| 71 |
| 72 FrameTreeNode* const owner_; |
| 73 |
| 74 mutable base::Lock lock_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(FrameTreeNodeBlameContext); |
| 77 }; |
| 78 |
| 79 } // content |
| 80 |
| 81 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_BLAME_CONTEXT_H |
| OLD | NEW |