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

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

Issue 1015243004: Move load progress tracking logic to the frame tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Readding TODO Created 5 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
« no previous file with comments | « content/browser/frame_host/frame_tree.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 28 matching lines...) Expand all
39 FrameTreeNode* node) { 39 FrameTreeNode* node) {
40 // If a new frame is created in the current SiteInstance, other frames in 40 // If a new frame is created in the current SiteInstance, other frames in
41 // that SiteInstance don't need a proxy for the new frame. 41 // that SiteInstance don't need a proxy for the new frame.
42 SiteInstance* current_instance = 42 SiteInstance* current_instance =
43 node->render_manager()->current_frame_host()->GetSiteInstance(); 43 node->render_manager()->current_frame_host()->GetSiteInstance();
44 if (current_instance != instance.get()) 44 if (current_instance != instance.get())
45 node->render_manager()->CreateRenderFrameProxy(instance.get()); 45 node->render_manager()->CreateRenderFrameProxy(instance.get());
46 return true; 46 return true;
47 } 47 }
48 48
49 // Helper function used with FrameTree::ForEach() for retrieving the total
50 // loading progress and number of frames in a frame tree.
51 bool CollectLoadProgress(double* progress,
52 int* frame_count,
53 FrameTreeNode* node) {
54 // Ignore the current frame if it has not started loading.
55 double frame_progress = node->loading_progress();
56 if (frame_progress == FrameTreeNode::kLoadingProgressNotStarted)
57 return true;
58
59 // Collect progress.
60 *progress += frame_progress;
61 (*frame_count)++;
62 return true;
63 }
64
65 // Helper function used with FrameTree::ForEach() to reset the load progress.
66 bool ResetNodeLoadProgress(FrameTreeNode* node) {
67 node->set_loading_progress(FrameTreeNode::kLoadingProgressNotStarted);
68 return true;
69 }
70
71 // Helper function used with FrameTree::ForEach() to check if at least one of
72 // the nodes is loading.
73 bool IsNodeLoading(bool* is_loading, FrameTreeNode* node) {
74 if (node->IsLoading()) {
75 // There is at least one node loading, so abort traversal.
76 *is_loading = true;
77 return false;
78 }
79 return true;
80 }
81
49 } // namespace 82 } // namespace
50 83
51 FrameTree::FrameTree(Navigator* navigator, 84 FrameTree::FrameTree(Navigator* navigator,
52 RenderFrameHostDelegate* render_frame_delegate, 85 RenderFrameHostDelegate* render_frame_delegate,
53 RenderViewHostDelegate* render_view_delegate, 86 RenderViewHostDelegate* render_view_delegate,
54 RenderWidgetHostDelegate* render_widget_delegate, 87 RenderWidgetHostDelegate* render_widget_delegate,
55 RenderFrameHostManager::Delegate* manager_delegate) 88 RenderFrameHostManager::Delegate* manager_delegate)
56 : render_frame_delegate_(render_frame_delegate), 89 : render_frame_delegate_(render_frame_delegate),
57 render_view_delegate_(render_view_delegate), 90 render_view_delegate_(render_view_delegate),
58 render_widget_delegate_(render_widget_delegate), 91 render_widget_delegate_(render_widget_delegate),
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 void FrameTree::FrameRemoved(FrameTreeNode* frame) { 338 void FrameTree::FrameRemoved(FrameTreeNode* frame) {
306 // No notification for the root frame. 339 // No notification for the root frame.
307 if (frame == root_.get()) 340 if (frame == root_.get())
308 return; 341 return;
309 342
310 // Notify observers of the frame removal. 343 // Notify observers of the frame removal.
311 if (!on_frame_removed_.is_null()) 344 if (!on_frame_removed_.is_null())
312 on_frame_removed_.Run(frame->current_frame_host()); 345 on_frame_removed_.Run(frame->current_frame_host());
313 } 346 }
314 347
348 double FrameTree::GetLoadProgress() {
349 double progress = 0.0;
350 int frame_count = 0;
351
352 ForEach(base::Bind(&CollectLoadProgress, &progress, &frame_count));
353 if (frame_count != 0)
354 progress /= frame_count;
355 return progress;
356 }
357
358 void FrameTree::ResetLoadProgress() {
359 ForEach(base::Bind(&ResetNodeLoadProgress));
360 }
361
362 bool FrameTree::IsLoading() {
363 bool is_loading = false;
364 ForEach(base::Bind(&IsNodeLoading, &is_loading));
365 return is_loading;
366 }
367
315 } // namespace content 368 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698