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

Side by Side Diff: blimp/engine/session/page_load_tracker.cc

Issue 2483933003: blimp: Fix page load status tracking. (Closed)
Patch Set: Created 4 years, 1 month 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 | « blimp/engine/session/page_load_tracker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "blimp/engine/session/page_load_tracker.h" 5 #include "blimp/engine/session/page_load_tracker.h"
6 6
7 #include "content/public/browser/navigation_handle.h"
7 #include "content/public/browser/render_widget_host_view.h" 8 #include "content/public/browser/render_widget_host_view.h"
8 9
9 namespace blimp { 10 namespace blimp {
10 namespace engine { 11 namespace engine {
11 12
12 namespace { 13 namespace {
13 14
14 content::RenderWidgetHost* GetRenderWidgetHostIfMainFrame( 15 bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle) {
15 content::RenderFrameHost* render_frame_host) { 16 // We change the progress bar for main frame navigations only.
16 if (render_frame_host->GetParent() != nullptr) 17 if (!navigation_handle->IsInMainFrame())
17 return nullptr; 18 return true;
18 19
19 return render_frame_host->GetView()->GetRenderWidgetHost(); 20 // Same page navigations don't need to trigger a progress bar update.
21 if (navigation_handle->IsSamePage())
22 return true;
23
24 return false;
20 } 25 }
21 26
22 } // namespace 27 } // namespace
23 28
24 PageLoadTracker::PageLoadTracker(content::WebContents* web_contents, 29 PageLoadTracker::PageLoadTracker(content::WebContents* web_contents,
25 PageLoadTrackerClient* client) 30 PageLoadTrackerClient* client)
26 : client_(client) { 31 : client_(client), weak_factory_(this) {
27 DCHECK(web_contents); 32 DCHECK(web_contents);
28 Observe(web_contents); 33 Observe(web_contents);
29 } 34 }
30 35
31 PageLoadTracker::~PageLoadTracker() {} 36 PageLoadTracker::~PageLoadTracker() {}
32 37
33 void PageLoadTracker::DidStartProvisionalLoadForFrame( 38 void PageLoadTracker::DidStartNavigation(
34 content::RenderFrameHost* render_frame_host, 39 content::NavigationHandle* navigation_handle) {
35 const GURL& validated_url, 40 if (ShouldIgnoreNavigation(navigation_handle))
36 bool is_error_page,
37 bool is_iframe_srcdoc) {
38 content::RenderWidgetHost* render_widget_host =
39 GetRenderWidgetHostIfMainFrame(render_frame_host);
40 if (!render_widget_host)
41 return; 41 return;
42 42
43 render_widget_load_status_[render_widget_host] = LoadStatus(); 43 DCHECK(!navigation_pending_)
44 44 << "There should be only one navigation in the main frame for a tab";
nasko 2016/11/08 16:39:27 I don't think this is a correct DCHECK. It is quit
Khushal 2016/11/08 20:52:25 I made sure to explicitly ignore same page navigat
nasko 2016/11/08 21:55:15 I still think it is possible without same page nav
Khushal 2016/11/08 23:54:06 Oh oh. I already came here trying to fix one DCHEC
Khushal 2016/11/11 01:53:35 Done.
45 // Notify the client that a navigation was initiated. 45 navigation_pending_ = true;
46 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADING); 46 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADING);
47 } 47 }
48 48
49 void PageLoadTracker::DidFinishLoad(content::RenderFrameHost* render_frame_host, 49 void PageLoadTracker::DidFinishNavigation(
50 const GURL& validated_url) { 50 content::NavigationHandle* navigation_handle) {
51 content::RenderWidgetHost* render_widget_host = 51 if (ShouldIgnoreNavigation(navigation_handle))
52 GetRenderWidgetHostIfMainFrame(render_frame_host);
53 if (!render_widget_host)
54 return; 52 return;
55 53
56 RenderWidgetLoadStatusMap::iterator it = 54 DCHECK(navigation_pending_);
57 render_widget_load_status_.find(render_widget_host); 55 navigation_pending_ = false;
58 DCHECK(it != render_widget_load_status_.end());
59 56
60 it->second.page_loaded = true; 57 if (navigation_handle->HasCommitted()) {
nasko 2016/11/08 16:39:27 Does this code care about error page vs real docum
Khushal 2016/11/08 20:52:25 Not at the moment. This code is very ad-hoc, and s
nasko 2016/11/08 21:55:15 Acknowledged.
61 if (it->second.Loaded()) { 58 // Make sure that at least one frame after the navigation commits is sent to
nasko 2016/11/08 16:39:27 nit: Be specific when you say "frame" as it is a v
Khushal 2016/11/08 20:52:25 Yes, it means an update to the compositor's conten
Khushal 2016/11/11 01:53:35 Done.
59 // the client.
60 // Note that a visual state update in our case implies that this callback
61 // will be invoked after a frame is queued to be sent to the client.
62 navigation_handle->GetRenderFrameHost()->InsertVisualStateCallback(
63 base::Bind(&PageLoadTracker::DidPaintAfterNavigationCommitted,
nasko 2016/11/08 16:39:27 This seems open to raciness. It could very well be
Khushal 2016/11/08 20:52:25 Good point. Could I use a cancelable callback then
Khushal 2016/11/08 21:20:57 Sorry, I meant each time we get a new pending navi
nasko 2016/11/08 21:55:15 I'm not sure it will fully eliminate the race. If
Khushal 2016/11/08 23:54:06 Its true, we could have a drawing frame in the IPC
kenrb 2016/11/10 18:11:42 The issues I had to deal with (and still haven't e
Khushal 2016/11/11 01:53:34 Thanks Ken. The id is already attached by the Rend
64 weak_factory_.GetWeakPtr()));
65 } else {
66 // Inform the client to update the progress bar right away.
62 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED); 67 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED);
63 render_widget_load_status_.erase(it);
64 } 68 }
65 } 69 }
66 70
67 void PageLoadTracker::DidFailLoad(content::RenderFrameHost* render_frame_host, 71 void PageLoadTracker::DidPaintAfterNavigationCommitted(bool result) {
68 const GURL& validated_url, 72 // If a navigation is pending, early out. We'll send a complete event based
69 int error_code, 73 // on the status of the currently pending navigation.
70 const base::string16& error_description, 74 if (navigation_pending_)
71 bool was_ignored_by_handler) {
72 content::RenderWidgetHost* render_widget_host =
73 GetRenderWidgetHostIfMainFrame(render_frame_host);
74 if (!render_widget_host)
75 return; 75 return;
76 76
77 RenderWidgetLoadStatusMap::iterator it =
78 render_widget_load_status_.find(render_widget_host);
79 DCHECK(it != render_widget_load_status_.end());
80
81 // If the navigation failed, the client should dismiss the load indicator.
82 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED); 77 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED);
83 render_widget_load_status_.erase(it);
84 }
85
86 void PageLoadTracker::DidFirstPaintAfterLoad(
87 content::RenderWidgetHost* render_widget_host) {
88 RenderWidgetLoadStatusMap::iterator it =
89 render_widget_load_status_.find(render_widget_host);
90 DCHECK(it != render_widget_load_status_.end());
91
92 it->second.did_first_paint = true;
93 if (it->second.Loaded()) {
94 client_->SendPageLoadStatusUpdate(PageLoadStatus::LOADED);
95 render_widget_load_status_.erase(it);
96 }
97 }
98
99 bool PageLoadTracker::LoadStatus::Loaded() const {
100 return page_loaded && did_first_paint;
101 } 78 }
102 79
103 } // namespace engine 80 } // namespace engine
104 } // namespace blimp 81 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/session/page_load_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698