Chromium Code Reviews| Index: content/renderer/load_progress_tracker.cc |
| diff --git a/content/renderer/load_progress_tracker.cc b/content/renderer/load_progress_tracker.cc |
| index 0cc26fdcccf14ef4ac74b52f9ea36d252fe85d91..05c3ed6675e05af2d886a0e9e75f7f6c612b14ad 100644 |
| --- a/content/renderer/load_progress_tracker.cc |
| +++ b/content/renderer/load_progress_tracker.cc |
| @@ -14,39 +14,42 @@ namespace { |
| const int kMinimumDelayBetweenUpdatesMS = 100; |
| +// This matches what blink's ProgrssTracker has traditionally used for a |
| +// minmum progress value. |
|
Charlie Reis
2014/03/11 21:51:12
nit: minimum
|
| +const double kMinimumProgress = 0.1; |
| + |
| } |
| LoadProgressTracker::LoadProgressTracker(RenderViewImpl* render_view) |
| : render_view_(render_view), |
| - tracked_frame_(NULL), |
| - progress_(0.0), |
| + total_progress_(0.0), |
| weak_factory_(this) { |
| } |
| LoadProgressTracker::~LoadProgressTracker() { |
| } |
| -void LoadProgressTracker::DidStopLoading() { |
| - if (!tracked_frame_) |
| +void LoadProgressTracker::DidStartLoading(int frame_routing_id) { |
| + progresses_[frame_routing_id] = kMinimumProgress; |
| + SendChangeLoadProgress(); |
| +} |
| + |
| +void LoadProgressTracker::DidStopLoading(int frame_routing_id) { |
| + if (progresses_.find(frame_routing_id) == progresses_.end()) |
| return; |
| - // Load stopped while we were still tracking load. Make sure we notify the |
| - // browser that load is complete. |
| - progress_ = 1.0; |
| + // Load stopped while we were still tracking load. Make sure we update |
| + // progress based on this frame's completion. |
| + progresses_[frame_routing_id] = 1.0; |
| SendChangeLoadProgress(); |
| // Then we clean-up our states. |
| - ResetStates(); |
| + if (total_progress_ == 1.0) |
| + ResetStates(); |
| } |
| -void LoadProgressTracker::DidChangeLoadProgress(blink::WebFrame* frame, |
| +void LoadProgressTracker::DidChangeLoadProgress(int frame_routing_id, |
| double progress) { |
| - if (tracked_frame_ && frame != tracked_frame_) |
| - return; |
| - |
| - if (!tracked_frame_) |
| - tracked_frame_ = frame; |
| - |
| - progress_ = progress; |
| + progresses_[frame_routing_id] = progress; |
| // We send the progress change to the browser immediately for the first and |
| // last updates. Also, since the message loop may be pretty busy when a page |
| @@ -60,7 +63,7 @@ void LoadProgressTracker::DidChangeLoadProgress(blink::WebFrame* frame, |
| // If there is a pending task to send progress, it is now obsolete. |
| weak_factory_.InvalidateWeakPtrs(); |
| SendChangeLoadProgress(); |
| - if (progress == 1.0) |
| + if (total_progress_ == 1.0) |
| ResetStates(); |
| return; |
| } |
| @@ -77,14 +80,28 @@ void LoadProgressTracker::DidChangeLoadProgress(blink::WebFrame* frame, |
| void LoadProgressTracker::SendChangeLoadProgress() { |
| last_time_progress_sent_ = base::TimeTicks::Now(); |
| + double progress = 0.0; |
| + unsigned frameCount = 0; |
| + ProgressMap::iterator end = progresses_.end(); |
| + for (ProgressMap::iterator it = progresses_.begin(); it != end; ++it) { |
| + progress += it->second; |
| + frameCount++; |
| + } |
| + progress /= frameCount; |
|
Charlie Reis
2014/03/11 21:51:12
This is crying out to divide by zero if progresses
Nate Chapin
2014/03/11 22:09:59
That shouldn't be possible, but...yeah, let's just
|
| + DCHECK(progress <= 1.0); |
| + |
| + if (progress <= total_progress_) |
| + return; |
| + total_progress_ = progress; |
| + |
| render_view_->Send( |
| new ViewHostMsg_DidChangeLoadProgress(render_view_->routing_id(), |
| - progress_)); |
| + progress)); |
| } |
| void LoadProgressTracker::ResetStates() { |
| - tracked_frame_ = NULL; |
| - progress_ = 0.0; |
| + progresses_.clear(); |
| + total_progress_ = 0.0; |
| weak_factory_.InvalidateWeakPtrs(); |
| last_time_progress_sent_ = base::TimeTicks(); |
| } |