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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp

Issue 2510333002: Send encoded_body_length to renderer when response completed (2/3) (Closed)
Patch Set: rebase Created 4 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 212 }
213 213
214 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, 214 void ResourceLoader::didReceiveResponse(WebURLLoader* loader,
215 const WebURLResponse& response) { 215 const WebURLResponse& response) {
216 didReceiveResponse(loader, response, nullptr); 216 didReceiveResponse(loader, response, nullptr);
217 } 217 }
218 218
219 void ResourceLoader::didReceiveData(WebURLLoader*, 219 void ResourceLoader::didReceiveData(WebURLLoader*,
220 const char* data, 220 const char* data,
221 int length, 221 int length,
222 int encodedDataLength, 222 int encodedDataLength) {
223 int encodedBodyLength) {
224 CHECK_GE(length, 0); 223 CHECK_GE(length, 0);
225 m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength); 224 m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength);
226 m_resource->addToEncodedBodyLength(encodedBodyLength);
227 m_resource->addToDecodedBodyLength(length); 225 m_resource->addToDecodedBodyLength(length);
228 m_resource->appendData(data, length); 226 m_resource->appendData(data, length);
229 } 227 }
230 228
231 void ResourceLoader::didFinishLoadingFirstPartInMultipart() { 229 void ResourceLoader::didFinishLoadingFirstPartInMultipart() {
232 m_fetcher->didFinishLoading(m_resource.get(), 0, 230 m_fetcher->didFinishLoading(m_resource.get(), 0,
233 ResourceFetcher::DidFinishFirstPartInMultipart); 231 ResourceFetcher::DidFinishFirstPartInMultipart);
234 } 232 }
235 233
236 void ResourceLoader::didFinishLoading(WebURLLoader*, 234 void ResourceLoader::didFinishLoading(WebURLLoader*,
237 double finishTime, 235 double finishTime,
238 int64_t encodedDataLength) { 236 int64_t encodedDataLength,
237 int64_t encodedBodyLength) {
239 m_resource->setEncodedDataLength(encodedDataLength); 238 m_resource->setEncodedDataLength(encodedDataLength);
239 m_resource->addToEncodedBodyLength(encodedBodyLength);
240 m_loader.reset(); 240 m_loader.reset();
241 m_fetcher->didFinishLoading(m_resource.get(), finishTime, 241 m_fetcher->didFinishLoading(m_resource.get(), finishTime,
242 ResourceFetcher::DidFinishLoading); 242 ResourceFetcher::DidFinishLoading);
243 } 243 }
244 244
245 void ResourceLoader::didFail(WebURLLoader*, 245 void ResourceLoader::didFail(WebURLLoader*,
246 const WebURLError& error, 246 const WebURLError& error,
247 int64_t encodedDataLength) { 247 int64_t encodedDataLength,
248 int64_t encodedBodyLength) {
248 m_resource->setEncodedDataLength(encodedDataLength); 249 m_resource->setEncodedDataLength(encodedDataLength);
250 m_resource->addToEncodedBodyLength(encodedBodyLength);
249 didFail(error); 251 didFail(error);
250 } 252 }
251 253
252 void ResourceLoader::didFail(const ResourceError& error) { 254 void ResourceLoader::didFail(const ResourceError& error) {
253 if (m_isCacheAwareLoadingActivated && error.isCacheMiss() && 255 if (m_isCacheAwareLoadingActivated && error.isCacheMiss() &&
254 m_fetcher->context().shouldLoadNewResource(m_resource->getType())) { 256 m_fetcher->context().shouldLoadNewResource(m_resource->getType())) {
255 m_resource->willReloadAfterDiskCacheMiss(); 257 m_resource->willReloadAfterDiskCacheMiss();
256 m_isCacheAwareLoadingActivated = false; 258 m_isCacheAwareLoadingActivated = false;
257 restart(m_resource->resourceRequest(), 259 restart(m_resource->resourceRequest(),
258 m_fetcher->context().loadingTaskRunner(), 260 m_fetcher->context().loadingTaskRunner(),
259 m_fetcher->context().defersLoading()); 261 m_fetcher->context().defersLoading());
260 return; 262 return;
261 } 263 }
262 264
263 m_loader.reset(); 265 m_loader.reset();
264 m_fetcher->didFailLoading(m_resource.get(), error); 266 m_fetcher->didFailLoading(m_resource.get(), error);
265 } 267 }
266 268
267 void ResourceLoader::requestSynchronously(const ResourceRequest& request) { 269 void ResourceLoader::requestSynchronously(const ResourceRequest& request) {
268 // downloadToFile is not supported for synchronous requests. 270 // downloadToFile is not supported for synchronous requests.
269 DCHECK(!request.downloadToFile()); 271 DCHECK(!request.downloadToFile());
270 DCHECK(m_loader); 272 DCHECK(m_loader);
271 DCHECK_EQ(request.priority(), ResourceLoadPriorityHighest); 273 DCHECK_EQ(request.priority(), ResourceLoadPriorityHighest);
272 274
273 WrappedResourceRequest requestIn(request); 275 WrappedResourceRequest requestIn(request);
274 WebURLResponse responseOut; 276 WebURLResponse responseOut;
275 WebURLError errorOut; 277 WebURLError errorOut;
276 WebData dataOut; 278 WebData dataOut;
277 int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength; 279 int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength;
280 int64_t encodedBodyLength = 0;
278 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut, 281 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut,
279 encodedDataLength); 282 encodedDataLength, encodedBodyLength);
280 283
281 // A message dispatched while synchronously fetching the resource 284 // A message dispatched while synchronously fetching the resource
282 // can bring about the cancellation of this load. 285 // can bring about the cancellation of this load.
283 if (!m_loader) 286 if (!m_loader)
284 return; 287 return;
285 if (errorOut.reason) { 288 if (errorOut.reason) {
286 didFail(0, errorOut, encodedDataLength); 289 didFail(0, errorOut, encodedDataLength, encodedBodyLength);
287 return; 290 return;
288 } 291 }
289 didReceiveResponse(0, responseOut); 292 didReceiveResponse(0, responseOut);
290 if (!m_loader) 293 if (!m_loader)
291 return; 294 return;
292 DCHECK_GE(responseOut.toResourceResponse().encodedBodyLength(), 0); 295 DCHECK_GE(responseOut.toResourceResponse().encodedBodyLength(), 0);
293 296
294 // Follow the async case convention of not calling didReceiveData or 297 // Follow the async case convention of not calling didReceiveData or
295 // appending data to m_resource if the response body is empty. Copying the 298 // appending data to m_resource if the response body is empty. Copying the
296 // empty buffer is a noop in most cases, but is destructive in the case of 299 // empty buffer is a noop in most cases, but is destructive in the case of
297 // a 304, where it will overwrite the cached data we should be reusing. 300 // a 304, where it will overwrite the cached data we should be reusing.
298 if (dataOut.size()) { 301 if (dataOut.size()) {
299 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(), 302 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size(),
300 encodedDataLength); 303 encodedDataLength);
301 m_resource->setResourceBuffer(dataOut); 304 m_resource->setResourceBuffer(dataOut);
302 } 305 }
303 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 306 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength,
307 encodedBodyLength);
304 } 308 }
305 309
306 void ResourceLoader::activateCacheAwareLoadingIfNeeded( 310 void ResourceLoader::activateCacheAwareLoadingIfNeeded(
307 const ResourceRequest& request) { 311 const ResourceRequest& request) {
308 DCHECK(!m_isCacheAwareLoadingActivated); 312 DCHECK(!m_isCacheAwareLoadingActivated);
309 313
310 if (m_resource->options().cacheAwareLoadingEnabled != 314 if (m_resource->options().cacheAwareLoadingEnabled !=
311 IsCacheAwareLoadingEnabled) 315 IsCacheAwareLoadingEnabled)
312 return; 316 return;
313 317
314 // Synchronous requests are not supported. 318 // Synchronous requests are not supported.
315 if (m_resource->options().synchronousPolicy == RequestSynchronously) 319 if (m_resource->options().synchronousPolicy == RequestSynchronously)
316 return; 320 return;
317 321
318 // Don't activate on Resource revalidation. 322 // Don't activate on Resource revalidation.
319 if (m_resource->isCacheValidator()) 323 if (m_resource->isCacheValidator())
320 return; 324 return;
321 325
322 // Don't activate if cache policy is explicitly set. 326 // Don't activate if cache policy is explicitly set.
323 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) 327 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy)
324 return; 328 return;
325 329
326 m_isCacheAwareLoadingActivated = true; 330 m_isCacheAwareLoadingActivated = true;
327 } 331 }
328 332
329 } // namespace blink 333 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceLoader.h ('k') | third_party/WebKit/Source/core/loader/PingLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698