#include "config.h"
#include "IconDatabase.h"
#if ENABLE(ICONDATABASE)
#include "DocumentLoader.h"
#include "FileSystem.h"
#include "IconDatabaseClient.h"
#include "IconRecord.h"
#include "Image.h"
#include "Logging.h"
#include "SQLiteStatement.h"
#include "SQLiteTransaction.h"
#include "SuddenTermination.h"
#include <wtf/AutodrainedPool.h>
#include <wtf/MainThread.h>
#include <wtf/StdLibExtras.h>
#define ASSERT_NOT_SYNC_THREAD() ASSERT(!m_syncThreadRunning || !IS_ICON_SYNC_THREAD())
#define IS_ICON_SYNC_THREAD() (m_syncThread == currentThread())
#define ASSERT_ICON_SYNC_THREAD() ASSERT(IS_ICON_SYNC_THREAD())
#if PLATFORM(GTK)
#define CAN_THEME_URL_ICON
#endif
namespace WebCore {
static int databaseCleanupCounter = 0;
static const int currentDatabaseVersion = 6;
static const int iconExpirationTime = 60*60*24*4;
static const int updateTimerDelay = 5;
static bool checkIntegrityOnOpen = false;
#if PLATFORM(GTK)
static const int notUsedIconExpirationTime = 60*60*24*30;
#endif
#if !LOG_DISABLED || !ERROR_DISABLED
static String urlForLogging(const String& url)
{
static unsigned urlTruncationLength = 120;
if (url.length() < urlTruncationLength)
return url;
return url.substring(0, urlTruncationLength) + "...";
}
#endif
class DefaultIconDatabaseClient final : public IconDatabaseClient {
WTF_MAKE_FAST_ALLOCATED;
public:
virtual void didImportIconURLForPageURL(const String&) override { }
virtual void didImportIconDataForPageURL(const String&) override { }
virtual void didChangeIconForPageURL(const String&) override { }
virtual void didRemoveAllIcons() override { }
virtual void didFinishURLImport() override { }
};
static IconDatabaseClient* defaultClient()
{
static IconDatabaseClient* defaultClient = new DefaultIconDatabaseClient;
return defaultClient;
}
void IconDatabase::setClient(IconDatabaseClient* client)
{
ASSERT(client);
ASSERT(!m_syncThreadRunning);
if (!client || m_syncThreadRunning)
return;
m_client = client;
}
bool IconDatabase::open(const String& directory, const String& filename)
{
ASSERT_NOT_SYNC_THREAD();
if (!m_isEnabled)
return false;
if (isOpen()) {
LOG_ERROR("Attempt to reopen the IconDatabase which is already open. Must close it first.");
return false;
}
m_databaseDirectory = directory.isolatedCopy();
m_completeDatabasePath = pathByAppendingComponent(m_databaseDirectory, filename);
m_syncLock.lock();
m_syncThread = createThread(IconDatabase::iconDatabaseSyncThreadStart, this, "WebCore: IconDatabase");
m_syncThreadRunning = m_syncThread;
m_syncLock.unlock();
if (!m_syncThread)
return false;
return true;
}
void IconDatabase::close()
{
ASSERT_NOT_SYNC_THREAD();
if (m_syncThreadRunning) {
m_threadTerminationRequested = true;
wakeSyncThread();
waitForThreadCompletion(m_syncThread);
}
m_syncThreadRunning = false;
m_threadTerminationRequested = false;
m_removeIconsRequested = false;
m_syncDB.close();
if (!isOpen() && m_client)
m_client->didClose();
}
void IconDatabase::removeAllIcons()
{
ASSERT_NOT_SYNC_THREAD();
if (!isOpen())
return;
LOG(IconDatabase, "Requesting background thread to remove all icons");
{
MutexLocker locker(m_urlAndIconLock);
HashMap<String, PageURLRecord*>::iterator iter = m_pageURLToRecordMap.begin();
HashMap<String, PageURLRecord*>::iterator end = m_pageURLToRecordMap.end();
for (; iter != end; ++iter)
(*iter).value->setIconRecord(0);
m_iconURLToRecordMap.clear();
{
MutexLocker locker(m_pendingSyncLock);
m_pageURLsPendingSync.clear();
m_iconsPendingSync.clear();
}
{
MutexLocker locker(m_pendingReadingLock);
m_pageURLsPendingImport.clear();
m_pageURLsInterestedInIcons.clear();
m_iconsPendingReading.clear();
m_loadersPendingDecision.clear();
}
}
m_removeIconsRequested = true;
wakeSyncThread();
}
Image* IconDatabase::synchronousIconForPageURL(const String& pageURLOriginal, const IntSize& size)
{
ASSERT_NOT_SYNC_THREAD();
if (!isOpen() || !documentCanHaveIcon(pageURLOriginal))
return 0;
MutexLocker locker(m_urlAndIconLock);
performPendingRetainAndReleaseOperations();
String pageURLCopy;
PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURLOriginal);
if (!pageRecord) {
pageURLCopy = pageURLOriginal.isolatedCopy();
pageRecord = getOrCreatePageURLRecord(pageURLCopy);
}
if (!pageRecord) {
MutexLocker locker(m_pendingReadingLock);
if (!m_iconURLImportComplete)
m_pageURLsInterestedInIcons.add(pageURLCopy);
return 0;
}
IconRecord* iconRecord = pageRecord->iconRecord();
if (!m_iconURLImportComplete && !iconRecord)
return 0;
ASSERT(iconRecord || databaseCleanupCounter || m_retainedPageURLs.contains(pageURLOriginal));
if (!iconRecord)
return 0;
if (iconRecord->imageDataStatus() == ImageDataStatusUnknown) {
if (pageURLCopy.isNull())
pageURLCopy = pageURLOriginal.isolatedCopy();
MutexLocker locker(m_pendingReadingLock);
m_pageURLsInterestedInIcons.add(pageURLCopy);
m_iconsPendingReading.add(iconRecord);
wakeSyncThread();
return 0;
}
if (size == IntSize(0, 0))
return 0;
return iconRecord->image(size);
}
PassNativeImagePtr IconDatabase::synchronousNativeIconForPageURL(const String& pageURLOriginal, const IntSize& size)
{
Image* icon = synchronousIconForPageURL(pageURLOriginal, size);
if (!icon)
return 0;
MutexLocker locker(m_urlAndIconLock);
return icon->nativeImageForCurrentFrame();
}
void IconDatabase::readIconForPageURLFromDisk(const String& pageURL)
{
synchronousIconForPageURL(pageURL, IntSize(0, 0));
}
String IconDatabase::synchronousIconURLForPageURL(const String& pageURLOriginal)
{
ASSERT_NOT_SYNC_THREAD();
if (!isOpen() || !documentCanHaveIcon(pageURLOriginal))
return String();
MutexLocker locker(m_urlAndIconLock);
PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURLOriginal);
if (!pageRecord)
pageRecord = getOrCreatePageURLRecord(pageURLOriginal.isolatedCopy());
if (!pageRecord)
return String();
return pageRecord->iconRecord() ? pageRecord->iconRecord()->iconURL().isolatedCopy() : String();
}
#ifdef CAN_THEME_URL_ICON
static inline void loadDefaultIconRecord(IconRecord* defaultIconRecord)
{
defaultIconRecord->loadImageFromResource("urlIcon");
}
#else
static inline void loadDefaultIconRecord(IconRecord* defaultIconRecord)
{
static const unsigned char defaultIconData[] = { 0x4D, 0x4D,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9F, 0x68, 0x00, 0x16, 0x76, 0x0D, 0xA1, 0x00, 0x08, 0x06,
0x03, 0x81, 0xA0, 0x20, 0x1A, 0x0D, 0x06, 0x80, 0x30, 0x24, 0x12, 0x89, 0x20, 0x98, 0x4A, 0x1F, 0x0F, 0x21, 0xA0, 0x9E, 0x36, 0x16, 0xC2, 0x88, 0xE6, 0x48, 0x9B, 0x83,
0x31, 0x1C, 0x55, 0x1E, 0x43, 0x59, 0x1A, 0x56, 0x1E, 0x42, 0xF0, 0xFA, 0x4D, 0x1B, 0x9B, 0x08, 0xDC, 0x5B, 0x02, 0xA1, 0x30, 0x7E, 0x3C, 0xEE, 0x5B, 0xA6, 0xDD, 0xB8,
0x6D, 0x5B, 0x62, 0xB7, 0xCD, 0xF3, 0x9C, 0xEA, 0x04, 0x80, 0x80, 0x00, 0x00, 0x0E, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x01,
0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0xE0, 0x01, 0x03, 0x00, 0x03, 0x00, 0x00,
0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x01, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x01, 0x11, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x08, 0x01, 0x15, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x01, 0x16, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x17,
0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x29, 0x01, 0x1A, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0xE8, 0x01, 0x1B, 0x00, 0x05, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x03, 0xF0, 0x01, 0x1C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x28, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02,
0x00, 0x00, 0x01, 0x52, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x0A,
0xFC, 0x80, 0x00, 0x00, 0x27, 0x10, 0x00, 0x0A, 0xFC, 0x80, 0x00, 0x00, 0x27, 0x10 };
static SharedBuffer* defaultIconBuffer = SharedBuffer::create(defaultIconData, sizeof(defaultIconData)).leakRef();
defaultIconRecord->setImageData(defaultIconBuffer);
}
#endif
Image* IconDatabase::defaultIcon(const IntSize& size)
{
ASSERT_NOT_SYNC_THREAD();
if (!m_defaultIconRecord) {
m_defaultIconRecord = IconRecord::create("urlIcon");
loadDefaultIconRecord(m_defaultIconRecord.get());
}
return m_defaultIconRecord->image(size);
}
void IconDatabase::retainIconForPageURL(const String& pageURL)
{
ASSERT_NOT_SYNC_THREAD();
if (!isEnabled() || !documentCanHaveIcon(pageURL))
return;
{
MutexLocker locker(m_urlsToRetainOrReleaseLock);
m_urlsToRetain.add(pageURL.isolatedCopy());
m_retainOrReleaseIconRequested = true;
}
scheduleOrDeferSyncTimer();
}
void IconDatabase::performRetainIconForPageURL(const String& pageURLOriginal, int retainCount)
{
PageURLRecord* record = m_pageURLToRecordMap.get(pageURLOriginal);
String pageURL;
if (!record) {
pageURL = pageURLOriginal.isolatedCopy();
record = new PageURLRecord(pageURL);
m_pageURLToRecordMap.set(pageURL, record);
}
if (!record->retain(retainCount)) {
if (pageURL.isNull())
pageURL = pageURLOriginal.isolatedCopy();
m_retainedPageURLs.add(pageURL);
if (!m_iconURLImportComplete)
return;
MutexLocker locker(m_pendingSyncLock);
if (!m_privateBrowsingEnabled && m_pageURLsPendingSync.contains(pageURL)) {
LOG(IconDatabase, "Bringing %s back from the brink", pageURL.ascii().data());
m_pageURLsPendingSync.set(pageURL, record->snapshot());
}
}
}
void IconDatabase::releaseIconForPageURL(const String& pageURL)
{
ASSERT_NOT_SYNC_THREAD();
if (!isEnabled() || !documentCanHaveIcon(pageURL))
return;
{
MutexLocker locker(m_urlsToRetainOrReleaseLock);
m_urlsToRelease.add(pageURL.isolatedCopy());
m_retainOrReleaseIconRequested = true;
}
scheduleOrDeferSyncTimer();
}
void IconDatabase::performReleaseIconForPageURL(const String& pageURLOriginal, int releaseCount)
{
if (!m_retainedPageURLs.contains(pageURLOriginal)) {
LOG_ERROR("Attempting to release icon for URL %s which is not retained", urlForLogging(pageURLOriginal).ascii().data());
return;
}
PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURLOriginal);
ASSERT(pageRecord);
LOG(IconDatabase, "Releasing pageURL %s to a retain count of %i", urlForLogging(pageURLOriginal).ascii().data(), pageRecord->retainCount() - 1);
ASSERT(pageRecord->retainCount() > 0);
if (pageRecord->release(releaseCount))
return;
LOG(IconDatabase, "No more retainers for PageURL %s", urlForLogging(pageURLOriginal).ascii().data());
m_pageURLToRecordMap.remove(pageURLOriginal);
m_retainedPageURLs.remove(pageURLOriginal);
IconRecord* iconRecord = pageRecord->iconRecord();
ASSERT(!iconRecord || (iconRecord && m_iconURLToRecordMap.get(iconRecord->iconURL()) == iconRecord));
{
MutexLocker locker(m_pendingReadingLock);
if (!m_iconURLImportComplete)
m_pageURLsPendingImport.remove(pageURLOriginal);
m_pageURLsInterestedInIcons.remove(pageURLOriginal);
if (iconRecord && iconRecord->hasOneRef()) {
m_iconURLToRecordMap.remove(iconRecord->iconURL());
m_iconsPendingReading.remove(iconRecord);
}
}
if (!m_privateBrowsingEnabled) {
MutexLocker locker(m_pendingSyncLock);
m_pageURLsPendingSync.set(pageURLOriginal.isolatedCopy(), pageRecord->snapshot(true));
if (iconRecord && iconRecord->hasOneRef())
m_iconsPendingSync.set(iconRecord->iconURL(), iconRecord->snapshot(true));
}
delete pageRecord;
}
void IconDatabase::setIconDataForIconURL(PassRefPtr<SharedBuffer> dataOriginal, const String& iconURLOriginal)
{
ASSERT_NOT_SYNC_THREAD();
if (!isOpen() || iconURLOriginal.isEmpty())
return;
RefPtr<SharedBuffer> data = dataOriginal ? dataOriginal->copy() : PassRefPtr<SharedBuffer>(0);
String iconURL = iconURLOriginal.isolatedCopy();
Vector<String> pageURLs;
{
MutexLocker locker(m_urlAndIconLock);
RefPtr<IconRecord> icon = m_iconURLToRecordMap.get(iconURL);
if (icon) {
MutexLocker locker(m_pendingReadingLock);
m_iconsPendingReading.remove(icon.get());
} else
icon = getOrCreateIconRecord(iconURL);
icon->setImageData(data.release());
icon->setTimestamp((int)currentTime());
pageURLs.appendRange(icon->retainingPageURLs().begin(), icon->retainingPageURLs().end());
if (!m_privateBrowsingEnabled) {
MutexLocker locker(m_pendingSyncLock);
m_iconsPendingSync.set(iconURL, icon->snapshot());
}
if (icon->hasOneRef()) {
ASSERT(icon->retainingPageURLs().isEmpty());
LOG(IconDatabase, "Icon for icon url %s is about to be destroyed - removing mapping for it", urlForLogging(icon->iconURL()).ascii().data());
m_iconURLToRecordMap.remove(icon->iconURL());
}
}
if (!IS_ICON_SYNC_THREAD()) {
scheduleOrDeferSyncTimer();
for (unsigned i = 0; i < pageURLs.size(); ++i) {
AutodrainedPool pool;
LOG(IconDatabase, "Dispatching notification that retaining pageURL %s has a new icon", urlForLogging(pageURLs[i]).ascii().data());
m_client->didChangeIconForPageURL(pageURLs[i]);
}
}
}
void IconDatabase::setIconURLForPageURL(const String& iconURLOriginal, const String& pageURLOriginal)
{
ASSERT_NOT_SYNC_THREAD();
ASSERT(!iconURLOriginal.isEmpty());
if (!isOpen() || !documentCanHaveIcon(pageURLOriginal))
return;
String iconURL, pageURL;
{
MutexLocker locker(m_urlAndIconLock);
PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURLOriginal);
if (pageRecord && pageRecord->iconRecord() && pageRecord->iconRecord()->iconURL() == iconURLOriginal)
return;
pageURL = pageURLOriginal.isolatedCopy();
iconURL = iconURLOriginal.isolatedCopy();
if (!pageRecord) {
pageRecord = new PageURLRecord(pageURL);
m_pageURLToRecordMap.set(pageURL, pageRecord);
}
RefPtr<IconRecord> iconRecord = pageRecord->iconRecord();
pageRecord->setIconRecord(getOrCreateIconRecord(iconURL));
if (iconRecord && iconRecord->hasOneRef()) {
ASSERT(iconRecord->retainingPageURLs().size() == 0);
LOG(IconDatabase, "Icon for icon url %s is about to be destroyed - removing mapping for it", urlForLogging(iconRecord->iconURL()).ascii().data());
m_iconURLToRecordMap.remove(iconRecord->iconURL());
MutexLocker locker(m_pendingReadingLock);
m_iconsPendingReading.remove(iconRecord.get());
}
if (!m_privateBrowsingEnabled) {
MutexLocker locker(m_pendingSyncLock);
m_pageURLsPendingSync.set(pageURL, pageRecord->snapshot());
if (iconRecord && iconRecord->hasOneRef())
m_iconsPendingSync.set(iconRecord->iconURL(), iconRecord->snapshot(true));
}
}
if (!IS_ICON_SYNC_THREAD()) {
scheduleOrDeferSyncTimer();
LOG(IconDatabase, "Dispatching notification that we changed an icon mapping for url %s", urlForLogging(pageURL).ascii().data());
AutodrainedPool pool;
m_client->didChangeIconForPageURL(pageURL);
}
}
IconLoadDecision IconDatabase::synchronousLoadDecisionForIconURL(const String& iconURL, DocumentLoader* notificationDocumentLoader)
{
ASSERT_NOT_SYNC_THREAD();
if (!isOpen() || iconURL.isEmpty())
return IconLoadNo;
{
MutexLocker locker(m_urlAndIconLock);
if (IconRecord* icon = m_iconURLToRecordMap.get(iconURL)) {
LOG(IconDatabase, "Found expiration time on a present icon based on existing IconRecord");
return static_cast<int>(currentTime()) - static_cast<int>(icon->getTimestamp()) > iconExpirationTime ? IconLoadYes : IconLoadNo;
}
}
MutexLocker readingLocker(m_pendingReadingLock);
if (m_iconURLImportComplete)
return IconLoadYes;
LOG(IconDatabase, "Don't know if we should load %s or not - adding %p to the set of document loaders waiting on a decision", iconURL.ascii().data(), notificationDocumentLoader);
if (notificationDocumentLoader)
m_loadersPendingDecision.add(notificationDocumentLoader);
return IconLoadUnknown;
}
bool IconDatabase::synchronousIconDataKnownForIconURL(const String& iconURL)
{
ASSERT_NOT_SYNC_THREAD();
MutexLocker locker(m_urlAndIconLock);
if (IconRecord* icon = m_iconURLToRecordMap.get(iconURL))
return icon->imageDataStatus() != ImageDataStatusUnknown;
return false;
}
void IconDatabase::setEnabled(bool enabled)
{
ASSERT_NOT_SYNC_THREAD();
if (!enabled && isOpen())
close();
m_isEnabled = enabled;
}
bool IconDatabase::isEnabled() const
{
ASSERT_NOT_SYNC_THREAD();
return m_isEnabled;
}
void IconDatabase::setPrivateBrowsingEnabled(bool flag)
{
m_privateBrowsingEnabled = flag;
}
bool IconDatabase::isPrivateBrowsingEnabled() const
{
return m_privateBrowsingEnabled;
}
void IconDatabase::delayDatabaseCleanup()
{
++databaseCleanupCounter;
if (databaseCleanupCounter == 1)
LOG(IconDatabase, "Database cleanup is now DISABLED");
}
void IconDatabase::allowDatabaseCleanup()
{
if (--databaseCleanupCounter < 0)
databaseCleanupCounter = 0;
if (databaseCleanupCounter == 0)
LOG(IconDatabase, "Database cleanup is now ENABLED");
}
void IconDatabase::checkIntegrityBeforeOpening()
{
checkIntegrityOnOpen = true;
}
size_t IconDatabase::pageURLMappingCount()
{
MutexLocker locker(m_urlAndIconLock);
return m_pageURLToRecordMap.size();
}
size_t IconDatabase::retainedPageURLCount()
{
MutexLocker locker(m_urlAndIconLock);
performPendingRetainAndReleaseOperations();
return m_retainedPageURLs.size();
}
size_t IconDatabase::iconRecordCount()
{
MutexLocker locker(m_urlAndIconLock);
return m_iconURLToRecordMap.size();
}
size_t IconDatabase::iconRecordCountWithData()
{
MutexLocker locker(m_urlAndIconLock);
size_t result = 0;
HashMap<String, IconRecord*>::iterator i = m_iconURLToRecordMap.begin();
HashMap<String, IconRecord*>::iterator end = m_iconURLToRecordMap.end();
for (; i != end; ++i)
result += ((*i).value->imageDataStatus() == ImageDataStatusPresent);
return result;
}
IconDatabase::IconDatabase()
: m_syncTimer(this, &IconDatabase::syncTimerFired)
, m_syncThreadRunning(false)
, m_scheduleOrDeferSyncTimerRequested(false)
, m_isEnabled(false)
, m_privateBrowsingEnabled(false)
, m_threadTerminationRequested(false)
, m_removeIconsRequested(false)
, m_iconURLImportComplete(false)
, m_syncThreadHasWorkToDo(false)
, m_retainOrReleaseIconRequested(false)
, m_initialPruningComplete(false)
, m_mainThreadCallbackCount(0)
, m_client(defaultClient())
{
LOG(IconDatabase, "Creating IconDatabase %p", this);
ASSERT(isMainThread());
}
IconDatabase::~IconDatabase()
{
ASSERT(!isOpen());
}
void IconDatabase::notifyPendingLoadDecisions()
{
ASSERT_NOT_SYNC_THREAD();
ASSERT(m_iconURLImportComplete);
LOG(IconDatabase, "Notifying all DocumentLoaders that were waiting on a load decision for their icons");
HashSet<RefPtr<DocumentLoader>>::iterator i = m_loadersPendingDecision.begin();
HashSet<RefPtr<DocumentLoader>>::iterator end = m_loadersPendingDecision.end();
for (; i != end; ++i)
if ((*i)->refCount() > 1)
(*i)->iconLoadDecisionAvailable();
m_loadersPendingDecision.clear();
}
void IconDatabase::wakeSyncThread()
{
MutexLocker locker(m_syncLock);
if (!m_disableSuddenTerminationWhileSyncThreadHasWorkToDo)
m_disableSuddenTerminationWhileSyncThreadHasWorkToDo = std::make_unique<SuddenTerminationDisabler>();
m_syncThreadHasWorkToDo = true;
m_syncCondition.signal();
}
void IconDatabase::scheduleOrDeferSyncTimer()
{
ASSERT_NOT_SYNC_THREAD();
if (m_scheduleOrDeferSyncTimerRequested)
return;
if (!m_disableSuddenTerminationWhileSyncTimerScheduled)
m_disableSuddenTerminationWhileSyncTimerScheduled = std::make_unique<SuddenTerminationDisabler>();
m_scheduleOrDeferSyncTimerRequested = true;
callOnMainThread([this] {
m_syncTimer.startOneShot(updateTimerDelay);
m_scheduleOrDeferSyncTimerRequested = false;
});
}
void IconDatabase::syncTimerFired(Timer<IconDatabase>&)
{
ASSERT_NOT_SYNC_THREAD();
wakeSyncThread();
m_disableSuddenTerminationWhileSyncTimerScheduled.reset();
}
bool IconDatabase::isOpen() const
{
return isOpenBesidesMainThreadCallbacks() || m_mainThreadCallbackCount;
}
bool IconDatabase::isOpenBesidesMainThreadCallbacks() const
{
MutexLocker locker(m_syncLock);
return m_syncThreadRunning || m_syncDB.isOpen();
}
String IconDatabase::databasePath() const
{
MutexLocker locker(m_syncLock);
return m_completeDatabasePath.isolatedCopy();
}
String IconDatabase::defaultDatabaseFilename()
{
DEPRECATED_DEFINE_STATIC_LOCAL(String, defaultDatabaseFilename, (ASCIILiteral("WebpageIcons.db")));
return defaultDatabaseFilename.isolatedCopy();
}
PassRefPtr<IconRecord> IconDatabase::getOrCreateIconRecord(const String& iconURL)
{
ASSERT(!m_urlAndIconLock.tryLock());
if (IconRecord* icon = m_iconURLToRecordMap.get(iconURL))
return icon;
RefPtr<IconRecord> newIcon = IconRecord::create(iconURL);
m_iconURLToRecordMap.set(iconURL, newIcon.get());
return newIcon.release();
}
PageURLRecord* IconDatabase::getOrCreatePageURLRecord(const String& pageURL)
{
ASSERT(!m_urlAndIconLock.tryLock());
if (!documentCanHaveIcon(pageURL))
return 0;
PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURL);
MutexLocker locker(m_pendingReadingLock);
if (!m_iconURLImportComplete) {
if (!pageRecord) {
LOG(IconDatabase, "Creating new PageURLRecord for pageURL %s", urlForLogging(pageURL).ascii().data());
pageRecord = new PageURLRecord(pageURL);
m_pageURLToRecordMap.set(pageURL, pageRecord);
}
if (!pageRecord->iconRecord()) {
m_pageURLsPendingImport.add(pageURL);
return 0;
}
}
return pageRecord;
}
bool IconDatabase::shouldStopThreadActivity() const
{
ASSERT_ICON_SYNC_THREAD();
return m_threadTerminationRequested || m_removeIconsRequested;
}
void IconDatabase::iconDatabaseSyncThreadStart(void* vIconDatabase)
{
IconDatabase* iconDB = static_cast<IconDatabase*>(vIconDatabase);
iconDB->iconDatabaseSyncThread();
}
void IconDatabase::iconDatabaseSyncThread()
{
m_syncLock.lock();
m_syncLock.unlock();
ASSERT_ICON_SYNC_THREAD();
LOG(IconDatabase, "(THREAD) IconDatabase sync thread started");
#if !LOG_DISABLED
double startTime = monotonicallyIncreasingTime();
#endif
makeAllDirectories(m_databaseDirectory);
String journalFilename = m_completeDatabasePath + "-journal";
if (!checkIntegrityOnOpen) {
AutodrainedPool pool;
checkIntegrityOnOpen = fileExists(journalFilename);
}
{
MutexLocker locker(m_syncLock);
if (!m_syncDB.open(m_completeDatabasePath)) {
LOG_ERROR("Unable to open icon database at path %s - %s", m_completeDatabasePath.ascii().data(), m_syncDB.lastErrorMsg());
return;
}
}
if (shouldStopThreadActivity()) {
syncThreadMainLoop();
return;
}
#if !LOG_DISABLED
double timeStamp = monotonicallyIncreasingTime();
LOG(IconDatabase, "(THREAD) Open took %.4f seconds", timeStamp - startTime);
#endif
performOpenInitialization();
if (shouldStopThreadActivity()) {
syncThreadMainLoop();
return;
}
#if !LOG_DISABLED
double newStamp = monotonicallyIncreasingTime();
LOG(IconDatabase, "(THREAD) performOpenInitialization() took %.4f seconds, now %.4f seconds from thread start", newStamp - timeStamp, newStamp - startTime);
timeStamp = newStamp;
#endif
LOG(IconDatabase, "(THREAD) Starting iconURL import");
performURLImport();
if (shouldStopThreadActivity()) {
syncThreadMainLoop();
return;
}
#if !LOG_DISABLED
newStamp = monotonicallyIncreasingTime();
LOG(IconDatabase, "(THREAD) performURLImport() took %.4f seconds. Entering main loop %.4f seconds from thread start", newStamp - timeStamp, newStamp - startTime);
#endif
LOG(IconDatabase, "(THREAD) Beginning sync");
syncThreadMainLoop();
}
static int databaseVersionNumber(SQLiteDatabase& db)
{
return SQLiteStatement(db, "SELECT value FROM IconDatabaseInfo WHERE key = 'Version';").getColumnInt(0);
}
static bool isValidDatabase(SQLiteDatabase& db)
{
if (!db.tableExists("IconInfo") || !db.tableExists("IconData") || !db.tableExists("PageURL") || !db.tableExists("IconDatabaseInfo"))
return false;
if (databaseVersionNumber(db) < currentDatabaseVersion) {
LOG(IconDatabase, "DB version is not found or below expected valid version");
return false;
}
return true;
}
static void createDatabaseTables(SQLiteDatabase& db)
{
if (!db.executeCommand("CREATE TABLE PageURL (url TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,iconID INTEGER NOT NULL ON CONFLICT FAIL);")) {
LOG_ERROR("Could not create PageURL table in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand("CREATE INDEX PageURLIndex ON PageURL (url);")) {
LOG_ERROR("Could not create PageURL index in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand("CREATE TABLE IconInfo (iconID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE ON CONFLICT REPLACE, url TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT FAIL, stamp INTEGER);")) {
LOG_ERROR("Could not create IconInfo table in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand("CREATE INDEX IconInfoIndex ON IconInfo (url, iconID);")) {
LOG_ERROR("Could not create PageURL index in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand("CREATE TABLE IconData (iconID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE ON CONFLICT REPLACE, data BLOB);")) {
LOG_ERROR("Could not create IconData table in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand("CREATE INDEX IconDataIndex ON IconData (iconID);")) {
LOG_ERROR("Could not create PageURL index in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand("CREATE TABLE IconDatabaseInfo (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL);")) {
LOG_ERROR("Could not create IconDatabaseInfo table in database (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
if (!db.executeCommand(String("INSERT INTO IconDatabaseInfo VALUES ('Version', ") + String::number(currentDatabaseVersion) + ");")) {
LOG_ERROR("Could not insert icon database version into IconDatabaseInfo table (%i) - %s", db.lastError(), db.lastErrorMsg());
db.close();
return;
}
}
void IconDatabase::performOpenInitialization()
{
ASSERT_ICON_SYNC_THREAD();
if (!isOpen())
return;
if (checkIntegrityOnOpen) {
checkIntegrityOnOpen = false;
if (!checkIntegrity()) {
LOG(IconDatabase, "Integrity check was bad - dumping IconDatabase");
m_syncDB.close();
{
MutexLocker locker(m_syncLock);
deleteFile(m_completeDatabasePath + "-journal");
deleteFile(m_completeDatabasePath);
}
if (!m_syncDB.open(m_completeDatabasePath)) {
LOG_ERROR("Unable to open icon database at path %s - %s", m_completeDatabasePath.ascii().data(), m_syncDB.lastErrorMsg());
return;
}
}
}
int version = databaseVersionNumber(m_syncDB);
if (version > currentDatabaseVersion) {
LOG(IconDatabase, "Database version number %i is greater than our current version number %i - closing the database to prevent overwriting newer versions", version, currentDatabaseVersion);
m_syncDB.close();
m_threadTerminationRequested = true;
return;
}
if (!isValidDatabase(m_syncDB)) {
LOG(IconDatabase, "%s is missing or in an invalid state - reconstructing", m_completeDatabasePath.ascii().data());
m_syncDB.clearAllTables();
createDatabaseTables(m_syncDB);
}
if (!SQLiteStatement(m_syncDB, "PRAGMA cache_size = 200;").executeCommand())
LOG_ERROR("SQLite database could not set cache_size");
if (canExcludeFromBackup() && !wasExcludedFromBackup() && excludeFromBackup(m_completeDatabasePath))
setWasExcludedFromBackup();
}
bool IconDatabase::checkIntegrity()
{
ASSERT_ICON_SYNC_THREAD();
SQLiteStatement integrity(m_syncDB, "PRAGMA integrity_check;");
if (integrity.prepare() != SQLResultOk) {
LOG_ERROR("checkIntegrity failed to execute");
return false;
}
int resultCode = integrity.step();
if (resultCode == SQLResultOk)
return true;
if (resultCode != SQLResultRow)
return false;
int columns = integrity.columnCount();
if (columns != 1) {
LOG_ERROR("Received %i columns performing integrity check, should be 1", columns);
return false;
}
String resultText = integrity.getColumnText(0);
if (resultText == "ok")
return true;
LOG_ERROR("Icon database integrity check failed - \n%s", resultText.ascii().data());
return false;
}
void IconDatabase::performURLImport()
{
ASSERT_ICON_SYNC_THREAD();
# if PLATFORM(GTK)
String importQuery = String::format("SELECT PageURL.url, IconInfo.url, IconInfo.stamp FROM PageURL INNER JOIN IconInfo ON PageURL.iconID=IconInfo.iconID WHERE IconInfo.stamp > %.0f;", floor(currentTime() - notUsedIconExpirationTime));
#else
String importQuery("SELECT PageURL.url, IconInfo.url, IconInfo.stamp FROM PageURL INNER JOIN IconInfo ON PageURL.iconID=IconInfo.iconID;");
#endif
SQLiteStatement query(m_syncDB, importQuery);
if (query.prepare() != SQLResultOk) {
LOG_ERROR("Unable to prepare icon url import query");
return;
}
int result = query.step();
while (result == SQLResultRow) {
AutodrainedPool pool;
String pageURL = query.getColumnText(0);
String iconURL = query.getColumnText(1);
{
MutexLocker locker(m_urlAndIconLock);
PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURL);
if (!pageRecord && databaseCleanupCounter && documentCanHaveIcon(pageURL)) {
pageRecord = new PageURLRecord(pageURL);
m_pageURLToRecordMap.set(pageURL, pageRecord);
}
if (pageRecord) {
IconRecord* currentIcon = pageRecord->iconRecord();
if (!currentIcon || currentIcon->iconURL() != iconURL) {
pageRecord->setIconRecord(getOrCreateIconRecord(iconURL));
currentIcon = pageRecord->iconRecord();
}
currentIcon->setTimestamp(query.getColumnInt(2));
}
}
{
MutexLocker locker(m_pendingReadingLock);
if (m_pageURLsPendingImport.contains(pageURL)) {
dispatchDidImportIconURLForPageURLOnMainThread(pageURL);
m_pageURLsPendingImport.remove(pageURL);
}
}
if (shouldStopThreadActivity()) {
LOG(IconDatabase, "IconDatabase asked to terminate during performURLImport()");
return;
}
result = query.step();
}
if (result != SQLResultDone)
LOG(IconDatabase, "Error reading page->icon url mappings from database");
Vector<String> urls;
{
MutexLocker locker(m_pendingReadingLock);
urls.appendRange(m_pageURLsPendingImport.begin(), m_pageURLsPendingImport.end());
m_pageURLsPendingImport.clear();
m_iconURLImportComplete = true;
}
Vector<String> urlsToNotify;
{
MutexLocker locker(m_urlAndIconLock);
performPendingRetainAndReleaseOperations();
for (unsigned i = 0; i < urls.size(); ++i) {
if (!m_retainedPageURLs.contains(urls[i])) {
PageURLRecord* record = m_pageURLToRecordMap.get(urls[i]);
if (record && !databaseCleanupCounter) {
m_pageURLToRecordMap.remove(urls[i]);
IconRecord* iconRecord = record->iconRecord();
if (iconRecord && iconRecord->hasOneRef()) {
m_iconURLToRecordMap.remove(iconRecord->iconURL());
{
MutexLocker locker(m_pendingReadingLock);
m_pageURLsInterestedInIcons.remove(urls[i]);
m_iconsPendingReading.remove(iconRecord);
}
{
MutexLocker locker(m_pendingSyncLock);
m_iconsPendingSync.set(iconRecord->iconURL(), iconRecord->snapshot(true));
}
}
delete record;
}
} else {
urlsToNotify.append(urls[i]);
}
}
}
LOG(IconDatabase, "Notifying %lu interested page URLs that their icon URL is known due to the import", static_cast<unsigned long>(urlsToNotify.size()));
for (unsigned i = 0; i < urlsToNotify.size(); ++i) {
AutodrainedPool pool;
LOG(IconDatabase, "Notifying icon info known for pageURL %s", urlsToNotify[i].ascii().data());
dispatchDidImportIconURLForPageURLOnMainThread(urlsToNotify[i]);
if (shouldStopThreadActivity())
return;
}
dispatchDidFinishURLImportOnMainThread();
callOnMainThread([this] {
notifyPendingLoadDecisions();
});
}
void IconDatabase::syncThreadMainLoop()
{
ASSERT_ICON_SYNC_THREAD();
m_syncLock.lock();
std::unique_ptr<SuddenTerminationDisabler> disableSuddenTermination = WTF::move(m_disableSuddenTerminationWhileSyncThreadHasWorkToDo);
m_syncThreadHasWorkToDo = false;
while (!m_threadTerminationRequested) {
m_syncLock.unlock();
#if !LOG_DISABLED
double timeStamp = monotonicallyIncreasingTime();
#endif
LOG(IconDatabase, "(THREAD) Main work loop starting");
if (m_removeIconsRequested) {
removeAllIconsOnThread();
m_removeIconsRequested = false;
}
if (m_threadTerminationRequested)
break;
{
MutexLocker locker(m_urlAndIconLock);
performPendingRetainAndReleaseOperations();
}
bool didAnyWork = true;
while (didAnyWork) {
bool didWrite = writeToDatabase();
if (shouldStopThreadActivity())
break;
didAnyWork = readFromDatabase();
if (shouldStopThreadActivity())
break;
static bool prunedUnretainedIcons = false;
if (didWrite && !m_privateBrowsingEnabled && !prunedUnretainedIcons && !databaseCleanupCounter) {
#if !LOG_DISABLED
double time = monotonicallyIncreasingTime();
#endif
LOG(IconDatabase, "(THREAD) Starting pruneUnretainedIcons()");
pruneUnretainedIcons();
LOG(IconDatabase, "(THREAD) pruneUnretainedIcons() took %.4f seconds", monotonicallyIncreasingTime() - time);
prunedUnretainedIcons = true;
}
didAnyWork = didAnyWork || didWrite;
if (shouldStopThreadActivity())
break;
}
#if !LOG_DISABLED
double newstamp = monotonicallyIncreasingTime();
LOG(IconDatabase, "(THREAD) Main work loop ran for %.4f seconds, %s requested to terminate", newstamp - timeStamp, shouldStopThreadActivity() ? "was" : "was not");
#endif
m_syncLock.lock();
if (shouldStopThreadActivity())
continue;
disableSuddenTermination.reset();
while (!m_syncThreadHasWorkToDo)
m_syncCondition.wait(m_syncLock);
m_syncThreadHasWorkToDo = false;
ASSERT(m_disableSuddenTerminationWhileSyncThreadHasWorkToDo);
disableSuddenTermination = WTF::move(m_disableSuddenTerminationWhileSyncThreadHasWorkToDo);
}
m_syncLock.unlock();
cleanupSyncThread();
}
void IconDatabase::performPendingRetainAndReleaseOperations()
{
ASSERT(!m_urlAndIconLock.tryLock());
HashCountedSet<String> toRetain;
HashCountedSet<String> toRelease;
{
MutexLocker pendingWorkLocker(m_urlsToRetainOrReleaseLock);
if (!m_retainOrReleaseIconRequested)
return;
toRetain.swap(m_urlsToRetain);
toRelease.swap(m_urlsToRelease);
m_retainOrReleaseIconRequested = false;
}
for (HashCountedSet<String>::const_iterator it = toRetain.begin(), end = toRetain.end(); it != end; ++it) {
ASSERT(!it->key.impl() || it->key.impl()->hasOneRef());
performRetainIconForPageURL(it->key, it->value);
}
for (HashCountedSet<String>::const_iterator it = toRelease.begin(), end = toRelease.end(); it != end; ++it) {
ASSERT(!it->key.impl() || it->key.impl()->hasOneRef());
performReleaseIconForPageURL(it->key, it->value);
}
}
bool IconDatabase::readFromDatabase()
{
ASSERT_ICON_SYNC_THREAD();
#if !LOG_DISABLED
double timeStamp = monotonicallyIncreasingTime();
#endif
bool didAnyWork = false;
Vector<IconRecord*> icons;
{
MutexLocker locker(m_pendingReadingLock);
icons.appendRange(m_iconsPendingReading.begin(), m_iconsPendingReading.end());
}
HashSet<String> urlsToNotify;
for (unsigned i = 0; i < icons.size(); ++i) {
didAnyWork = true;
RefPtr<SharedBuffer> imageData = getImageDataForIconURLFromSQLDatabase(icons[i]->iconURL());
{
MutexLocker urlLocker(m_urlAndIconLock);
{
MutexLocker readLocker(m_pendingReadingLock);
if (m_iconsPendingReading.contains(icons[i])) {
icons[i]->setImageData(imageData.release());
m_iconsPendingReading.remove(icons[i]);
const HashSet<String>* outerHash;
const HashSet<String>* innerHash;
if (icons[i]->retainingPageURLs().size() > m_pageURLsInterestedInIcons.size()) {
outerHash = &m_pageURLsInterestedInIcons;
innerHash = &(icons[i]->retainingPageURLs());
} else {
innerHash = &m_pageURLsInterestedInIcons;
outerHash = &(icons[i]->retainingPageURLs());
}
HashSet<String>::const_iterator iter = outerHash->begin();
HashSet<String>::const_iterator end = outerHash->end();
for (; iter != end; ++iter) {
if (innerHash->contains(*iter)) {
LOG(IconDatabase, "%s is interested in the icon we just read. Adding it to the notification list and removing it from the interested set", urlForLogging(*iter).ascii().data());
urlsToNotify.add(*iter);
}
if (urlsToNotify.size() == m_pageURLsInterestedInIcons.size())
break;
}
if (urlsToNotify.size() == m_pageURLsInterestedInIcons.size())
m_pageURLsInterestedInIcons.clear();
else {
iter = urlsToNotify.begin();
end = urlsToNotify.end();
for (; iter != end; ++iter)
m_pageURLsInterestedInIcons.remove(*iter);
}
}
}
}
if (shouldStopThreadActivity())
return didAnyWork;
for (HashSet<String>::const_iterator it = urlsToNotify.begin(), end = urlsToNotify.end(); it != end; ++it) {
AutodrainedPool pool;
LOG(IconDatabase, "Notifying icon received for pageURL %s", urlForLogging(*it).ascii().data());
dispatchDidImportIconDataForPageURLOnMainThread(*it);
if (shouldStopThreadActivity())
return didAnyWork;
}
LOG(IconDatabase, "Done notifying %i pageURLs who just received their icons", urlsToNotify.size());
urlsToNotify.clear();
if (shouldStopThreadActivity())
return didAnyWork;
}
LOG(IconDatabase, "Reading from database took %.4f seconds", monotonicallyIncreasingTime() - timeStamp);
return didAnyWork;
}
bool IconDatabase::writeToDatabase()
{
ASSERT_ICON_SYNC_THREAD();
#if !LOG_DISABLED
double timeStamp = monotonicallyIncreasingTime();
#endif
bool didAnyWork = false;
{
MutexLocker locker(m_urlAndIconLock);
Vector<IconSnapshot> iconSnapshots;
Vector<PageURLSnapshot> pageSnapshots;
{
MutexLocker locker(m_pendingSyncLock);
iconSnapshots.appendRange(m_iconsPendingSync.begin().values(), m_iconsPendingSync.end().values());
m_iconsPendingSync.clear();
pageSnapshots.appendRange(m_pageURLsPendingSync.begin().values(), m_pageURLsPendingSync.end().values());
m_pageURLsPendingSync.clear();
}
if (iconSnapshots.size() || pageSnapshots.size())
didAnyWork = true;
SQLiteTransaction syncTransaction(m_syncDB);
syncTransaction.begin();
for (unsigned i = 0; i < iconSnapshots.size(); ++i) {
writeIconSnapshotToSQLDatabase(iconSnapshots[i]);
LOG(IconDatabase, "Wrote IconRecord for IconURL %s with timeStamp of %i to the DB", urlForLogging(iconSnapshots[i].iconURL()).ascii().data(), iconSnapshots[i].timestamp());
}
for (unsigned i = 0; i < pageSnapshots.size(); ++i) {
if (pageSnapshots[i].iconURL().isEmpty())
removePageURLFromSQLDatabase(pageSnapshots[i].pageURL());
else
setIconURLForPageURLInSQLDatabase(pageSnapshots[i].iconURL(), pageSnapshots[i].pageURL());
LOG(IconDatabase, "Committed IconURL for PageURL %s to database", urlForLogging(pageSnapshots[i].pageURL()).ascii().data());
}
syncTransaction.commit();
}
if (didAnyWork)
checkForDanglingPageURLs(false);
LOG(IconDatabase, "Updating the database took %.4f seconds", monotonicallyIncreasingTime() - timeStamp);
return didAnyWork;
}
void IconDatabase::pruneUnretainedIcons()
{
ASSERT_ICON_SYNC_THREAD();
if (!isOpen())
return;
ASSERT(!m_initialPruningComplete);
ASSERT(m_iconURLImportComplete);
Vector<int64_t> pageIDsToDelete;
SQLiteStatement pageSQL(m_syncDB, "SELECT rowid, url FROM PageURL;");
pageSQL.prepare();
int result;
while ((result = pageSQL.step()) == SQLResultRow) {
MutexLocker locker(m_urlAndIconLock);
if (!m_pageURLToRecordMap.contains(pageSQL.getColumnText(1)))
pageIDsToDelete.append(pageSQL.getColumnInt64(0));
}
if (result != SQLResultDone)
LOG_ERROR("Error reading PageURL table from on-disk DB");
pageSQL.finalize();
size_t numToDelete = pageIDsToDelete.size();
if (numToDelete) {
SQLiteTransaction pruningTransaction(m_syncDB);
pruningTransaction.begin();
SQLiteStatement pageDeleteSQL(m_syncDB, "DELETE FROM PageURL WHERE rowid = (?);");
pageDeleteSQL.prepare();
for (size_t i = 0; i < numToDelete; ++i) {
LOG(IconDatabase, "Pruning page with rowid %lli from disk", static_cast<long long>(pageIDsToDelete[i]));
pageDeleteSQL.bindInt64(1, pageIDsToDelete[i]);
int result = pageDeleteSQL.step();
if (result != SQLResultDone)
LOG_ERROR("Unabled to delete page with id %lli from disk", static_cast<long long>(pageIDsToDelete[i]));
pageDeleteSQL.reset();
if (shouldStopThreadActivity()) {
pruningTransaction.commit();
return;
}
}
pruningTransaction.commit();
pageDeleteSQL.finalize();
}
SQLiteTransaction pruningTransaction(m_syncDB);
pruningTransaction.begin();
if (!m_syncDB.executeCommand("DELETE FROM IconData WHERE iconID NOT IN (SELECT iconID FROM PageURL);"))
LOG_ERROR("Failed to execute SQL to prune unretained icons from the on-disk IconData table");
if (!m_syncDB.executeCommand("DELETE FROM IconInfo WHERE iconID NOT IN (SELECT iconID FROM PageURL);"))
LOG_ERROR("Failed to execute SQL to prune unretained icons from the on-disk IconInfo table");
pruningTransaction.commit();
checkForDanglingPageURLs(true);
m_initialPruningComplete = true;
}
void IconDatabase::checkForDanglingPageURLs(bool pruneIfFound)
{
ASSERT_ICON_SYNC_THREAD();
#ifndef NDEBUG
static bool danglersFound = true;
#else
static bool danglersFound = false;
#endif
if ((pruneIfFound || !danglersFound) && SQLiteStatement(m_syncDB, "SELECT url FROM PageURL WHERE PageURL.iconID NOT IN (SELECT iconID FROM IconInfo) LIMIT 1;").returnsAtLeastOneResult()) {
danglersFound = true;
LOG(IconDatabase, "Dangling PageURL entries found");
if (pruneIfFound && !m_syncDB.executeCommand("DELETE FROM PageURL WHERE iconID NOT IN (SELECT iconID FROM IconInfo);"))
LOG(IconDatabase, "Unable to prune dangling PageURLs");
}
}
void IconDatabase::removeAllIconsOnThread()
{
ASSERT_ICON_SYNC_THREAD();
LOG(IconDatabase, "Removing all icons on the sync thread");
deleteAllPreparedStatements();
m_syncDB.clearAllTables();
m_syncDB.runVacuumCommand();
createDatabaseTables(m_syncDB);
LOG(IconDatabase, "Dispatching notification that we removed all icons");
dispatchDidRemoveAllIconsOnMainThread();
}
void IconDatabase::deleteAllPreparedStatements()
{
ASSERT_ICON_SYNC_THREAD();
m_setIconIDForPageURLStatement.clear();
m_removePageURLStatement.clear();
m_getIconIDForIconURLStatement.clear();
m_getImageDataForIconURLStatement.clear();
m_addIconToIconInfoStatement.clear();
m_addIconToIconDataStatement.clear();
m_getImageDataStatement.clear();
m_deletePageURLsForIconURLStatement.clear();
m_deleteIconFromIconInfoStatement.clear();
m_deleteIconFromIconDataStatement.clear();
m_updateIconInfoStatement.clear();
m_updateIconDataStatement.clear();
m_setIconInfoStatement.clear();
m_setIconDataStatement.clear();
}
void* IconDatabase::cleanupSyncThread()
{
ASSERT_ICON_SYNC_THREAD();
#if !LOG_DISABLED
double timeStamp = monotonicallyIncreasingTime();
#endif
if (m_removeIconsRequested)
removeAllIconsOnThread();
LOG(IconDatabase, "(THREAD) Doing final writeout and closure of sync thread");
writeToDatabase();
MutexLocker locker(m_syncLock);
m_databaseDirectory = String();
m_completeDatabasePath = String();
deleteAllPreparedStatements();
m_syncDB.close();
#if !LOG_DISABLED
LOG(IconDatabase, "(THREAD) Final closure took %.4f seconds", monotonicallyIncreasingTime() - timeStamp);
#endif
m_syncThreadRunning = false;
return 0;
}
inline void readySQLiteStatement(OwnPtr<SQLiteStatement>& statement, SQLiteDatabase& db, const String& str)
{
if (statement && (statement->database() != &db || statement->isExpired())) {
if (statement->isExpired())
LOG(IconDatabase, "SQLiteStatement associated with %s is expired", str.ascii().data());
statement.clear();
}
if (!statement) {
statement = adoptPtr(new SQLiteStatement(db, str));
if (statement->prepare() != SQLResultOk)
LOG_ERROR("Preparing statement %s failed", str.ascii().data());
}
}
void IconDatabase::setIconURLForPageURLInSQLDatabase(const String& iconURL, const String& pageURL)
{
ASSERT_ICON_SYNC_THREAD();
int64_t iconID = getIconIDForIconURLFromSQLDatabase(iconURL);
if (!iconID)
iconID = addIconURLToSQLDatabase(iconURL);
if (!iconID) {
LOG_ERROR("Failed to establish an ID for iconURL %s", urlForLogging(iconURL).ascii().data());
ASSERT_NOT_REACHED();
return;
}
setIconIDForPageURLInSQLDatabase(iconID, pageURL);
}
void IconDatabase::setIconIDForPageURLInSQLDatabase(int64_t iconID, const String& pageURL)
{
ASSERT_ICON_SYNC_THREAD();
readySQLiteStatement(m_setIconIDForPageURLStatement, m_syncDB, "INSERT INTO PageURL (url, iconID) VALUES ((?), ?);");
m_setIconIDForPageURLStatement->bindText(1, pageURL);
m_setIconIDForPageURLStatement->bindInt64(2, iconID);
int result = m_setIconIDForPageURLStatement->step();
if (result != SQLResultDone) {
ASSERT_NOT_REACHED();
LOG_ERROR("setIconIDForPageURLQuery failed for url %s", urlForLogging(pageURL).ascii().data());
}
m_setIconIDForPageURLStatement->reset();
}
void IconDatabase::removePageURLFromSQLDatabase(const String& pageURL)
{
ASSERT_ICON_SYNC_THREAD();
readySQLiteStatement(m_removePageURLStatement, m_syncDB, "DELETE FROM PageURL WHERE url = (?);");
m_removePageURLStatement->bindText(1, pageURL);
if (m_removePageURLStatement->step() != SQLResultDone)
LOG_ERROR("removePageURLFromSQLDatabase failed for url %s", urlForLogging(pageURL).ascii().data());
m_removePageURLStatement->reset();
}
int64_t IconDatabase::getIconIDForIconURLFromSQLDatabase(const String& iconURL)
{
ASSERT_ICON_SYNC_THREAD();
readySQLiteStatement(m_getIconIDForIconURLStatement, m_syncDB, "SELECT IconInfo.iconID FROM IconInfo WHERE IconInfo.url = (?);");
m_getIconIDForIconURLStatement->bindText(1, iconURL);
int64_t result = m_getIconIDForIconURLStatement->step();
if (result == SQLResultRow)
result = m_getIconIDForIconURLStatement->getColumnInt64(0);
else {
if (result != SQLResultDone)
LOG_ERROR("getIconIDForIconURLFromSQLDatabase failed for url %s", urlForLogging(iconURL).ascii().data());
result = 0;
}
m_getIconIDForIconURLStatement->reset();
return result;
}
int64_t IconDatabase::addIconURLToSQLDatabase(const String& iconURL)
{
ASSERT_ICON_SYNC_THREAD();
readySQLiteStatement(m_addIconToIconInfoStatement, m_syncDB, "INSERT INTO IconInfo (url, stamp) VALUES (?, 0);");
m_addIconToIconInfoStatement->bindText(1, iconURL);
int result = m_addIconToIconInfoStatement->step();
m_addIconToIconInfoStatement->reset();
if (result != SQLResultDone) {
LOG_ERROR("addIconURLToSQLDatabase failed to insert %s into IconInfo", urlForLogging(iconURL).ascii().data());
return 0;
}
int64_t iconID = m_syncDB.lastInsertRowID();
readySQLiteStatement(m_addIconToIconDataStatement, m_syncDB, "INSERT INTO IconData (iconID, data) VALUES (?, ?);");
m_addIconToIconDataStatement->bindInt64(1, iconID);
result = m_addIconToIconDataStatement->step();
m_addIconToIconDataStatement->reset();
if (result != SQLResultDone) {
LOG_ERROR("addIconURLToSQLDatabase failed to insert %s into IconData", urlForLogging(iconURL).ascii().data());
return 0;
}
return iconID;
}
PassRefPtr<SharedBuffer> IconDatabase::getImageDataForIconURLFromSQLDatabase(const String& iconURL)
{
ASSERT_ICON_SYNC_THREAD();
RefPtr<SharedBuffer> imageData;
readySQLiteStatement(m_getImageDataForIconURLStatement, m_syncDB, "SELECT IconData.data FROM IconData WHERE IconData.iconID IN (SELECT iconID FROM IconInfo WHERE IconInfo.url = (?));");
m_getImageDataForIconURLStatement->bindText(1, iconURL);
int result = m_getImageDataForIconURLStatement->step();
if (result == SQLResultRow) {
Vector<char> data;
m_getImageDataForIconURLStatement->getColumnBlobAsVector(0, data);
imageData = SharedBuffer::create(data.data(), data.size());
} else if (result != SQLResultDone)
LOG_ERROR("getImageDataForIconURLFromSQLDatabase failed for url %s", urlForLogging(iconURL).ascii().data());
m_getImageDataForIconURLStatement->reset();
return imageData.release();
}
void IconDatabase::removeIconFromSQLDatabase(const String& iconURL)
{
ASSERT_ICON_SYNC_THREAD();
if (iconURL.isEmpty())
return;
int64_t iconID = getIconIDForIconURLFromSQLDatabase(iconURL);
if (!iconID)
return;
readySQLiteStatement(m_deletePageURLsForIconURLStatement, m_syncDB, "DELETE FROM PageURL WHERE PageURL.iconID = (?);");
m_deletePageURLsForIconURLStatement->bindInt64(1, iconID);
if (m_deletePageURLsForIconURLStatement->step() != SQLResultDone)
LOG_ERROR("m_deletePageURLsForIconURLStatement failed for url %s", urlForLogging(iconURL).ascii().data());
readySQLiteStatement(m_deleteIconFromIconInfoStatement, m_syncDB, "DELETE FROM IconInfo WHERE IconInfo.iconID = (?);");
m_deleteIconFromIconInfoStatement->bindInt64(1, iconID);
if (m_deleteIconFromIconInfoStatement->step() != SQLResultDone)
LOG_ERROR("m_deleteIconFromIconInfoStatement failed for url %s", urlForLogging(iconURL).ascii().data());
readySQLiteStatement(m_deleteIconFromIconDataStatement, m_syncDB, "DELETE FROM IconData WHERE IconData.iconID = (?);");
m_deleteIconFromIconDataStatement->bindInt64(1, iconID);
if (m_deleteIconFromIconDataStatement->step() != SQLResultDone)
LOG_ERROR("m_deleteIconFromIconDataStatement failed for url %s", urlForLogging(iconURL).ascii().data());
m_deletePageURLsForIconURLStatement->reset();
m_deleteIconFromIconInfoStatement->reset();
m_deleteIconFromIconDataStatement->reset();
}
void IconDatabase::writeIconSnapshotToSQLDatabase(const IconSnapshot& snapshot)
{
ASSERT_ICON_SYNC_THREAD();
if (snapshot.iconURL().isEmpty())
return;
if (!snapshot.timestamp() && !snapshot.data()) {
LOG(IconDatabase, "Removing %s from on-disk database", urlForLogging(snapshot.iconURL()).ascii().data());
removeIconFromSQLDatabase(snapshot.iconURL());
return;
}
int64_t iconID = getIconIDForIconURLFromSQLDatabase(snapshot.iconURL());
if (iconID) {
readySQLiteStatement(m_updateIconInfoStatement, m_syncDB, "UPDATE IconInfo SET stamp = ?, url = ? WHERE iconID = ?;");
m_updateIconInfoStatement->bindInt64(1, snapshot.timestamp());
m_updateIconInfoStatement->bindText(2, snapshot.iconURL());
m_updateIconInfoStatement->bindInt64(3, iconID);
if (m_updateIconInfoStatement->step() != SQLResultDone)
LOG_ERROR("Failed to update icon info for url %s", urlForLogging(snapshot.iconURL()).ascii().data());
m_updateIconInfoStatement->reset();
readySQLiteStatement(m_updateIconDataStatement, m_syncDB, "UPDATE IconData SET data = ? WHERE iconID = ?;");
m_updateIconDataStatement->bindInt64(2, iconID);
if (snapshot.data() && snapshot.data()->size())
m_updateIconDataStatement->bindBlob(1, snapshot.data()->data(), snapshot.data()->size());
else
m_updateIconDataStatement->bindNull(1);
if (m_updateIconDataStatement->step() != SQLResultDone)
LOG_ERROR("Failed to update icon data for url %s", urlForLogging(snapshot.iconURL()).ascii().data());
m_updateIconDataStatement->reset();
} else {
readySQLiteStatement(m_setIconInfoStatement, m_syncDB, "INSERT INTO IconInfo (url,stamp) VALUES (?, ?);");
m_setIconInfoStatement->bindText(1, snapshot.iconURL());
m_setIconInfoStatement->bindInt64(2, snapshot.timestamp());
if (m_setIconInfoStatement->step() != SQLResultDone)
LOG_ERROR("Failed to set icon info for url %s", urlForLogging(snapshot.iconURL()).ascii().data());
m_setIconInfoStatement->reset();
int64_t iconID = m_syncDB.lastInsertRowID();
readySQLiteStatement(m_setIconDataStatement, m_syncDB, "INSERT INTO IconData (iconID, data) VALUES (?, ?);");
m_setIconDataStatement->bindInt64(1, iconID);
if (snapshot.data() && snapshot.data()->size())
m_setIconDataStatement->bindBlob(2, snapshot.data()->data(), snapshot.data()->size());
else
m_setIconDataStatement->bindNull(2);
if (m_setIconDataStatement->step() != SQLResultDone)
LOG_ERROR("Failed to set icon data for url %s", urlForLogging(snapshot.iconURL()).ascii().data());
m_setIconDataStatement->reset();
}
}
bool IconDatabase::wasExcludedFromBackup()
{
ASSERT_ICON_SYNC_THREAD();
return SQLiteStatement(m_syncDB, "SELECT value FROM IconDatabaseInfo WHERE key = 'ExcludedFromBackup';").getColumnInt(0);
}
void IconDatabase::setWasExcludedFromBackup()
{
ASSERT_ICON_SYNC_THREAD();
SQLiteStatement(m_syncDB, "INSERT INTO IconDatabaseInfo (key, value) VALUES ('ExcludedFromBackup', 1)").executeCommand();
}
void IconDatabase::checkClosedAfterMainThreadCallback()
{
ASSERT_NOT_SYNC_THREAD();
if (--m_mainThreadCallbackCount)
return;
if (isOpenBesidesMainThreadCallbacks())
return;
if (m_client)
m_client->didClose();
}
void IconDatabase::dispatchDidImportIconURLForPageURLOnMainThread(const String& pageURL)
{
ASSERT_ICON_SYNC_THREAD();
++m_mainThreadCallbackCount;
String pageURLCopy = pageURL.isolatedCopy();
callOnMainThread([this, pageURLCopy] {
if (m_client)
m_client->didImportIconURLForPageURL(pageURLCopy);
checkClosedAfterMainThreadCallback();
});
}
void IconDatabase::dispatchDidImportIconDataForPageURLOnMainThread(const String& pageURL)
{
ASSERT_ICON_SYNC_THREAD();
++m_mainThreadCallbackCount;
String pageURLCopy = pageURL.isolatedCopy();
callOnMainThread([this, pageURLCopy] {
if (m_client)
m_client->didImportIconDataForPageURL(pageURLCopy);
checkClosedAfterMainThreadCallback();
});
}
void IconDatabase::dispatchDidRemoveAllIconsOnMainThread()
{
ASSERT_ICON_SYNC_THREAD();
++m_mainThreadCallbackCount;
callOnMainThread([this] {
if (m_client)
m_client->didRemoveAllIcons();
checkClosedAfterMainThreadCallback();
});
}
void IconDatabase::dispatchDidFinishURLImportOnMainThread()
{
ASSERT_ICON_SYNC_THREAD();
++m_mainThreadCallbackCount;
callOnMainThread([this] {
if (m_client)
m_client->didFinishURLImport();
checkClosedAfterMainThreadCallback();
});
}
}
#endif // ENABLE(ICONDATABASE)