| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/frame_host/frame_tree.h" | 5 #include "content/browser/frame_host/frame_tree.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "content/browser/frame_host/frame_tree_node.h" | 13 #include "content/browser/frame_host/frame_tree_node.h" |
| 14 #include "content/browser/frame_host/navigator.h" | 14 #include "content/browser/frame_host/navigator.h" |
| 15 #include "content/browser/frame_host/render_frame_host_factory.h" | 15 #include "content/browser/frame_host/render_frame_host_factory.h" |
| 16 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 17 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 17 #include "content/browser/renderer_host/render_view_host_factory.h" | 18 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 18 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // This is a global map between frame_tree_node_ids and pointer to | 26 // This is a global map between frame_tree_node_ids and pointer to |
| 26 // FrameTreeNodes. | 27 // FrameTreeNodes. |
| 27 typedef base::hash_map<int64, FrameTreeNode*> FrameTreeNodeIDMap; | 28 typedef base::hash_map<int64, FrameTreeNode*> FrameTreeNodeIDMap; |
| 28 | 29 |
| 29 base::LazyInstance<FrameTreeNodeIDMap> g_frame_tree_node_id_map = | 30 base::LazyInstance<FrameTreeNodeIDMap> g_frame_tree_node_id_map = |
| 30 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
| 31 | 32 |
| 32 // Used with FrameTree::ForEach() to search for the FrameTreeNode | 33 // Used with FrameTree::ForEach() to search for the FrameTreeNode |
| 33 // corresponding to |frame_tree_node_id| whithin a specific FrameTree. | 34 // corresponding to |frame_tree_node_id| whithin a specific FrameTree. |
| 34 bool FrameTreeNodeForId(int64 frame_tree_node_id, | 35 bool FrameTreeNodeForId(int64 frame_tree_node_id, |
| 35 FrameTreeNode** out_node, | 36 FrameTreeNode** out_node, |
| 36 FrameTreeNode* node) { | 37 FrameTreeNode* node) { |
| 37 if (node->frame_tree_node_id() == frame_tree_node_id) { | 38 if (node->frame_tree_node_id() == frame_tree_node_id) { |
| 38 *out_node = node; | 39 *out_node = node; |
| 39 // Terminate iteration once the node has been found. | 40 // Terminate iteration once the node has been found. |
| 40 return false; | 41 return false; |
| 41 } | 42 } |
| 42 return true; | 43 return true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool FrameTreeNodeForRoutingId(int routing_id, | |
| 46 int process_id, | |
| 47 FrameTreeNode** out_node, | |
| 48 FrameTreeNode* node) { | |
| 49 // TODO(creis): Look through the swapped out RFHs as well. | |
| 50 if (node->current_frame_host()->GetProcess()->GetID() == process_id && | |
| 51 node->current_frame_host()->GetRoutingID() == routing_id) { | |
| 52 *out_node = node; | |
| 53 // Terminate iteration once the node has been found. | |
| 54 return false; | |
| 55 } | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 // Iterate over the FrameTree to reset any node affected by the loss of the | 46 // Iterate over the FrameTree to reset any node affected by the loss of the |
| 60 // given RenderViewHost's process. | 47 // given RenderViewHost's process. |
| 61 bool ResetNodesForNewProcess(RenderViewHost* render_view_host, | 48 bool ResetNodesForNewProcess(RenderViewHost* render_view_host, |
| 62 FrameTreeNode* node) { | 49 FrameTreeNode* node) { |
| 63 if (render_view_host == node->current_frame_host()->render_view_host()) | 50 if (render_view_host == node->current_frame_host()->render_view_host()) |
| 64 node->ResetForNewProcess(); | 51 node->ResetForNewProcess(); |
| 65 return true; | 52 return true; |
| 66 } | 53 } |
| 67 | 54 |
| 68 bool CreateProxyForSiteInstance(FrameTreeNode* source_node, | 55 bool CreateProxyForSiteInstance(FrameTreeNode* source_node, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return it == nodes->end() ? NULL : it->second; | 100 return it == nodes->end() ? NULL : it->second; |
| 114 } | 101 } |
| 115 | 102 |
| 116 FrameTreeNode* FrameTree::FindByID(int64 frame_tree_node_id) { | 103 FrameTreeNode* FrameTree::FindByID(int64 frame_tree_node_id) { |
| 117 FrameTreeNode* node = NULL; | 104 FrameTreeNode* node = NULL; |
| 118 ForEach(base::Bind(&FrameTreeNodeForId, frame_tree_node_id, &node)); | 105 ForEach(base::Bind(&FrameTreeNodeForId, frame_tree_node_id, &node)); |
| 119 return node; | 106 return node; |
| 120 } | 107 } |
| 121 | 108 |
| 122 FrameTreeNode* FrameTree::FindByRoutingID(int routing_id, int process_id) { | 109 FrameTreeNode* FrameTree::FindByRoutingID(int routing_id, int process_id) { |
| 123 FrameTreeNode* node = NULL; | 110 RenderFrameHostImpl* render_frame_host = |
| 124 ForEach( | 111 RenderFrameHostImpl::FromID(process_id, routing_id); |
| 125 base::Bind(&FrameTreeNodeForRoutingId, routing_id, process_id, &node)); | 112 if (render_frame_host) { |
| 126 return node; | 113 FrameTreeNode* result = render_frame_host->frame_tree_node(); |
| 114 if (this == result->frame_tree()) |
| 115 return result; |
| 116 } |
| 117 |
| 118 RenderFrameProxyHost* render_frame_proxy_host = |
| 119 RenderFrameProxyHost::FromID(process_id, routing_id); |
| 120 if (render_frame_proxy_host) { |
| 121 FrameTreeNode* result = render_frame_proxy_host->frame_tree_node(); |
| 122 if (this == result->frame_tree()) |
| 123 return result; |
| 124 } |
| 125 |
| 126 return NULL; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void FrameTree::ForEach( | 129 void FrameTree::ForEach( |
| 130 const base::Callback<bool(FrameTreeNode*)>& on_node) const { | 130 const base::Callback<bool(FrameTreeNode*)>& on_node) const { |
| 131 std::queue<FrameTreeNode*> queue; | 131 std::queue<FrameTreeNode*> queue; |
| 132 queue.push(root_.get()); | 132 queue.push(root_.get()); |
| 133 | 133 |
| 134 while (!queue.empty()) { | 134 while (!queue.empty()) { |
| 135 FrameTreeNode* node = queue.front(); | 135 FrameTreeNode* node = queue.front(); |
| 136 queue.pop(); | 136 queue.pop(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 rvh->Shutdown(); | 322 rvh->Shutdown(); |
| 323 render_view_host_pending_shutdown_map_.erase(multi_iter); | 323 render_view_host_pending_shutdown_map_.erase(multi_iter); |
| 324 } | 324 } |
| 325 break; | 325 break; |
| 326 } | 326 } |
| 327 CHECK(render_view_host_found); | 327 CHECK(render_view_host_found); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 } // namespace content | 331 } // namespace content |
| OLD | NEW |