| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 } | 471 } |
| 472 | 472 |
| 473 void Resource::removeClient(ResourceClient* client) | 473 void Resource::removeClient(ResourceClient* client) |
| 474 { | 474 { |
| 475 if (m_clientsAwaitingCallback.contains(client)) { | 475 if (m_clientsAwaitingCallback.contains(client)) { |
| 476 ASSERT(!m_clients.contains(client)); | 476 ASSERT(!m_clients.contains(client)); |
| 477 m_clientsAwaitingCallback.remove(client); | 477 m_clientsAwaitingCallback.remove(client); |
| 478 if (m_clientsAwaitingCallback.isEmpty()) | 478 if (m_clientsAwaitingCallback.isEmpty()) |
| 479 ResourceCallback::callbackHandler()->cancel(this); | 479 ResourceCallback::callbackHandler()->cancel(this); |
| 480 } else { | 480 } else { |
| 481 ASSERT(m_clients.contains(client)); | 481 RELEASE_ASSERT(m_clients.contains(client)); |
| 482 m_clients.remove(client); | 482 m_clients.remove(client); |
| 483 didRemoveClient(client); | 483 didRemoveClient(client); |
| 484 } | 484 } |
| 485 | 485 |
| 486 bool deleted = deleteIfPossible(); | 486 bool deleted = deleteIfPossible(); |
| 487 if (!deleted && !hasClients()) { | 487 if (!deleted && !hasClients()) { |
| 488 memoryCache()->makeDead(this); | 488 memoryCache()->makeDead(this); |
| 489 if (!m_switchingClientsToRevalidatedResource) | 489 if (!m_switchingClientsToRevalidatedResource) |
| 490 allClientsRemoved(); | 490 allClientsRemoved(); |
| 491 | 491 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 556 } |
| 557 | 557 |
| 558 void Resource::didAccessDecodedData() | 558 void Resource::didAccessDecodedData() |
| 559 { | 559 { |
| 560 memoryCache()->updateDecodedResource(this, UpdateForAccess); | 560 memoryCache()->updateDecodedResource(this, UpdateForAccess); |
| 561 memoryCache()->prune(); | 561 memoryCache()->prune(); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void Resource::finishPendingClients() | 564 void Resource::finishPendingClients() |
| 565 { | 565 { |
| 566 while (!m_clientsAwaitingCallback.isEmpty()) { | 566 // We're going to notify clients one by one. It is simple if the client does
nothing. |
| 567 ResourceClient* client = m_clientsAwaitingCallback.begin()->key; | 567 // However there are a couple other things that can happen. |
| 568 m_clientsAwaitingCallback.remove(client); | 568 // |
| 569 // 1. Clients can be added during the loop. Make sure they are not processed
. |
| 570 // 2. Clients can be removed during the loop. Make sure they are always avai
lable to be |
| 571 // removed. Also don't call removed clients or add them back. |
| 572 |
| 573 // Handle case (1) by saving a list of clients to notify. A separate list al
so ensure |
| 574 // a client is either in m_clients or m_clientsAwaitingCallback. |
| 575 Vector<ResourceClient*> clientsToNotify; |
| 576 copyToVector(m_clientsAwaitingCallback, clientsToNotify); |
| 577 |
| 578 for (size_t i = 0; i < clientsToNotify.size(); ++i) { |
| 579 ResourceClient* client = clientsToNotify[i]; |
| 580 |
| 581 // Handle case (2) to skip removed clients. |
| 582 if (!m_clientsAwaitingCallback.remove(client)) |
| 583 continue; |
| 569 m_clients.add(client); | 584 m_clients.add(client); |
| 570 didAddClient(client); | 585 didAddClient(client); |
| 571 } | 586 } |
| 587 |
| 588 bool scheduled = ResourceCallback::callbackHandler()->isScheduled(this); |
| 589 // It is a critical problem if a callback is scheduled but there is no clien
t waiting for it. |
| 590 // Such a callback cannot be cancelled. It is better to crash the renderer n
ow. |
| 591 RELEASE_ASSERT(!scheduled || !m_clientsAwaitingCallback.isEmpty()); |
| 592 |
| 593 // Prevent the case when there are clients waiting but no callback scheduled
. |
| 594 ASSERT(m_clientsAwaitingCallback.isEmpty() || scheduled); |
| 572 } | 595 } |
| 573 | 596 |
| 574 void Resource::prune() | 597 void Resource::prune() |
| 575 { | 598 { |
| 576 destroyDecodedDataIfPossible(); | 599 destroyDecodedDataIfPossible(); |
| 577 unlock(); | 600 unlock(); |
| 578 } | 601 } |
| 579 | 602 |
| 580 void Resource::setResourceToRevalidate(Resource* resource) | 603 void Resource::setResourceToRevalidate(Resource* resource) |
| 581 { | 604 { |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 return "Shader"; | 965 return "Shader"; |
| 943 case Resource::ImportResource: | 966 case Resource::ImportResource: |
| 944 return "ImportResource"; | 967 return "ImportResource"; |
| 945 } | 968 } |
| 946 ASSERT_NOT_REACHED(); | 969 ASSERT_NOT_REACHED(); |
| 947 return "Unknown"; | 970 return "Unknown"; |
| 948 } | 971 } |
| 949 #endif // !LOG_DISABLED | 972 #endif // !LOG_DISABLED |
| 950 | 973 |
| 951 } | 974 } |
| OLD | NEW |