OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/load_progress_tracker.h" | 5 #include "content/browser/frame_host/load_progress_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/browser/frame_host/navigator_delegate.h" |
10 #include "content/renderer/render_view_impl.h" | |
11 | 10 |
12 namespace content { | 11 namespace content { |
13 namespace { | 12 namespace { |
14 | 13 |
15 const int kMinimumDelayBetweenUpdatesMS = 100; | 14 const int kMinimumDelayBetweenUpdatesMS = 100; |
16 | 15 |
17 // This matches what blink's ProgrssTracker has traditionally used for a | 16 // This matches what Blink's ProgressTracker has traditionally used for a |
18 // minimum progress value. | 17 // minimum progress value. |
19 const double kMinimumProgress = 0.1; | 18 const double kMinimumProgress = 0.1; |
20 | 19 |
21 } | 20 } |
22 | 21 |
23 LoadProgressTracker::LoadProgressTracker(RenderViewImpl* render_view) | 22 LoadProgressTracker::LoadProgressTracker(NavigatorDelegate* delegate) |
24 : render_view_(render_view), | 23 : delegate_(delegate), |
25 total_progress_(0.0), | 24 total_progress_(0.0), |
26 weak_factory_(this) { | 25 weak_factory_(this) { |
27 } | 26 } |
28 | 27 |
29 LoadProgressTracker::~LoadProgressTracker() { | 28 LoadProgressTracker::~LoadProgressTracker() { |
30 } | 29 } |
31 | 30 |
32 void LoadProgressTracker::DidStartLoading(int frame_routing_id) { | 31 void LoadProgressTracker::DidStartLoading(int frame_routing_id) { |
33 progresses_[frame_routing_id] = kMinimumProgress; | 32 progresses_[frame_routing_id] = kMinimumProgress; |
34 SendChangeLoadProgress(); | 33 SendChangeLoadProgress(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 87 } |
89 if (frameCount == 0) | 88 if (frameCount == 0) |
90 return; | 89 return; |
91 progress /= frameCount; | 90 progress /= frameCount; |
92 DCHECK(progress <= 1.0); | 91 DCHECK(progress <= 1.0); |
93 | 92 |
94 if (progress <= total_progress_) | 93 if (progress <= total_progress_) |
95 return; | 94 return; |
96 total_progress_ = progress; | 95 total_progress_ = progress; |
97 | 96 |
98 render_view_->Send( | 97 if (delegate_) |
99 new ViewHostMsg_DidChangeLoadProgress(render_view_->routing_id(), | 98 delegate_->DidChangeLoadProgress(progress); |
100 progress)); | |
101 } | 99 } |
102 | 100 |
103 void LoadProgressTracker::ResetStates() { | 101 void LoadProgressTracker::ResetStates() { |
104 progresses_.clear(); | 102 progresses_.clear(); |
105 total_progress_ = 0.0; | 103 total_progress_ = 0.0; |
106 weak_factory_.InvalidateWeakPtrs(); | 104 weak_factory_.InvalidateWeakPtrs(); |
107 last_time_progress_sent_ = base::TimeTicks(); | 105 last_time_progress_sent_ = base::TimeTicks(); |
108 } | 106 } |
109 | 107 |
110 } // namespace content | 108 } // namespace content |
OLD | NEW |