OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/load_progress_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 if (!tracked_frame_) | 45 if (!tracked_frame_) |
46 tracked_frame_ = frame; | 46 tracked_frame_ = frame; |
47 | 47 |
48 progress_ = progress; | 48 progress_ = progress; |
49 | 49 |
50 // We send the progress change to the browser immediately for the first and | 50 // We send the progress change to the browser immediately for the first and |
51 // last updates. Also, since the message loop may be pretty busy when a page | 51 // last updates. Also, since the message loop may be pretty busy when a page |
52 // is loaded, it might not execute a posted task in a timely manner so we make | 52 // is loaded, it might not execute a posted task in a timely manner so we make |
53 // sure to immediately send progress report if enough time has passed. | 53 // sure to immediately send progress report if enough time has passed. |
| 54 base::TimeDelta min_delay = |
| 55 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenUpdatesMS); |
54 if (progress == 1.0 || last_time_progress_sent_.is_null() || | 56 if (progress == 1.0 || last_time_progress_sent_.is_null() || |
55 (base::TimeTicks::Now() - last_time_progress_sent_).InMilliseconds() > | 57 base::TimeTicks::Now() - last_time_progress_sent_ > |
56 kMinimumDelayBetweenUpdatesMS) { | 58 min_delay) { |
57 // If there is a pending task to send progress, it is now obsolete. | 59 // If there is a pending task to send progress, it is now obsolete. |
58 weak_factory_.InvalidateWeakPtrs(); | 60 weak_factory_.InvalidateWeakPtrs(); |
59 SendChangeLoadProgress(); | 61 SendChangeLoadProgress(); |
60 if (progress == 1.0) | 62 if (progress == 1.0) |
61 ResetStates(); | 63 ResetStates(); |
62 return; | 64 return; |
63 } | 65 } |
64 | 66 |
65 if (weak_factory_.HasWeakPtrs()) | 67 if (weak_factory_.HasWeakPtrs()) |
66 return; | 68 return; |
67 | 69 |
68 MessageLoop::current()->PostDelayedTask( | 70 MessageLoop::current()->PostDelayedTask( |
69 FROM_HERE, | 71 FROM_HERE, |
70 base::Bind(&LoadProgressTracker::SendChangeLoadProgress, | 72 base::Bind(&LoadProgressTracker::SendChangeLoadProgress, |
71 weak_factory_.GetWeakPtr()), | 73 weak_factory_.GetWeakPtr()), |
72 kMinimumDelayBetweenUpdatesMS); | 74 min_delay); |
73 } | 75 } |
74 | 76 |
75 void LoadProgressTracker::SendChangeLoadProgress() { | 77 void LoadProgressTracker::SendChangeLoadProgress() { |
76 last_time_progress_sent_ = base::TimeTicks::Now(); | 78 last_time_progress_sent_ = base::TimeTicks::Now(); |
77 render_view_->Send( | 79 render_view_->Send( |
78 new ViewHostMsg_DidChangeLoadProgress(render_view_->routing_id(), | 80 new ViewHostMsg_DidChangeLoadProgress(render_view_->routing_id(), |
79 progress_)); | 81 progress_)); |
80 } | 82 } |
81 | 83 |
82 void LoadProgressTracker::ResetStates() { | 84 void LoadProgressTracker::ResetStates() { |
83 tracked_frame_ = NULL; | 85 tracked_frame_ = NULL; |
84 progress_ = 0.0; | 86 progress_ = 0.0; |
85 weak_factory_.InvalidateWeakPtrs(); | 87 weak_factory_.InvalidateWeakPtrs(); |
86 last_time_progress_sent_ = base::TimeTicks(); | 88 last_time_progress_sent_ = base::TimeTicks(); |
87 } | 89 } |
OLD | NEW |