📄 icondatabase.cpp
字号:
String IconDatabase::iconURLForPageURL(const String& pageURLOriginal){ ASSERT_NOT_SYNC_THREAD(); // Cannot do anything with pageURLOriginal that would end up storing it without deep copying first // Also, in the case we have a real answer for the caller, we must deep copy that as well if (!isOpen() || pageURLOriginal.isEmpty()) return String(); MutexLocker locker(m_urlAndIconLock); PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURLOriginal); if (!pageRecord) pageRecord = getOrCreatePageURLRecord(pageURLOriginal.copy()); // If pageRecord is NULL, one of two things is true - // 1 - The initial url import is incomplete and this pageURL has already been marked to be notified once it is complete if an iconURL exists // 2 - The initial url import IS complete and this pageURL has no icon if (!pageRecord) return String(); // Possible the pageRecord is around because it's a retained pageURL with no iconURL, so we have to check return pageRecord->iconRecord() ? pageRecord->iconRecord()->iconURL().copy() : String();}#ifdef CAN_THEME_URL_ICONstatic inline void loadDefaultIconRecord(IconRecord* defaultIconRecord){ defaultIconRecord->loadImageFromResource("urlIcon");}#elsestatic inline void loadDefaultIconRecord(IconRecord* defaultIconRecord){ static const unsigned char defaultIconData[] = { 0x4D, 0x4D, 0x00, 0x2A, 0x00, 0x00, 0x03, 0x32, 0x80, 0x00, 0x20, 0x50, 0x38, 0x24, 0x16, 0x0D, 0x07, 0x84, 0x42, 0x61, 0x50, 0xB8, 0x64, 0x08, 0x18, 0x0D, 0x0A, 0x0B, 0x84, 0xA2, 0xA1, 0xE2, 0x08, 0x5E, 0x39, 0x28, 0xAF, 0x48, 0x24, 0xD3, 0x53, 0x9A, 0x37, 0x1D, 0x18, 0x0E, 0x8A, 0x4B, 0xD1, 0x38, 0xB0, 0x7C, 0x82, 0x07, 0x03, 0x82, 0xA2, 0xE8, 0x6C, 0x2C, 0x03, 0x2F, 0x02, 0x82, 0x41, 0xA1, 0xE2, 0xF8, 0xC8, 0x84, 0x68, 0x6D, 0x1C, 0x11, 0x0A, 0xB7, 0xFA, 0x91, 0x6E, 0xD1, 0x7F, 0xAF, 0x9A, 0x4E, 0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, 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 }; DEFINE_STATIC_LOCAL(RefPtr<SharedBuffer>, defaultIconBuffer, (SharedBuffer::create(defaultIconData, sizeof(defaultIconData)))); defaultIconRecord->setImageData(defaultIconBuffer);}#endifImage* 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& pageURLOriginal){ ASSERT_NOT_SYNC_THREAD(); // Cannot do anything with pageURLOriginal that would end up storing it without deep copying first if (!isEnabled() || pageURLOriginal.isEmpty()) return; MutexLocker locker(m_urlAndIconLock); PageURLRecord* record = m_pageURLToRecordMap.get(pageURLOriginal); String pageURL; if (!record) { pageURL = pageURLOriginal.copy(); record = new PageURLRecord(pageURL); m_pageURLToRecordMap.set(pageURL, record); } if (!record->retain()) { if (pageURL.isNull()) pageURL = pageURLOriginal.copy(); // This page just had its retain count bumped from 0 to 1 - Record that fact m_retainedPageURLs.add(pageURL); // If we read the iconURLs yet, we want to avoid any pageURL->iconURL lookups and the pageURLsPendingDeletion is moot, // so we bail here and skip those steps if (!m_iconURLImportComplete) return; MutexLocker locker(m_pendingSyncLock); // If this pageURL waiting to be sync'ed, update the sync record // This saves us in the case where a page was ready to be deleted from the database but was just retained - so theres no need to delete it! 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& pageURLOriginal){ ASSERT_NOT_SYNC_THREAD(); // Cannot do anything with pageURLOriginal that would end up storing it without deep copying first if (!isEnabled() || pageURLOriginal.isEmpty()) return; MutexLocker locker(m_urlAndIconLock); // Check if this pageURL is actually retained if (!m_retainedPageURLs.contains(pageURLOriginal)) { LOG_ERROR("Attempting to release icon for URL %s which is not retained", urlForLogging(pageURLOriginal).ascii().data()); return; } // Get its retain count - if it's retained, we'd better have a PageURLRecord for it 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 it still has a positive retain count, store the new count and bail if (pageRecord->release()) return; // This pageRecord has now been fully released. Do the appropriate cleanup LOG(IconDatabase, "No more retainers for PageURL %s", urlForLogging(pageURLOriginal).ascii().data()); m_pageURLToRecordMap.remove(pageURLOriginal); m_retainedPageURLs.remove(pageURLOriginal); // Grab the iconRecord for later use (and do a sanity check on it for kicks) IconRecord* iconRecord = pageRecord->iconRecord(); ASSERT(!iconRecord || (iconRecord && m_iconURLToRecordMap.get(iconRecord->iconURL()) == iconRecord)); { MutexLocker locker(m_pendingReadingLock); // Since this pageURL is going away, there's no reason anyone would ever be interested in its read results if (!m_iconURLImportComplete) m_pageURLsPendingImport.remove(pageURLOriginal); m_pageURLsInterestedInIcons.remove(pageURLOriginal); // If this icon is down to it's last retainer, we don't care about reading it in from disk anymore if (iconRecord && iconRecord->hasOneRef()) { m_iconURLToRecordMap.remove(iconRecord->iconURL()); m_iconsPendingReading.remove(iconRecord); } } // Mark stuff for deletion from the database only if we're not in private browsing if (!m_privateBrowsingEnabled) { MutexLocker locker(m_pendingSyncLock); m_pageURLsPendingSync.set(pageURLOriginal.copy(), pageRecord->snapshot(true)); // If this page is the last page to refer to a particular IconRecord, that IconRecord needs to // be marked for deletion if (iconRecord && iconRecord->hasOneRef()) m_iconsPendingSync.set(iconRecord->iconURL(), iconRecord->snapshot(true)); } delete pageRecord; if (isOpen()) scheduleOrDeferSyncTimer();}void IconDatabase::setIconDataForIconURL(PassRefPtr<SharedBuffer> dataOriginal, const String& iconURLOriginal){ ASSERT_NOT_SYNC_THREAD(); // Cannot do anything with dataOriginal or iconURLOriginal that would end up storing them without deep copying first if (!isOpen() || iconURLOriginal.isEmpty()) return; RefPtr<SharedBuffer> data = dataOriginal ? dataOriginal->copy() : 0; String iconURL = iconURLOriginal.copy(); Vector<String> pageURLs; { MutexLocker locker(m_urlAndIconLock); // If this icon was pending a read, remove it from that set because this new data should override what is on disk RefPtr<IconRecord> icon = m_iconURLToRecordMap.get(iconURL); if (icon) { MutexLocker locker(m_pendingReadingLock); m_iconsPendingReading.remove(icon.get()); } else icon = getOrCreateIconRecord(iconURL); // Update the data and set the time stamp icon->setImageData(data); icon->setTimestamp((int)currentTime()); // Copy the current retaining pageURLs - if any - to notify them of the change pageURLs.appendRange(icon->retainingPageURLs().begin(), icon->retainingPageURLs().end()); // Mark the IconRecord as requiring an update to the database only if private browsing is disabled 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()); } } // Send notification out regarding all PageURLs that retain this icon // But not if we're on the sync thread because that implies this mapping // comes from the initial import which we don't want notifications for if (!IS_ICON_SYNC_THREAD()) { // Start the timer to commit this change - or further delay the timer if it was already started scheduleOrDeferSyncTimer(); // Informal testing shows that draining the autorelease pool every 25 iterations is about as low as we can go // before performance starts to drop off, but we don't want to increase this number because then accumulated memory usage will go up AutodrainedPool pool(25); for (unsigned i = 0; i < pageURLs.size(); ++i) { LOG(IconDatabase, "Dispatching notification that retaining pageURL %s has a new icon", urlForLogging(pageURLs[i]).ascii().data()); m_client->dispatchDidAddIconForPageURL(pageURLs[i]); pool.cycle(); } }}void IconDatabase::setIconURLForPageURL(const String& iconURLOriginal, const String& pageURLOriginal){ ASSERT_NOT_SYNC_THREAD(); // Cannot do anything with iconURLOriginal or pageURLOriginal that would end up storing them without deep copying first ASSERT(!iconURLOriginal.isEmpty()); if (!isOpen() || pageURLOriginal.isEmpty()) return; String iconURL, pageURL; { MutexLocker locker(m_urlAndIconLock); PageURLRecord* pageRecord = m_pageURLToRecordMap.get(pageURLOriginal); // If the urls already map to each other, bail. // This happens surprisingly often, and seems to cream iBench performance if (pageRecord && pageRecord->iconRecord() && pageRecord->iconRecord()->iconURL() == iconURLOriginal) return; pageURL = pageURLOriginal.copy(); iconURL = iconURLOriginal.copy(); if (!pageRecord) { pageRecord = new PageURLRecord(pageURL); m_pageURLToRecordMap.set(pageURL, pageRecord); } RefPtr<IconRecord> iconRecord = pageRecord->iconRecord(); // Otherwise, set the new icon record for this page pageRecord->setIconRecord(getOrCreateIconRecord(iconURL)); // If the current icon has only a single ref left, it is about to get wiped out. // Remove it from the in-memory records and don't bother reading it in from disk anymore 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());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -