OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 10 matching lines...) Expand all Loading... |
21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
22 */ | 22 */ |
23 | 23 |
24 #include "core/fetch/Resource.h" | 24 #include "core/fetch/Resource.h" |
25 | 25 |
26 #include "core/fetch/CachedMetadata.h" | 26 #include "core/fetch/CachedMetadata.h" |
27 #include "core/fetch/CrossOriginAccessControl.h" | 27 #include "core/fetch/CrossOriginAccessControl.h" |
28 #include "core/fetch/FetchInitiatorTypeNames.h" | 28 #include "core/fetch/FetchInitiatorTypeNames.h" |
29 #include "core/fetch/MemoryCache.h" | 29 #include "core/fetch/MemoryCache.h" |
30 #include "core/fetch/ResourceClient.h" | 30 #include "core/fetch/ResourceClient.h" |
31 #include "core/fetch/ResourceClientWalker.h" | 31 #include "core/fetch/ResourceClientOrObserverWalker.h" |
32 #include "core/fetch/ResourceFetcher.h" | 32 #include "core/fetch/ResourceFetcher.h" |
33 #include "core/fetch/ResourceLoader.h" | 33 #include "core/fetch/ResourceLoader.h" |
34 #include "core/inspector/InspectorInstrumentation.h" | 34 #include "core/inspector/InspectorInstrumentation.h" |
35 #include "core/inspector/InstanceCounters.h" | 35 #include "core/inspector/InstanceCounters.h" |
36 #include "platform/Logging.h" | 36 #include "platform/Logging.h" |
37 #include "platform/SharedBuffer.h" | 37 #include "platform/SharedBuffer.h" |
38 #include "platform/TraceEvent.h" | 38 #include "platform/TraceEvent.h" |
39 #include "platform/network/HTTPParsers.h" | 39 #include "platform/network/HTTPParsers.h" |
40 #include "platform/weborigin/KURL.h" | 40 #include "platform/weborigin/KURL.h" |
41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 419 } |
420 | 420 |
421 bool Resource::unlock() | 421 bool Resource::unlock() |
422 { | 422 { |
423 if (!m_data) | 423 if (!m_data) |
424 return false; | 424 return false; |
425 | 425 |
426 if (!m_data->isLocked()) | 426 if (!m_data->isLocked()) |
427 return true; | 427 return true; |
428 | 428 |
429 if (!memoryCache()->contains(this) || hasClients() || !m_revalidatingRequest
.isNull() || !m_loadFinishTime || !isSafeToUnlock()) | 429 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !m_revalida
tingRequest.isNull() || !m_loadFinishTime || !isSafeToUnlock()) |
430 return false; | 430 return false; |
431 | 431 |
432 m_data->unlock(); | 432 m_data->unlock(); |
433 return true; | 433 return true; |
434 } | 434 } |
435 | 435 |
436 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web
DataConsumerHandle>) | 436 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web
DataConsumerHandle>) |
437 { | 437 { |
438 m_responseTimestamp = currentTime(); | 438 m_responseTimestamp = currentTime(); |
439 | 439 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 #if ENABLE(OILPAN) | 499 #if ENABLE(OILPAN) |
500 return this; | 500 return this; |
501 #else | 501 #else |
502 return m_weakPtrFactory.createWeakPtr(); | 502 return m_weakPtrFactory.createWeakPtr(); |
503 #endif | 503 #endif |
504 } | 504 } |
505 | 505 |
506 String Resource::reasonNotDeletable() const | 506 String Resource::reasonNotDeletable() const |
507 { | 507 { |
508 StringBuilder builder; | 508 StringBuilder builder; |
509 if (hasClients()) { | 509 if (hasClientsOrObservers()) { |
510 builder.append("hasClients("); | 510 builder.append("hasClients("); |
511 builder.appendNumber(m_clients.size()); | 511 builder.appendNumber(m_clients.size()); |
512 if (!m_clientsAwaitingCallback.isEmpty()) { | 512 if (!m_clientsAwaitingCallback.isEmpty()) { |
513 builder.append(", AwaitingCallback="); | 513 builder.append(", AwaitingCallback="); |
514 builder.appendNumber(m_clientsAwaitingCallback.size()); | 514 builder.appendNumber(m_clientsAwaitingCallback.size()); |
515 } | 515 } |
516 if (!m_finishedClients.isEmpty()) { | 516 if (!m_finishedClients.isEmpty()) { |
517 builder.append(", Finished="); | 517 builder.append(", Finished="); |
518 builder.appendNumber(m_finishedClients.size()); | 518 builder.appendNumber(m_finishedClients.size()); |
519 } | 519 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 return true; | 574 return true; |
575 if (type == Resource::CSSStyleSheet) | 575 if (type == Resource::CSSStyleSheet) |
576 return true; | 576 return true; |
577 if (type == Resource::Script) | 577 if (type == Resource::Script) |
578 return true; | 578 return true; |
579 if (type == Resource::Font) | 579 if (type == Resource::Font) |
580 return true; | 580 return true; |
581 return false; | 581 return false; |
582 } | 582 } |
583 | 583 |
584 void Resource::addClient(ResourceClient* client) | 584 void Resource::willAddClientOrObserver() |
585 { | 585 { |
586 ASSERT(!isPurgeable()); | 586 ASSERT(!isPurgeable()); |
587 | |
588 if (m_preloadResult == PreloadNotReferenced) { | 587 if (m_preloadResult == PreloadNotReferenced) { |
589 if (isLoaded()) | 588 if (isLoaded()) |
590 m_preloadResult = PreloadReferencedWhileComplete; | 589 m_preloadResult = PreloadReferencedWhileComplete; |
591 else if (isLoading()) | 590 else if (isLoading()) |
592 m_preloadResult = PreloadReferencedWhileLoading; | 591 m_preloadResult = PreloadReferencedWhileLoading; |
593 else | 592 else |
594 m_preloadResult = PreloadReferenced; | 593 m_preloadResult = PreloadReferenced; |
595 } | 594 } |
596 if (!hasClients()) | 595 if (!hasClientsOrObservers()) |
597 memoryCache()->makeLive(this); | 596 memoryCache()->makeLive(this); |
| 597 } |
| 598 |
| 599 void Resource::addClient(ResourceClient* client) |
| 600 { |
| 601 willAddClientOrObserver(); |
598 | 602 |
599 if (!m_revalidatingRequest.isNull()) { | 603 if (!m_revalidatingRequest.isNull()) { |
600 m_clients.add(client); | 604 m_clients.add(client); |
601 return; | 605 return; |
602 } | 606 } |
603 | 607 |
604 // If we have existing data to send to the new client and the resource type
supprts it, send it asynchronously. | 608 // If we have existing data to send to the new client and the resource type
supprts it, send it asynchronously. |
605 if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getTyp
e()) && !m_needsSynchronousCacheHit) { | 609 if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getTyp
e()) && !m_needsSynchronousCacheHit) { |
606 m_clientsAwaitingCallback.add(client); | 610 m_clientsAwaitingCallback.add(client); |
607 ResourceCallback::callbackHandler()->schedule(this); | 611 ResourceCallback::callbackHandler()->schedule(this); |
608 return; | 612 return; |
609 } | 613 } |
610 | 614 |
611 m_clients.add(client); | 615 m_clients.add(client); |
612 didAddClient(client); | 616 didAddClient(client); |
613 return; | 617 return; |
614 } | 618 } |
615 | 619 |
616 void Resource::removeClient(ResourceClient* client) | 620 void Resource::removeClient(ResourceClient* client) |
617 { | 621 { |
618 ASSERT(hasClient(client)); | 622 ASSERT(hasClient(client)); |
619 if (m_finishedClients.contains(client)) | 623 if (m_finishedClients.contains(client)) |
620 m_finishedClients.remove(client); | 624 m_finishedClients.remove(client); |
621 else if (m_clientsAwaitingCallback.contains(client)) | 625 else if (m_clientsAwaitingCallback.contains(client)) |
622 m_clientsAwaitingCallback.remove(client); | 626 m_clientsAwaitingCallback.remove(client); |
623 else | 627 else |
624 m_clients.remove(client); | 628 m_clients.remove(client); |
625 | 629 |
626 didRemoveClient(client); | |
627 | |
628 if (m_clientsAwaitingCallback.isEmpty()) | 630 if (m_clientsAwaitingCallback.isEmpty()) |
629 ResourceCallback::callbackHandler()->cancel(this); | 631 ResourceCallback::callbackHandler()->cancel(this); |
630 | 632 |
631 if (!hasClients()) { | 633 didRemoveClientOrObserver(); |
| 634 // This object may be dead here. |
| 635 } |
| 636 |
| 637 void Resource::didRemoveClientOrObserver() |
| 638 { |
| 639 if (!hasClientsOrObservers()) { |
632 RefPtrWillBeRawPtr<Resource> protect(this); | 640 RefPtrWillBeRawPtr<Resource> protect(this); |
633 memoryCache()->makeDead(this); | 641 memoryCache()->makeDead(this); |
634 allClientsRemoved(); | 642 allClientsAndObserversRemoved(); |
635 | 643 |
636 // RFC2616 14.9.2: | 644 // RFC2616 14.9.2: |
637 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" | 645 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" |
638 // "... History buffers MAY store such responses as part of their normal
operation." | 646 // "... History buffers MAY store such responses as part of their normal
operation." |
639 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. | 647 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. |
640 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { | 648 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { |
641 memoryCache()->remove(this); | 649 memoryCache()->remove(this); |
642 memoryCache()->prune(); | 650 memoryCache()->prune(); |
643 } else { | 651 } else { |
644 memoryCache()->prune(this); | 652 memoryCache()->prune(this); |
645 } | 653 } |
646 } | 654 } |
647 // This object may be dead here. | 655 // This object may be dead here. |
648 } | 656 } |
649 | 657 |
650 void Resource::allClientsRemoved() | 658 void Resource::allClientsAndObserversRemoved() |
651 { | 659 { |
652 if (!m_loader) | 660 if (!m_loader) |
653 return; | 661 return; |
654 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this
)) | 662 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this
)) |
655 cancelTimerFired(&m_cancelTimer); | 663 cancelTimerFired(&m_cancelTimer); |
656 else if (!m_cancelTimer.isActive()) | 664 else if (!m_cancelTimer.isActive()) |
657 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); | 665 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); |
658 | 666 |
659 unlock(); | 667 unlock(); |
660 } | 668 } |
661 | 669 |
662 void Resource::cancelTimerFired(Timer<Resource>* timer) | 670 void Resource::cancelTimerFired(Timer<Resource>* timer) |
663 { | 671 { |
664 ASSERT_UNUSED(timer, timer == &m_cancelTimer); | 672 ASSERT_UNUSED(timer, timer == &m_cancelTimer); |
665 if (hasClients() || !m_loader) | 673 if (hasClientsOrObservers() || !m_loader) |
666 return; | 674 return; |
667 RefPtrWillBeRawPtr<Resource> protect(this); | 675 RefPtrWillBeRawPtr<Resource> protect(this); |
668 m_loader->cancelIfNotFinishing(); | 676 m_loader->cancelIfNotFinishing(); |
669 memoryCache()->remove(this); | 677 memoryCache()->remove(this); |
670 } | 678 } |
671 | 679 |
672 void Resource::setDecodedSize(size_t decodedSize) | 680 void Resource::setDecodedSize(size_t decodedSize) |
673 { | 681 { |
674 if (decodedSize == m_decodedSize) | 682 if (decodedSize == m_decodedSize) |
675 return; | 683 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 return m_data && !m_data->isLocked(); | 878 return m_data && !m_data->isLocked(); |
871 } | 879 } |
872 | 880 |
873 bool Resource::lock() | 881 bool Resource::lock() |
874 { | 882 { |
875 if (!m_data) | 883 if (!m_data) |
876 return true; | 884 return true; |
877 if (m_data->isLocked()) | 885 if (m_data->isLocked()) |
878 return true; | 886 return true; |
879 | 887 |
880 ASSERT(!hasClients()); | 888 ASSERT(!hasClientsOrObservers()); |
881 | 889 |
882 // If locking fails, our buffer has been purged. There's no point | 890 // If locking fails, our buffer has been purged. There's no point |
883 // in leaving a purged resource in MemoryCache. | 891 // in leaving a purged resource in MemoryCache. |
884 if (!m_data->lock()) { | 892 if (!m_data->lock()) { |
885 m_data.clear(); | 893 m_data.clear(); |
886 setEncodedSize(0); | 894 setEncodedSize(0); |
887 memoryCache()->remove(this); | 895 memoryCache()->remove(this); |
888 return false; | 896 return false; |
889 } | 897 } |
890 return true; | 898 return true; |
891 } | 899 } |
892 | 900 |
893 size_t Resource::overheadSize() const | 901 size_t Resource::overheadSize() const |
894 { | 902 { |
895 static const int kAverageClientsHashMapSize = 384; | 903 static const int kAverageClientsHashMapSize = 384; |
896 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().getString().length() * 2; | 904 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().getString().length() * 2; |
897 } | 905 } |
898 | 906 |
899 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
orityValue) | 907 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
orityValue) |
900 { | 908 { |
901 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); | 909 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); |
902 if (m_loader) | 910 if (m_loader) |
903 m_loader->didChangePriority(loadPriority, intraPriorityValue); | 911 m_loader->didChangePriority(loadPriority, intraPriorityValue); |
904 } | 912 } |
905 | 913 |
906 ResourcePriority Resource::priorityFromClients() | |
907 { | |
908 ResourcePriority priority; | |
909 ResourceClientWalker<ResourceClient> walker(m_clients); | |
910 while (ResourceClient* c = walker.next()) { | |
911 ResourcePriority nextPriority = c->computeResourcePriority(); | |
912 if (nextPriority.visibility == ResourcePriority::NotVisible) | |
913 continue; | |
914 priority.visibility = ResourcePriority::Visible; | |
915 priority.intraPriorityValue += nextPriority.intraPriorityValue; | |
916 } | |
917 return priority; | |
918 } | |
919 | |
920 Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler() | 914 Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler() |
921 { | 915 { |
922 // Oilpan + LSan: as the callbackHandler() singleton is used by Resource | 916 // Oilpan + LSan: as the callbackHandler() singleton is used by Resource |
923 // and ResourcePtr finalizers, it cannot be released upon shutdown in | 917 // and ResourcePtr finalizers, it cannot be released upon shutdown in |
924 // preparation for leak detection. | 918 // preparation for leak detection. |
925 // | 919 // |
926 // Keep it out of LSan's reach instead. | 920 // Keep it out of LSan's reach instead. |
927 LEAK_SANITIZER_DISABLED_SCOPE; | 921 LEAK_SANITIZER_DISABLED_SCOPE; |
928 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ResourceCallback>, callbackHandle
r, (adoptPtrWillBeNoop(new ResourceCallback))); | 922 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ResourceCallback>, callbackHandle
r, (adoptPtrWillBeNoop(new ResourceCallback))); |
929 return callbackHandler.get(); | 923 return callbackHandler.get(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 case Resource::Media: | 1086 case Resource::Media: |
1093 return "Media"; | 1087 return "Media"; |
1094 case Resource::Manifest: | 1088 case Resource::Manifest: |
1095 return "Manifest"; | 1089 return "Manifest"; |
1096 } | 1090 } |
1097 ASSERT_NOT_REACHED(); | 1091 ASSERT_NOT_REACHED(); |
1098 return "Unknown"; | 1092 return "Unknown"; |
1099 } | 1093 } |
1100 | 1094 |
1101 } // namespace blink | 1095 } // namespace blink |
OLD | NEW |