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

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

Issue 1410153009: DevTools: Make network events continuous on Timeline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplify the patch Created 5 years, 1 month 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 16 matching lines...) Expand all
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "core/fetch/ResourceLoader.h" 31 #include "core/fetch/ResourceLoader.h"
32 32
33 #include "core/fetch/CSSStyleSheetResource.h" 33 #include "core/fetch/CSSStyleSheetResource.h"
34 #include "core/fetch/Resource.h" 34 #include "core/fetch/Resource.h"
35 #include "core/fetch/ResourceFetcher.h" 35 #include "core/fetch/ResourceFetcher.h"
36 #include "core/fetch/ResourcePtr.h" 36 #include "core/fetch/ResourcePtr.h"
37 #include "core/inspector/InspectorTraceEvents.h"
37 #include "platform/Logging.h" 38 #include "platform/Logging.h"
38 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
39 #include "platform/ThreadedDataReceiver.h" 40 #include "platform/ThreadedDataReceiver.h"
40 #include "platform/exported/WrappedResourceRequest.h" 41 #include "platform/exported/WrappedResourceRequest.h"
41 #include "platform/exported/WrappedResourceResponse.h" 42 #include "platform/exported/WrappedResourceResponse.h"
42 #include "platform/network/ResourceError.h" 43 #include "platform/network/ResourceError.h"
43 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
44 #include "public/platform/WebData.h" 45 #include "public/platform/WebData.h"
45 #include "public/platform/WebThreadedDataReceiver.h" 46 #include "public/platform/WebThreadedDataReceiver.h"
46 #include "public/platform/WebURLError.h" 47 #include "public/platform/WebURLError.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // |rawHandle|'s ownership is transferred to the callee. 308 // |rawHandle|'s ownership is transferred to the callee.
308 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); 309 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle);
309 310
310 bool isMultipartPayload = response.isMultipartPayload(); 311 bool isMultipartPayload = response.isMultipartPayload();
311 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse); 312 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse);
312 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. 313 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved.
313 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); 314 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition);
314 m_connectionState = ConnectionStateReceivedResponse; 315 m_connectionState = ConnectionStateReceivedResponse;
315 316
316 const ResourceResponse& resourceResponse = response.toResourceResponse(); 317 const ResourceResponse& resourceResponse = response.toResourceResponse();
318 TRACE_EVENT1("devtools.timeline", "ResourceReceiveResponse", "data", Inspect orReceiveResponseEvent::data(m_resource->identifier(), resourceResponse));
317 319
318 if (responseNeedsAccessControlCheck()) { 320 if (responseNeedsAccessControlCheck()) {
319 if (response.wasFetchedViaServiceWorker()) { 321 if (response.wasFetchedViaServiceWorker()) {
320 if (response.wasFallbackRequiredByServiceWorker()) { 322 if (response.wasFallbackRequiredByServiceWorker()) {
321 m_loader->cancel(); 323 m_loader->cancel();
322 m_loader.clear(); 324 m_loader.clear();
323 m_connectionState = ConnectionStateStarted; 325 m_connectionState = ConnectionStateStarted;
324 m_loader = adoptPtr(Platform::current()->createURLLoader()); 326 m_loader = adoptPtr(Platform::current()->createURLLoader());
325 ASSERT(m_loader); 327 ASSERT(m_loader);
326 ASSERT(!m_request.skipServiceWorker()); 328 ASSERT(!m_request.skipServiceWorker());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 387
386 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response) 388 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon se& response)
387 { 389 {
388 didReceiveResponse(loader, response, nullptr); 390 didReceiveResponse(loader, response, nullptr);
389 } 391 }
390 392
391 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength) 393 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length, int encodedDataLength)
392 { 394 {
393 ASSERT(m_state != Terminated); 395 ASSERT(m_state != Terminated);
394 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); 396 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData);
397 TRACE_EVENT1("devtools.timeline", "ResourceReceivedData", "data", InspectorR eceiveDataEvent::data(m_resource->identifier(), encodedDataLength));
395 m_connectionState = ConnectionStateReceivingData; 398 m_connectionState = ConnectionStateReceivingData;
396 399
397 // It is possible to receive data on uninitialized resources if it had an er ror status code, and we are running a nested message 400 // It is possible to receive data on uninitialized resources if it had an er ror status code, and we are running a nested message
398 // loop. When this occurs, ignoring the data is the correct action. 401 // loop. When this occurs, ignoring the data is the correct action.
399 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn oreHTTPStatusCodeErrors()) 402 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn oreHTTPStatusCodeErrors())
400 return; 403 return;
401 ASSERT(m_state == Initialized); 404 ASSERT(m_state == Initialized);
402 405
403 // FIXME: If we get a resource with more than 2B bytes, this code won't do t he right thing. 406 // FIXME: If we get a resource with more than 2B bytes, this code won't do t he right thing.
404 // However, with today's computers and networking speeds, this won't happen in practice. 407 // However, with today's computers and networking speeds, this won't happen in practice.
405 // Could be an issue with a giant local file. 408 // Could be an issue with a giant local file.
406 m_fetcher->didReceiveData(m_resource, data, length, encodedDataLength); 409 m_fetcher->didReceiveData(m_resource, data, length, encodedDataLength);
407 if (m_state == Terminated) 410 if (m_state == Terminated)
408 return; 411 return;
409 RELEASE_ASSERT(length >= 0); 412 RELEASE_ASSERT(length >= 0);
410 m_resource->appendData(data, length); 413 m_resource->appendData(data, length);
411 } 414 }
412 415
413 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t encodedDataLength) 416 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t encodedDataLength)
414 { 417 {
415 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); 418 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData);
419 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", InspectorResourc eFinishEvent::data(m_resource->identifier(), finishTime, false));
416 m_connectionState = ConnectionStateFinishedLoading; 420 m_connectionState = ConnectionStateFinishedLoading;
417 if (m_state != Initialized) 421 if (m_state != Initialized)
418 return; 422 return;
419 ASSERT(m_state != Terminated); 423 ASSERT(m_state != Terminated);
420 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data()); 424 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data());
421 425
422 ResourcePtr<Resource> protectResource(m_resource); 426 ResourcePtr<Resource> protectResource(m_resource);
423 m_state = Finishing; 427 m_state = Finishing;
424 m_resource->setLoadFinishTime(finishTime); 428 m_resource->setLoadFinishTime(finishTime);
425 didFinishLoadingOnePart(finishTime, encodedDataLength); 429 didFinishLoadingOnePart(finishTime, encodedDataLength);
426 if (m_state == Terminated) 430 if (m_state == Terminated)
427 return; 431 return;
428 m_resource->finish(); 432 m_resource->finish();
429 433
430 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release 434 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release
431 // the resources a second time, they have been released by cancel. 435 // the resources a second time, they have been released by cancel.
432 if (m_state == Terminated) 436 if (m_state == Terminated)
433 return; 437 return;
434 releaseResources(); 438 releaseResources();
435 } 439 }
436 440
437 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) 441 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error)
438 { 442 {
443 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", InspectorResourc eFinishEvent::data(m_resource->identifier(), 0, true));
439 m_connectionState = ConnectionStateFailed; 444 m_connectionState = ConnectionStateFailed;
440 ASSERT(m_state != Terminated); 445 ASSERT(m_state != Terminated);
441 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data()); 446 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data());
442 447
443 ResourcePtr<Resource> protectResource(m_resource); 448 ResourcePtr<Resource> protectResource(m_resource);
444 m_state = Finishing; 449 m_state = Finishing;
445 m_resource->setResourceError(error); 450 m_resource->setResourceError(error);
446 451
447 if (!m_notifiedLoadComplete) { 452 if (!m_notifiedLoadComplete) {
448 m_notifiedLoadComplete = true; 453 m_notifiedLoadComplete = true;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 508 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
504 } 509 }
505 510
506 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const 511 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const
507 { 512 {
508 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 513 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
509 return request; 514 return request;
510 } 515 }
511 516
512 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698