| 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 431 } |
| 432 | 432 |
| 433 bool Resource::unlock() | 433 bool Resource::unlock() |
| 434 { | 434 { |
| 435 if (!m_data) | 435 if (!m_data) |
| 436 return false; | 436 return false; |
| 437 | 437 |
| 438 if (!m_data->isLocked()) | 438 if (!m_data->isLocked()) |
| 439 return true; | 439 return true; |
| 440 | 440 |
| 441 if (!memoryCache()->contains(this) || hasClients() || !m_revalidatingRequest
.isNull() || !m_loadFinishTime || !isSafeToUnlock()) | 441 if (!memoryCache()->contains(this) || hasClientsOrObservers() || !m_revalida
tingRequest.isNull() || !m_loadFinishTime || !isSafeToUnlock()) |
| 442 return false; | 442 return false; |
| 443 | 443 |
| 444 m_data->unlock(); | 444 m_data->unlock(); |
| 445 return true; | 445 return true; |
| 446 } | 446 } |
| 447 | 447 |
| 448 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web
DataConsumerHandle>) | 448 void Resource::responseReceived(const ResourceResponse& response, PassOwnPtr<Web
DataConsumerHandle>) |
| 449 { | 449 { |
| 450 m_responseTimestamp = currentTime(); | 450 m_responseTimestamp = currentTime(); |
| 451 | 451 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 #if ENABLE(OILPAN) | 511 #if ENABLE(OILPAN) |
| 512 return this; | 512 return this; |
| 513 #else | 513 #else |
| 514 return m_weakPtrFactory.createWeakPtr(); | 514 return m_weakPtrFactory.createWeakPtr(); |
| 515 #endif | 515 #endif |
| 516 } | 516 } |
| 517 | 517 |
| 518 String Resource::reasonNotDeletable() const | 518 String Resource::reasonNotDeletable() const |
| 519 { | 519 { |
| 520 StringBuilder builder; | 520 StringBuilder builder; |
| 521 if (hasClients()) { | 521 if (hasClientsOrObservers()) { |
| 522 builder.append("hasClients("); | 522 builder.append("hasClients("); |
| 523 builder.appendNumber(m_clients.size()); | 523 builder.appendNumber(m_clients.size()); |
| 524 if (!m_clientsAwaitingCallback.isEmpty()) { | 524 if (!m_clientsAwaitingCallback.isEmpty()) { |
| 525 builder.append(", AwaitingCallback="); | 525 builder.append(", AwaitingCallback="); |
| 526 builder.appendNumber(m_clientsAwaitingCallback.size()); | 526 builder.appendNumber(m_clientsAwaitingCallback.size()); |
| 527 } | 527 } |
| 528 if (!m_finishedClients.isEmpty()) { | 528 if (!m_finishedClients.isEmpty()) { |
| 529 builder.append(", Finished="); | 529 builder.append(", Finished="); |
| 530 builder.appendNumber(m_finishedClients.size()); | 530 builder.appendNumber(m_finishedClients.size()); |
| 531 } | 531 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 return true; | 586 return true; |
| 587 if (type == Resource::CSSStyleSheet) | 587 if (type == Resource::CSSStyleSheet) |
| 588 return true; | 588 return true; |
| 589 if (type == Resource::Script) | 589 if (type == Resource::Script) |
| 590 return true; | 590 return true; |
| 591 if (type == Resource::Font) | 591 if (type == Resource::Font) |
| 592 return true; | 592 return true; |
| 593 return false; | 593 return false; |
| 594 } | 594 } |
| 595 | 595 |
| 596 void Resource::addClient(ResourceClient* client) | 596 void Resource::willAddClientOrObserver() |
| 597 { | 597 { |
| 598 ASSERT(!isPurgeable()); | 598 ASSERT(!isPurgeable()); |
| 599 | |
| 600 if (m_preloadResult == PreloadNotReferenced) { | 599 if (m_preloadResult == PreloadNotReferenced) { |
| 601 if (isLoaded()) | 600 if (isLoaded()) |
| 602 m_preloadResult = PreloadReferencedWhileComplete; | 601 m_preloadResult = PreloadReferencedWhileComplete; |
| 603 else if (m_requestedFromNetworkingLayer) | 602 else if (m_requestedFromNetworkingLayer) |
| 604 m_preloadResult = PreloadReferencedWhileLoading; | 603 m_preloadResult = PreloadReferencedWhileLoading; |
| 605 else | 604 else |
| 606 m_preloadResult = PreloadReferenced; | 605 m_preloadResult = PreloadReferenced; |
| 607 } | 606 } |
| 608 if (!hasClients()) | 607 if (!hasClientsOrObservers()) |
| 609 memoryCache()->makeLive(this); | 608 memoryCache()->makeLive(this); |
| 609 } |
| 610 |
| 611 void Resource::addClient(ResourceClient* client) |
| 612 { |
| 613 willAddClientOrObserver(); |
| 610 | 614 |
| 611 if (!m_revalidatingRequest.isNull()) { | 615 if (!m_revalidatingRequest.isNull()) { |
| 612 m_clients.add(client); | 616 m_clients.add(client); |
| 613 return; | 617 return; |
| 614 } | 618 } |
| 615 | 619 |
| 616 // If we have existing data to send to the new client and the resource type
supprts it, send it asynchronously. | 620 // If we have existing data to send to the new client and the resource type
supprts it, send it asynchronously. |
| 617 if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getTyp
e()) && !m_needsSynchronousCacheHit) { | 621 if (!m_response.isNull() && !shouldSendCachedDataSynchronouslyForType(getTyp
e()) && !m_needsSynchronousCacheHit) { |
| 618 m_clientsAwaitingCallback.add(client); | 622 m_clientsAwaitingCallback.add(client); |
| 619 ResourceCallback::callbackHandler()->schedule(this); | 623 ResourceCallback::callbackHandler()->schedule(this); |
| 620 return; | 624 return; |
| 621 } | 625 } |
| 622 | 626 |
| 623 m_clients.add(client); | 627 m_clients.add(client); |
| 624 didAddClient(client); | 628 didAddClient(client); |
| 625 return; | 629 return; |
| 626 } | 630 } |
| 627 | 631 |
| 628 void Resource::removeClient(ResourceClient* client) | 632 void Resource::removeClient(ResourceClient* client) |
| 629 { | 633 { |
| 630 ASSERT(hasClient(client)); | 634 ASSERT(hasClient(client)); |
| 631 if (m_finishedClients.contains(client)) | 635 if (m_finishedClients.contains(client)) |
| 632 m_finishedClients.remove(client); | 636 m_finishedClients.remove(client); |
| 633 else if (m_clientsAwaitingCallback.contains(client)) | 637 else if (m_clientsAwaitingCallback.contains(client)) |
| 634 m_clientsAwaitingCallback.remove(client); | 638 m_clientsAwaitingCallback.remove(client); |
| 635 else | 639 else |
| 636 m_clients.remove(client); | 640 m_clients.remove(client); |
| 637 | 641 |
| 638 didRemoveClient(client); | |
| 639 | |
| 640 if (m_clientsAwaitingCallback.isEmpty()) | 642 if (m_clientsAwaitingCallback.isEmpty()) |
| 641 ResourceCallback::callbackHandler()->cancel(this); | 643 ResourceCallback::callbackHandler()->cancel(this); |
| 642 | 644 |
| 643 if (!hasClients()) { | 645 didRemoveClientOrObserver(); |
| 646 // This object may be dead here. |
| 647 } |
| 648 |
| 649 void Resource::didRemoveClientOrObserver() |
| 650 { |
| 651 if (!hasClientsOrObservers()) { |
| 644 RefPtrWillBeRawPtr<Resource> protect(this); | 652 RefPtrWillBeRawPtr<Resource> protect(this); |
| 645 memoryCache()->makeDead(this); | 653 memoryCache()->makeDead(this); |
| 646 allClientsRemoved(); | 654 allClientsAndObserversRemoved(); |
| 647 | 655 |
| 648 // RFC2616 14.9.2: | 656 // RFC2616 14.9.2: |
| 649 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" | 657 // "no-store: ... MUST make a best-effort attempt to remove the informat
ion from volatile storage as promptly as possible" |
| 650 // "... History buffers MAY store such responses as part of their normal
operation." | 658 // "... History buffers MAY store such responses as part of their normal
operation." |
| 651 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. | 659 // We allow non-secure content to be reused in history, but we do not al
low secure content to be reused. |
| 652 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { | 660 if (hasCacheControlNoStoreHeader() && url().protocolIs("https")) { |
| 653 memoryCache()->remove(this); | 661 memoryCache()->remove(this); |
| 654 memoryCache()->prune(); | 662 memoryCache()->prune(); |
| 655 } else { | 663 } else { |
| 656 memoryCache()->prune(this); | 664 memoryCache()->prune(this); |
| 657 } | 665 } |
| 658 } | 666 } |
| 659 // This object may be dead here. | 667 // This object may be dead here. |
| 660 } | 668 } |
| 661 | 669 |
| 662 void Resource::allClientsRemoved() | 670 void Resource::allClientsAndObserversRemoved() |
| 663 { | 671 { |
| 664 if (!m_loader) | 672 if (!m_loader) |
| 665 return; | 673 return; |
| 666 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this
)) | 674 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this
)) |
| 667 cancelTimerFired(&m_cancelTimer); | 675 cancelTimerFired(&m_cancelTimer); |
| 668 else if (!m_cancelTimer.isActive()) | 676 else if (!m_cancelTimer.isActive()) |
| 669 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); | 677 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); |
| 670 | 678 |
| 671 unlock(); | 679 unlock(); |
| 672 } | 680 } |
| 673 | 681 |
| 674 void Resource::cancelTimerFired(Timer<Resource>* timer) | 682 void Resource::cancelTimerFired(Timer<Resource>* timer) |
| 675 { | 683 { |
| 676 ASSERT_UNUSED(timer, timer == &m_cancelTimer); | 684 ASSERT_UNUSED(timer, timer == &m_cancelTimer); |
| 677 if (hasClients() || !m_loader) | 685 if (hasClientsOrObservers() || !m_loader) |
| 678 return; | 686 return; |
| 679 RefPtrWillBeRawPtr<Resource> protect(this); | 687 RefPtrWillBeRawPtr<Resource> protect(this); |
| 680 m_loader->cancelIfNotFinishing(); | 688 m_loader->cancelIfNotFinishing(); |
| 681 if (m_status != Cached) | 689 if (m_status != Cached) |
| 682 memoryCache()->remove(this); | 690 memoryCache()->remove(this); |
| 683 } | 691 } |
| 684 | 692 |
| 685 void Resource::setDecodedSize(size_t decodedSize) | 693 void Resource::setDecodedSize(size_t decodedSize) |
| 686 { | 694 { |
| 687 if (decodedSize == m_decodedSize) | 695 if (decodedSize == m_decodedSize) |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 return m_data && !m_data->isLocked(); | 890 return m_data && !m_data->isLocked(); |
| 883 } | 891 } |
| 884 | 892 |
| 885 bool Resource::lock() | 893 bool Resource::lock() |
| 886 { | 894 { |
| 887 if (!m_data) | 895 if (!m_data) |
| 888 return true; | 896 return true; |
| 889 if (m_data->isLocked()) | 897 if (m_data->isLocked()) |
| 890 return true; | 898 return true; |
| 891 | 899 |
| 892 ASSERT(!hasClients()); | 900 ASSERT(!hasClientsOrObservers()); |
| 893 | 901 |
| 894 // If locking fails, our buffer has been purged. There's no point | 902 // If locking fails, our buffer has been purged. There's no point |
| 895 // in leaving a purged resource in MemoryCache. | 903 // in leaving a purged resource in MemoryCache. |
| 896 if (!m_data->lock()) { | 904 if (!m_data->lock()) { |
| 897 memoryCache()->remove(this); | 905 memoryCache()->remove(this); |
| 898 return false; | 906 return false; |
| 899 } | 907 } |
| 900 return true; | 908 return true; |
| 901 } | 909 } |
| 902 | 910 |
| 903 size_t Resource::overheadSize() const | 911 size_t Resource::overheadSize() const |
| 904 { | 912 { |
| 905 static const int kAverageClientsHashMapSize = 384; | 913 static const int kAverageClientsHashMapSize = 384; |
| 906 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().string().length() * 2; | 914 return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapS
ize + m_resourceRequest.url().string().length() * 2; |
| 907 } | 915 } |
| 908 | 916 |
| 909 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
orityValue) | 917 void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPri
orityValue) |
| 910 { | 918 { |
| 911 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); | 919 m_resourceRequest.setPriority(loadPriority, intraPriorityValue); |
| 912 if (m_loader) | 920 if (m_loader) |
| 913 m_loader->didChangePriority(loadPriority, intraPriorityValue); | 921 m_loader->didChangePriority(loadPriority, intraPriorityValue); |
| 914 } | 922 } |
| 915 | 923 |
| 916 ResourcePriority Resource::priorityFromClients() | |
| 917 { | |
| 918 ResourcePriority priority; | |
| 919 ResourceClientWalker<ResourceClient> walker(m_clients); | |
| 920 while (ResourceClient* c = walker.next()) { | |
| 921 ResourcePriority nextPriority = c->computeResourcePriority(); | |
| 922 if (nextPriority.visibility == ResourcePriority::NotVisible) | |
| 923 continue; | |
| 924 priority.visibility = ResourcePriority::Visible; | |
| 925 priority.intraPriorityValue += nextPriority.intraPriorityValue; | |
| 926 } | |
| 927 return priority; | |
| 928 } | |
| 929 | |
| 930 Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler() | 924 Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler() |
| 931 { | 925 { |
| 932 // Oilpan + LSan: as the callbackHandler() singleton is used by Resource | 926 // Oilpan + LSan: as the callbackHandler() singleton is used by Resource |
| 933 // and ResourcePtr finalizers, it cannot be released upon shutdown in | 927 // and ResourcePtr finalizers, it cannot be released upon shutdown in |
| 934 // preparation for leak detection. | 928 // preparation for leak detection. |
| 935 // | 929 // |
| 936 // Keep it out of LSan's reach instead. | 930 // Keep it out of LSan's reach instead. |
| 937 LEAK_SANITIZER_DISABLED_SCOPE; | 931 LEAK_SANITIZER_DISABLED_SCOPE; |
| 938 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ResourceCallback>, callbackHandle
r, (adoptPtrWillBeNoop(new ResourceCallback))); | 932 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ResourceCallback>, callbackHandle
r, (adoptPtrWillBeNoop(new ResourceCallback))); |
| 939 return callbackHandler.get(); | 933 return callbackHandler.get(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 case Resource::Media: | 1104 case Resource::Media: |
| 1111 return "Media"; | 1105 return "Media"; |
| 1112 case Resource::Manifest: | 1106 case Resource::Manifest: |
| 1113 return "Manifest"; | 1107 return "Manifest"; |
| 1114 } | 1108 } |
| 1115 ASSERT_NOT_REACHED(); | 1109 ASSERT_NOT_REACHED(); |
| 1116 return "Unknown"; | 1110 return "Unknown"; |
| 1117 } | 1111 } |
| 1118 | 1112 |
| 1119 } // namespace blink | 1113 } // namespace blink |
| OLD | NEW |