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

Side by Side Diff: content/renderer/load_progress_tracker.cc

Issue 9185026: Convert use of int ms to TimeDelta in files owned by brettw. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Explicitly include base/time.h in header file. Created 8 years, 11 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/ppapi_plugin/plugin_process_dispatcher.cc ('k') | content/renderer/render_widget.cc » ('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 (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
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 }
OLDNEW
« no previous file with comments | « content/ppapi_plugin/plugin_process_dispatcher.cc ('k') | content/renderer/render_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698