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

Side by Side Diff: Source/core/inspector/InspectorResourceAgent.cpp

Issue 23702040: Send synchronous loads through the cache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 7 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 cachedResource = InspectorPageAgent::cachedResource(loader->frame(), res ponse.url()); 343 cachedResource = InspectorPageAgent::cachedResource(loader->frame(), res ponse.url());
344 344
345 if (cachedResource) { 345 if (cachedResource) {
346 // Use mime type from cached resource in case the one in response is emp ty. 346 // Use mime type from cached resource in case the one in response is emp ty.
347 if (resourceResponse && response.mimeType().isEmpty()) 347 if (resourceResponse && response.mimeType().isEmpty())
348 resourceResponse->setString(TypeBuilder::Network::Response::MimeType , cachedResource->response().mimeType()); 348 resourceResponse->setString(TypeBuilder::Network::Response::MimeType , cachedResource->response().mimeType());
349 m_resourcesData->addResource(requestId, cachedResource); 349 m_resourcesData->addResource(requestId, cachedResource);
350 } 350 }
351 351
352 InspectorPageAgent::ResourceType type = cachedResource ? InspectorPageAgent: :cachedResourceType(*cachedResource) : InspectorPageAgent::OtherResource; 352 InspectorPageAgent::ResourceType type = cachedResource ? InspectorPageAgent: :cachedResourceType(*cachedResource) : InspectorPageAgent::OtherResource;
353 if (m_loadingXHRSynchronously || m_resourcesData->resourceType(requestId) == InspectorPageAgent::XHRResource) 353 if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::XHRResou rce)
354 type = InspectorPageAgent::XHRResource; 354 type = InspectorPageAgent::XHRResource;
355 else if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::Scr iptResource) 355 else if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::Scr iptResource)
356 type = InspectorPageAgent::ScriptResource; 356 type = InspectorPageAgent::ScriptResource;
357 else if (equalIgnoringFragmentIdentifier(response.url(), loader->url()) && ! loader->isCommitted()) 357 else if (equalIgnoringFragmentIdentifier(response.url(), loader->url()) && ! loader->isCommitted())
358 type = InspectorPageAgent::DocumentResource; 358 type = InspectorPageAgent::DocumentResource;
359 359
360 m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(loader->fr ame()), response); 360 m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(loader->fr ame()), response);
361 m_resourcesData->setResourceType(requestId, type); 361 m_resourcesData->setResourceType(requestId, type);
362 m_frontend->responseReceived(requestId, m_pageAgent->frameId(loader->frame() ), m_pageAgent->loaderId(loader), currentTime(), InspectorPageAgent::resourceTyp eJson(type), resourceResponse); 362 m_frontend->responseReceived(requestId, m_pageAgent->frameId(loader->frame() ), m_pageAgent->loaderId(loader), currentTime(), InspectorPageAgent::resourceTyp eJson(type), resourceResponse);
363 // If we revalidated the resource and got Not modified, send content length following didReceiveResponse 363 // If we revalidated the resource and got Not modified, send content length following didReceiveResponse
364 // as there will be no calls to didReceiveData from the network stack. 364 // as there will be no calls to didReceiveData from the network stack.
365 if (isNotModified && cachedResource && cachedResource->encodedSize()) 365 if (isNotModified && cachedResource && cachedResource->encodedSize())
366 didReceiveData(identifier, 0, cachedResource->encodedSize(), 0); 366 didReceiveData(identifier, 0, cachedResource->encodedSize(), 0);
367 } 367 }
368 368
369 static bool isErrorStatusCode(int statusCode) 369 static bool isErrorStatusCode(int statusCode)
370 { 370 {
371 return statusCode >= 400; 371 return statusCode >= 400;
372 } 372 }
373 373
374 void InspectorResourceAgent::didReceiveData(unsigned long identifier, const char * data, int dataLength, int encodedDataLength) 374 void InspectorResourceAgent::didReceiveData(unsigned long identifier, const char * data, int dataLength, int encodedDataLength)
375 { 375 {
376 String requestId = IdentifiersFactory::requestId(identifier); 376 String requestId = IdentifiersFactory::requestId(identifier);
377 377
378 if (data) { 378 if (data) {
379 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData ->data(requestId); 379 NetworkResourcesData::ResourceData const* resourceData = m_resourcesData ->data(requestId);
380 if (resourceData && !m_loadingXHRSynchronously && (!resourceData->cached Resource() || resourceData->cachedResource()->dataBufferingPolicy() == DoNotBuff erData || isErrorStatusCode(resourceData->httpStatusCode()))) 380 if (resourceData && (!resourceData->cachedResource() || resourceData->ca chedResource()->dataBufferingPolicy() == DoNotBufferData || isErrorStatusCode(re sourceData->httpStatusCode())))
381 m_resourcesData->maybeAddResourceData(requestId, data, dataLength); 381 m_resourcesData->maybeAddResourceData(requestId, data, dataLength);
382 } 382 }
383 383
384 m_frontend->dataReceived(requestId, currentTime(), dataLength, encodedDataLe ngth); 384 m_frontend->dataReceived(requestId, currentTime(), dataLength, encodedDataLe ngth);
385 } 385 }
386 386
387 void InspectorResourceAgent::didFinishLoading(unsigned long identifier, Document Loader* loader, double monotonicFinishTime) 387 void InspectorResourceAgent::didFinishLoading(unsigned long identifier, Document Loader* loader, double monotonicFinishTime)
388 { 388 {
389 double finishTime = 0.0; 389 double finishTime = 0.0;
390 // FIXME: Expose all of the timing details to inspector and have it calculat e finishTime. 390 // FIXME: Expose all of the timing details to inspector and have it calculat e finishTime.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 m_pendingXHRReplayData.set(client, xhrReplayData); 445 m_pendingXHRReplayData.set(client, xhrReplayData);
446 } 446 }
447 447
448 void InspectorResourceAgent::didFailXHRLoading(ThreadableLoaderClient* client) 448 void InspectorResourceAgent::didFailXHRLoading(ThreadableLoaderClient* client)
449 { 449 {
450 m_pendingXHRReplayData.remove(client); 450 m_pendingXHRReplayData.remove(client);
451 } 451 }
452 452
453 void InspectorResourceAgent::didFinishXHRLoading(ThreadableLoaderClient* client, unsigned long identifier, ScriptString sourceString, const String&, const Strin g&, unsigned) 453 void InspectorResourceAgent::didFinishXHRLoading(ThreadableLoaderClient* client, unsigned long identifier, ScriptString sourceString, const String&, const Strin g&, unsigned)
454 { 454 {
455 // For Asynchronous XHRs, the inspector can grab the data directly off of th e Resource. For sync XHRs, we need to
456 // provide the data here, since no Resource was involved.
457 if (m_loadingXHRSynchronously)
458 m_resourcesData->setResourceContent(IdentifiersFactory::requestId(identi fier), sourceString.flattenToString());
459 m_pendingXHRReplayData.remove(client); 455 m_pendingXHRReplayData.remove(client);
460 } 456 }
461 457
462 void InspectorResourceAgent::didReceiveXHRResponse(unsigned long identifier) 458 void InspectorResourceAgent::didReceiveXHRResponse(unsigned long identifier)
463 { 459 {
464 m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource); 460 m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource);
465 } 461 }
466 462
467 void InspectorResourceAgent::willLoadXHRSynchronously()
468 {
469 m_loadingXHRSynchronously = true;
470 }
471
472 void InspectorResourceAgent::didLoadXHRSynchronously()
473 {
474 m_loadingXHRSynchronously = false;
475 }
476
477 void InspectorResourceAgent::willDestroyResource(Resource* cachedResource) 463 void InspectorResourceAgent::willDestroyResource(Resource* cachedResource)
478 { 464 {
479 Vector<String> requestIds = m_resourcesData->removeResource(cachedResource); 465 Vector<String> requestIds = m_resourcesData->removeResource(cachedResource);
480 if (!requestIds.size()) 466 if (!requestIds.size())
481 return; 467 return;
482 468
483 String content; 469 String content;
484 bool base64Encoded; 470 bool base64Encoded;
485 if (!InspectorPageAgent::cachedResourceContent(cachedResource, &content, &ba se64Encoded)) 471 if (!InspectorPageAgent::cachedResourceContent(cachedResource, &content, &ba se64Encoded))
486 return; 472 return;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 m_frameNavigationInitiatorMap.remove(m_pageAgent->frameId(frame)); 762 m_frameNavigationInitiatorMap.remove(m_pageAgent->frameId(frame));
777 } 763 }
778 764
779 InspectorResourceAgent::InspectorResourceAgent(InstrumentingAgents* instrumentin gAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorCompos iteState* state, InspectorOverlay* overlay) 765 InspectorResourceAgent::InspectorResourceAgent(InstrumentingAgents* instrumentin gAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorCompos iteState* state, InspectorOverlay* overlay)
780 : InspectorBaseAgent<InspectorResourceAgent>("Network", instrumentingAgents, state) 766 : InspectorBaseAgent<InspectorResourceAgent>("Network", instrumentingAgents, state)
781 , m_pageAgent(pageAgent) 767 , m_pageAgent(pageAgent)
782 , m_client(client) 768 , m_client(client)
783 , m_overlay(overlay) 769 , m_overlay(overlay)
784 , m_frontend(0) 770 , m_frontend(0)
785 , m_resourcesData(adoptPtr(new NetworkResourcesData())) 771 , m_resourcesData(adoptPtr(new NetworkResourcesData()))
786 , m_loadingXHRSynchronously(false)
787 , m_isRecalculatingStyle(false) 772 , m_isRecalculatingStyle(false)
788 { 773 {
789 } 774 }
790 775
791 } // namespace WebCore 776 } // namespace WebCore
792 777
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorResourceAgent.h ('k') | Source/core/loader/DocumentThreadableLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698