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

Side by Side Diff: Source/core/loader/ProgressTracker.cpp

Issue 31063004: Have Frame::loader() return a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/Prerenderer.cpp ('k') | Source/core/loader/appcache/ApplicationCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 void ProgressTracker::progressStarted(Frame* frame) 105 void ProgressTracker::progressStarted(Frame* frame)
106 { 106 {
107 LOG(Progress, "Progress started (%p) - frame %p(\"%s\"), value %f, tracked f rames %d, originating frame %p", this, frame, frame->tree().uniqueName().string( ).utf8().data(), m_progressValue, m_numProgressTrackedFrames, m_originatingProgr essFrame.get()); 107 LOG(Progress, "Progress started (%p) - frame %p(\"%s\"), value %f, tracked f rames %d, originating frame %p", this, frame, frame->tree().uniqueName().string( ).utf8().data(), m_progressValue, m_numProgressTrackedFrames, m_originatingProgr essFrame.get());
108 108
109 if (m_numProgressTrackedFrames == 0 || m_originatingProgressFrame == frame) { 109 if (m_numProgressTrackedFrames == 0 || m_originatingProgressFrame == frame) {
110 reset(); 110 reset();
111 m_progressValue = initialProgressValue; 111 m_progressValue = initialProgressValue;
112 m_originatingProgressFrame = frame; 112 m_originatingProgressFrame = frame;
113 113
114 m_originatingProgressFrame->loader()->client()->postProgressStartedNotif ication(); 114 m_originatingProgressFrame->loader().client()->postProgressStartedNotifi cation();
115 } 115 }
116 m_numProgressTrackedFrames++; 116 m_numProgressTrackedFrames++;
117 InspectorInstrumentation::frameStartedLoading(frame); 117 InspectorInstrumentation::frameStartedLoading(frame);
118 } 118 }
119 119
120 void ProgressTracker::progressCompleted(Frame* frame) 120 void ProgressTracker::progressCompleted(Frame* frame)
121 { 121 {
122 LOG(Progress, "Progress completed (%p) - frame %p(\"%s\"), value %f, tracked frames %d, originating frame %p", this, frame, frame->tree().uniqueName().strin g().utf8().data(), m_progressValue, m_numProgressTrackedFrames, m_originatingPro gressFrame.get()); 122 LOG(Progress, "Progress completed (%p) - frame %p(\"%s\"), value %f, tracked frames %d, originating frame %p", this, frame, frame->tree().uniqueName().strin g().utf8().data(), m_progressValue, m_numProgressTrackedFrames, m_originatingPro gressFrame.get());
123 123
124 if (m_numProgressTrackedFrames <= 0) 124 if (m_numProgressTrackedFrames <= 0)
125 return; 125 return;
126 m_numProgressTrackedFrames--; 126 m_numProgressTrackedFrames--;
127 if (!m_numProgressTrackedFrames || m_originatingProgressFrame == frame) 127 if (!m_numProgressTrackedFrames || m_originatingProgressFrame == frame)
128 finalProgressComplete(); 128 finalProgressComplete();
129 } 129 }
130 130
131 void ProgressTracker::finalProgressComplete() 131 void ProgressTracker::finalProgressComplete()
132 { 132 {
133 LOG(Progress, "Final progress complete (%p)", this); 133 LOG(Progress, "Final progress complete (%p)", this);
134 134
135 RefPtr<Frame> frame = m_originatingProgressFrame.release(); 135 RefPtr<Frame> frame = m_originatingProgressFrame.release();
136 136
137 // Before resetting progress value be sure to send client a least one notifi cation 137 // Before resetting progress value be sure to send client a least one notifi cation
138 // with final progress value. 138 // with final progress value.
139 if (!m_finalProgressChangedSent) { 139 if (!m_finalProgressChangedSent) {
140 m_progressValue = 1; 140 m_progressValue = 1;
141 frame->loader()->client()->postProgressEstimateChangedNotification(); 141 frame->loader().client()->postProgressEstimateChangedNotification();
142 } 142 }
143 143
144 reset(); 144 reset();
145 frame->loader()->client()->postProgressFinishedNotification(); 145 frame->loader().client()->postProgressFinishedNotification();
146 InspectorInstrumentation::frameStoppedLoading(frame.get()); 146 InspectorInstrumentation::frameStoppedLoading(frame.get());
147 } 147 }
148 148
149 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource Response& response) 149 void ProgressTracker::incrementProgress(unsigned long identifier, const Resource Response& response)
150 { 150 {
151 LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d, orig inating frame %p", this, m_progressValue, m_numProgressTrackedFrames, m_originat ingProgressFrame.get()); 151 LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d, orig inating frame %p", this, m_progressValue, m_numProgressTrackedFrames, m_originat ingProgressFrame.get());
152 152
153 if (m_numProgressTrackedFrames <= 0) 153 if (m_numProgressTrackedFrames <= 0)
154 return; 154 return;
155 155
(...skipping 23 matching lines...) Expand all
179 unsigned bytesReceived = length; 179 unsigned bytesReceived = length;
180 double increment, percentOfRemainingBytes; 180 double increment, percentOfRemainingBytes;
181 long long remainingBytes, estimatedBytesForPendingRequests; 181 long long remainingBytes, estimatedBytesForPendingRequests;
182 182
183 item->bytesReceived += bytesReceived; 183 item->bytesReceived += bytesReceived;
184 if (item->bytesReceived > item->estimatedLength) { 184 if (item->bytesReceived > item->estimatedLength) {
185 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item-> estimatedLength); 185 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item-> estimatedLength);
186 item->estimatedLength = item->bytesReceived * 2; 186 item->estimatedLength = item->bytesReceived * 2;
187 } 187 }
188 188
189 int numPendingOrLoadingRequests = frame->loader()->numPendingOrLoadingReques ts(true); 189 int numPendingOrLoadingRequests = frame->loader().numPendingOrLoadingRequest s(true);
190 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP endingOrLoadingRequests; 190 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP endingOrLoadingRequests;
191 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend ingRequests) - m_totalBytesReceived); 191 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend ingRequests) - m_totalBytesReceived);
192 if (remainingBytes > 0) // Prevent divide by 0. 192 if (remainingBytes > 0) // Prevent divide by 0.
193 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes ; 193 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes ;
194 else 194 else
195 percentOfRemainingBytes = 1.0; 195 percentOfRemainingBytes = 1.0;
196 196
197 // For documents that use WebCore's layout system, treat first layout as the half-way point. 197 // For documents that use WebCore's layout system, treat first layout as the half-way point.
198 bool useClampedMaxProgress = !frame->view()->didFirstLayout(); 198 bool useClampedMaxProgress = !frame->view()->didFirstLayout();
199 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; 199 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue;
200 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; 200 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes;
201 m_progressValue += increment; 201 m_progressValue += increment;
202 m_progressValue = min(m_progressValue, maxProgressValue); 202 m_progressValue = min(m_progressValue, maxProgressValue);
203 ASSERT(m_progressValue >= initialProgressValue); 203 ASSERT(m_progressValue >= initialProgressValue);
204 204
205 m_totalBytesReceived += bytesReceived; 205 m_totalBytesReceived += bytesReceived;
206 206
207 double now = currentTime(); 207 double now = currentTime();
208 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime; 208 double notifiedProgressTimeDelta = now - m_lastNotifiedProgressTime;
209 209
210 LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d", thi s, m_progressValue, m_numProgressTrackedFrames); 210 LOG(Progress, "Progress incremented (%p) - value %f, tracked frames %d", thi s, m_progressValue, m_numProgressTrackedFrames);
211 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV alue; 211 double notificationProgressDelta = m_progressValue - m_lastNotifiedProgressV alue;
212 if ((notificationProgressDelta >= m_progressNotificationInterval || 212 if ((notificationProgressDelta >= m_progressNotificationInterval ||
213 notifiedProgressTimeDelta >= m_progressNotificationTimeInterval) && 213 notifiedProgressTimeDelta >= m_progressNotificationTimeInterval) &&
214 m_numProgressTrackedFrames > 0) { 214 m_numProgressTrackedFrames > 0) {
215 if (!m_finalProgressChangedSent) { 215 if (!m_finalProgressChangedSent) {
216 if (m_progressValue == 1) 216 if (m_progressValue == 1)
217 m_finalProgressChangedSent = true; 217 m_finalProgressChangedSent = true;
218 218
219 frame->loader()->client()->postProgressEstimateChangedNotification() ; 219 frame->loader().client()->postProgressEstimateChangedNotification();
220 220
221 m_lastNotifiedProgressValue = m_progressValue; 221 m_lastNotifiedProgressValue = m_progressValue;
222 m_lastNotifiedProgressTime = now; 222 m_lastNotifiedProgressTime = now;
223 } 223 }
224 } 224 }
225 } 225 }
226 226
227 void ProgressTracker::completeProgress(unsigned long identifier) 227 void ProgressTracker::completeProgress(unsigned long identifier)
228 { 228 {
229 ProgressItem* item = m_progressItems.get(identifier); 229 ProgressItem* item = m_progressItems.get(identifier);
230 230
231 // This can happen if a load fails without receiving any response data. 231 // This can happen if a load fails without receiving any response data.
232 if (!item) 232 if (!item)
233 return; 233 return;
234 234
235 // Adjust the total expected bytes to account for any overage/underage. 235 // Adjust the total expected bytes to account for any overage/underage.
236 long long delta = item->bytesReceived - item->estimatedLength; 236 long long delta = item->bytesReceived - item->estimatedLength;
237 m_totalPageAndResourceBytesToLoad += delta; 237 m_totalPageAndResourceBytesToLoad += delta;
238 238
239 m_progressItems.remove(identifier); 239 m_progressItems.remove(identifier);
240 } 240 }
241 241
242 } 242 }
OLDNEW
« no previous file with comments | « Source/core/loader/Prerenderer.cpp ('k') | Source/core/loader/appcache/ApplicationCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698