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

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

Issue 1187563005: Code cleanup in core/loader/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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/PingLoader.h ('k') | no next file » | 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 19 matching lines...) Expand all
30 #include "core/frame/FrameView.h" 30 #include "core/frame/FrameView.h"
31 #include "core/frame/LocalFrame.h" 31 #include "core/frame/LocalFrame.h"
32 #include "core/inspector/InspectorInstrumentation.h" 32 #include "core/inspector/InspectorInstrumentation.h"
33 #include "core/loader/FrameLoader.h" 33 #include "core/loader/FrameLoader.h"
34 #include "core/loader/FrameLoaderClient.h" 34 #include "core/loader/FrameLoaderClient.h"
35 #include "platform/Logging.h" 35 #include "platform/Logging.h"
36 #include "platform/network/ResourceResponse.h" 36 #include "platform/network/ResourceResponse.h"
37 #include "wtf/CurrentTime.h" 37 #include "wtf/CurrentTime.h"
38 #include "wtf/text/CString.h" 38 #include "wtf/text/CString.h"
39 39
40 using std::min; 40 using namespace std;
41 41
42 namespace blink { 42 namespace blink {
43 43
44 // Always start progress at initialProgressValue. This helps provide feedback as 44 // Always start progress at initialProgressValue. This helps provide feedback as
45 // soon as a load starts. 45 // soon as a load starts.
46 static const double initialProgressValue = 0.1; 46 static const double initialProgressValue = 0.1;
47 47
48 // Similarly, always leave space at the end. This helps show the user that we're not done 48 // Similarly, always leave space at the end. This helps show the user that we're not done
49 // until we're done. 49 // until we're done.
50 static const double finalProgressValue = 0.9; // 1.0 - initialProgressValue 50 static const double finalProgressValue = 0.9; // 1.0 - initialProgressValue
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 long long estimatedLength = response.expectedContentLength(); 145 long long estimatedLength = response.expectedContentLength();
146 if (estimatedLength < 0) 146 if (estimatedLength < 0)
147 estimatedLength = progressItemDefaultEstimatedLength; 147 estimatedLength = progressItemDefaultEstimatedLength;
148 148
149 m_totalPageAndResourceBytesToLoad += estimatedLength; 149 m_totalPageAndResourceBytesToLoad += estimatedLength;
150 150
151 if (ProgressItem* item = m_progressItems.get(identifier)) { 151 if (ProgressItem* item = m_progressItems.get(identifier)) {
152 item->bytesReceived = 0; 152 item->bytesReceived = 0;
153 item->estimatedLength = estimatedLength; 153 item->estimatedLength = estimatedLength;
154 } else 154 } else {
155 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt h))); 155 m_progressItems.set(identifier, adoptPtr(new ProgressItem(estimatedLengt h)));
156 }
156 } 157 }
157 158
158 void ProgressTracker::incrementProgress(unsigned long identifier, int length) 159 void ProgressTracker::incrementProgress(unsigned long identifier, int length)
159 { 160 {
160 ProgressItem* item = m_progressItems.get(identifier); 161 ProgressItem* item = m_progressItems.get(identifier);
161 162
162 // FIXME: Can this ever happen? 163 // FIXME: Can this ever happen?
163 if (!item) 164 if (!item)
164 return; 165 return;
165 166
166 unsigned bytesReceived = length; 167 unsigned bytesReceived = length;
167 double increment, percentOfRemainingBytes; 168 double increment, percentOfRemainingBytes;
168 long long remainingBytes, estimatedBytesForPendingRequests; 169 long long remainingBytes, estimatedBytesForPendingRequests;
169 170
170 item->bytesReceived += bytesReceived; 171 item->bytesReceived += bytesReceived;
171 if (item->bytesReceived > item->estimatedLength) { 172 if (item->bytesReceived > item->estimatedLength) {
172 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item-> estimatedLength); 173 m_totalPageAndResourceBytesToLoad += ((item->bytesReceived * 2) - item-> estimatedLength);
173 item->estimatedLength = item->bytesReceived * 2; 174 item->estimatedLength = item->bytesReceived * 2;
174 } 175 }
175 176
176 int numPendingOrLoadingRequests = m_frame->document()->fetcher()->requestCou nt(); 177 int numPendingOrLoadingRequests = m_frame->document()->fetcher()->requestCou nt();
177 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP endingOrLoadingRequests; 178 estimatedBytesForPendingRequests = progressItemDefaultEstimatedLength * numP endingOrLoadingRequests;
178 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend ingRequests) - m_totalBytesReceived); 179 remainingBytes = ((m_totalPageAndResourceBytesToLoad + estimatedBytesForPend ingRequests) - m_totalBytesReceived);
179 if (remainingBytes > 0) // Prevent divide by 0. 180 if (remainingBytes > 0) // Prevent divide by 0.
180 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes ; 181 percentOfRemainingBytes = (double)bytesReceived / (double)remainingBytes ;
181 else 182 else
182 percentOfRemainingBytes = 1.0; 183 percentOfRemainingBytes = 1.0;
183 184
184 // For documents that use WebCore's layout system, treat first layout as the half-way point. 185 // For documents that use WebCore's layout system, treat first layout as the half-way point.
185 bool useClampedMaxProgress = !m_frame->view()->didFirstLayout(); 186 bool useClampedMaxProgress = !m_frame->view()->didFirstLayout();
186 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue; 187 double maxProgressValue = useClampedMaxProgress ? 0.5 : finalProgressValue;
187 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes; 188 increment = (maxProgressValue - m_progressValue) * percentOfRemainingBytes;
188 m_progressValue += increment; 189 m_progressValue += increment;
189 m_progressValue = min(m_progressValue, maxProgressValue); 190 m_progressValue = min(m_progressValue, maxProgressValue);
(...skipping 27 matching lines...) Expand all
217 return; 218 return;
218 219
219 // Adjust the total expected bytes to account for any overage/underage. 220 // Adjust the total expected bytes to account for any overage/underage.
220 long long delta = item->bytesReceived - item->estimatedLength; 221 long long delta = item->bytesReceived - item->estimatedLength;
221 m_totalPageAndResourceBytesToLoad += delta; 222 m_totalPageAndResourceBytesToLoad += delta;
222 223
223 m_progressItems.remove(identifier); 224 m_progressItems.remove(identifier);
224 } 225 }
225 226
226 } 227 }
OLDNEW
« no previous file with comments | « Source/core/loader/PingLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698