diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/loader/icon/IconDatabase.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/loader/icon/IconDatabase.h')
-rw-r--r-- | Source/WebCore/loader/icon/IconDatabase.h | 187 |
1 files changed, 87 insertions, 100 deletions
diff --git a/Source/WebCore/loader/icon/IconDatabase.h b/Source/WebCore/loader/icon/IconDatabase.h index 04db323a7..061af4a12 100644 --- a/Source/WebCore/loader/icon/IconDatabase.h +++ b/Source/WebCore/loader/icon/IconDatabase.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008, 2009, 2014 Apple Inc. All rights reserved. * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) * * Redistribution and use in source and binary forms, with or without @@ -11,10 +11,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -24,113 +24,101 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef IconDatabase_h -#define IconDatabase_h +#pragma once #include "IconDatabaseBase.h" -#include "Timer.h" -#include <wtf/HashCountedSet.h> -#include <wtf/HashMap.h> -#include <wtf/HashSet.h> -#include <wtf/Noncopyable.h> -#include <wtf/OwnPtr.h> -#include <wtf/PassOwnPtr.h> -#include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> #if ENABLE(ICONDATABASE) #include "SQLiteDatabase.h" -#include <wtf/Threading.h> -#endif // ENABLE(ICONDATABASE) +#include "Timer.h" +#include <wtf/Condition.h> +#include <wtf/HashCountedSet.h> +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#endif namespace WebCore { -class DocumentLoader; -class Image; -class IntSize; -class IconDatabaseClient; -class IconRecord; -class IconSnapshot; -class URL; -class PageURLRecord; -class PageURLSnapshot; -class SharedBuffer; -class SuddenTerminationDisabler; +#if !ENABLE(ICONDATABASE) -#if ENABLE(ICONDATABASE) -class SQLTransaction; -#endif +// Dummy version of IconDatabase that does nothing. +class IconDatabase final : public IconDatabaseBase { + WTF_MAKE_FAST_ALLOCATED; -#if !ENABLE(ICONDATABASE) -// For builds with IconDatabase disabled, they'll just use a default derivation of IconDatabaseBase. Which does nothing. -class IconDatabase : public IconDatabaseBase { public: - static PassOwnPtr<IconDatabase> create() { return adoptPtr(new IconDatabase); } static void delayDatabaseCleanup() { } static void allowDatabaseCleanup() { } static void checkIntegrityBeforeOpening() { } - static String defaultDatabaseFilename() { return "WebpageIcons.db"; } + + // FIXME: Is it really helpful to return a filename here rather than just the null string? + static String defaultDatabaseFilename() { return ASCIILiteral("WebpageIcons.db"); } }; -#else -class IconDatabase : public IconDatabaseBase { +#else + +class IconRecord; +class IconSnapshot; +class PageURLRecord; +class PageURLSnapshot; +class SuddenTerminationDisabler; + +class IconDatabase final : public IconDatabaseBase { WTF_MAKE_FAST_ALLOCATED; // *** Main Thread Only *** public: - static PassOwnPtr<IconDatabase> create() { return adoptPtr(new IconDatabase); } + WEBCORE_EXPORT IconDatabase(); ~IconDatabase(); - virtual void setClient(IconDatabaseClient*); + WEBCORE_EXPORT void setClient(IconDatabaseClient*) final; - virtual bool open(const String& directory, const String& filename); - virtual void close(); + WEBCORE_EXPORT bool open(const String& directory, const String& filename) final; + WEBCORE_EXPORT void close() final; - virtual void removeAllIcons(); + WEBCORE_EXPORT void removeAllIcons() final; void readIconForPageURLFromDisk(const String&); - virtual Image* defaultIcon(const IntSize&); + WEBCORE_EXPORT Image* defaultIcon(const IntSize&) final; - virtual void retainIconForPageURL(const String&); - virtual void releaseIconForPageURL(const String&); - virtual void setIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String&); - virtual void setIconURLForPageURL(const String& iconURL, const String& pageURL); + WEBCORE_EXPORT void retainIconForPageURL(const String&) final; + WEBCORE_EXPORT void releaseIconForPageURL(const String&) final; + WEBCORE_EXPORT void setIconDataForIconURL(SharedBuffer* data, const String& iconURL) final; + WEBCORE_EXPORT void setIconURLForPageURL(const String& iconURL, const String& pageURL) final; - virtual Image* synchronousIconForPageURL(const String&, const IntSize&); - virtual PassNativeImagePtr synchronousNativeIconForPageURL(const String& pageURLOriginal, const IntSize&); - virtual String synchronousIconURLForPageURL(const String&); - virtual bool synchronousIconDataKnownForIconURL(const String&); - virtual IconLoadDecision synchronousLoadDecisionForIconURL(const String&, DocumentLoader*); - - virtual void setEnabled(bool); - virtual bool isEnabled() const; - - virtual void setPrivateBrowsingEnabled(bool flag); + WEBCORE_EXPORT Image* synchronousIconForPageURL(const String&, const IntSize&) final; + NativeImagePtr synchronousNativeIconForPageURL(const String& pageURLOriginal, const IntSize&) final; + WEBCORE_EXPORT String synchronousIconURLForPageURL(const String&) final; + bool synchronousIconDataKnownForIconURL(const String&) final; + WEBCORE_EXPORT IconLoadDecision synchronousLoadDecisionForIconURL(const String&, DocumentLoader*) final; + + WEBCORE_EXPORT void setEnabled(bool); + WEBCORE_EXPORT bool isEnabled() const final; + + WEBCORE_EXPORT void setPrivateBrowsingEnabled(bool flag) final; bool isPrivateBrowsingEnabled() const; - - static void delayDatabaseCleanup(); - static void allowDatabaseCleanup(); - static void checkIntegrityBeforeOpening(); - + + WEBCORE_EXPORT static void delayDatabaseCleanup(); + WEBCORE_EXPORT static void allowDatabaseCleanup(); + WEBCORE_EXPORT static void checkIntegrityBeforeOpening(); + // Support for WebCoreStatistics in WebKit - virtual size_t pageURLMappingCount(); - virtual size_t retainedPageURLCount(); - virtual size_t iconRecordCount(); - virtual size_t iconRecordCountWithData(); + WEBCORE_EXPORT size_t pageURLMappingCount() final; + WEBCORE_EXPORT size_t retainedPageURLCount() final; + WEBCORE_EXPORT size_t iconRecordCount() final; + WEBCORE_EXPORT size_t iconRecordCountWithData() final; private: - IconDatabase(); friend IconDatabaseBase& iconDatabase(); - static void notifyPendingLoadDecisionsOnMainThread(void*); void notifyPendingLoadDecisions(); void wakeSyncThread(); void scheduleOrDeferSyncTimer(); - void syncTimerFired(Timer<IconDatabase>&); + void syncTimerFired(); - Timer<IconDatabase> m_syncTimer; + Timer m_syncTimer; ThreadIdentifier m_syncThread; bool m_syncThreadRunning; @@ -138,27 +126,24 @@ private: RefPtr<IconRecord> m_defaultIconRecord; - static void performScheduleOrDeferSyncTimerOnMainThread(void*); - void performScheduleOrDeferSyncTimer(); - bool m_scheduleOrDeferSyncTimerRequested; std::unique_ptr<SuddenTerminationDisabler> m_disableSuddenTerminationWhileSyncTimerScheduled; // *** Any Thread *** public: - virtual bool isOpen() const; - virtual String databasePath() const; - static String defaultDatabaseFilename(); + WEBCORE_EXPORT bool isOpen() const final; + WEBCORE_EXPORT String databasePath() const final; + WEBCORE_EXPORT static String defaultDatabaseFilename(); private: - PassRefPtr<IconRecord> getOrCreateIconRecord(const String& iconURL); + Ref<IconRecord> getOrCreateIconRecord(const String& iconURL); PageURLRecord* getOrCreatePageURLRecord(const String& pageURL); bool m_isEnabled; bool m_privateBrowsingEnabled; - mutable Mutex m_syncLock; - ThreadCondition m_syncCondition; + mutable Lock m_syncLock; + Condition m_syncCondition; String m_databaseDirectory; // Holding m_syncLock is required when accessing m_completeDatabasePath String m_completeDatabasePath; @@ -169,24 +154,24 @@ private: bool m_syncThreadHasWorkToDo; std::unique_ptr<SuddenTerminationDisabler> m_disableSuddenTerminationWhileSyncThreadHasWorkToDo; - Mutex m_urlAndIconLock; + Lock m_urlAndIconLock; // Holding m_urlAndIconLock is required when accessing any of the following data structures or the objects they contain HashMap<String, IconRecord*> m_iconURLToRecordMap; HashMap<String, PageURLRecord*> m_pageURLToRecordMap; HashSet<String> m_retainedPageURLs; - Mutex m_pendingSyncLock; + Lock m_pendingSyncLock; // Holding m_pendingSyncLock is required when accessing any of the following data structures HashMap<String, PageURLSnapshot> m_pageURLsPendingSync; HashMap<String, IconSnapshot> m_iconsPendingSync; - Mutex m_pendingReadingLock; + Lock m_pendingReadingLock; // Holding m_pendingSyncLock is required when accessing any of the following data structures - when dealing with IconRecord*s, holding m_urlAndIconLock is also required HashSet<String> m_pageURLsPendingImport; HashSet<String> m_pageURLsInterestedInIcons; HashSet<IconRecord*> m_iconsPendingReading; - Mutex m_urlsToRetainOrReleaseLock; + Lock m_urlsToRetainOrReleaseLock; // Holding m_urlsToRetainOrReleaseLock is required when accessing any of the following data structures. HashCountedSet<String> m_urlsToRetain; HashCountedSet<String> m_urlsToRelease; @@ -194,7 +179,7 @@ private: // *** Sync Thread Only *** public: - virtual bool shouldStopThreadActivity() const; + WEBCORE_EXPORT bool shouldStopThreadActivity() const final; private: static void iconDatabaseSyncThreadStart(void *); @@ -219,6 +204,9 @@ private: bool wasExcludedFromBackup(); void setWasExcludedFromBackup(); + bool isOpenBesidesMainThreadCallbacks() const; + void checkClosedAfterMainThreadCallback(); + bool m_initialPruningComplete; void setIconURLForPageURLInSQLDatabase(const String&, const String&); @@ -226,7 +214,7 @@ private: void removePageURLFromSQLDatabase(const String& pageURL); int64_t getIconIDForIconURLFromSQLDatabase(const String& iconURL); int64_t addIconURLToSQLDatabase(const String&); - PassRefPtr<SharedBuffer> getImageDataForIconURLFromSQLDatabase(const String& iconURL); + RefPtr<SharedBuffer> getImageDataForIconURLFromSQLDatabase(const String& iconURL); void removeIconFromSQLDatabase(const String& iconURL); void writeIconSnapshotToSQLDatabase(const IconSnapshot&); @@ -237,30 +225,29 @@ private: void dispatchDidImportIconDataForPageURLOnMainThread(const String&); void dispatchDidRemoveAllIconsOnMainThread(); void dispatchDidFinishURLImportOnMainThread(); + std::atomic<uint32_t> m_mainThreadCallbackCount; // The client is set by the main thread before the thread starts, and from then on is only used by the sync thread IconDatabaseClient* m_client; SQLiteDatabase m_syncDB; - OwnPtr<SQLiteStatement> m_setIconIDForPageURLStatement; - OwnPtr<SQLiteStatement> m_removePageURLStatement; - OwnPtr<SQLiteStatement> m_getIconIDForIconURLStatement; - OwnPtr<SQLiteStatement> m_getImageDataForIconURLStatement; - OwnPtr<SQLiteStatement> m_addIconToIconInfoStatement; - OwnPtr<SQLiteStatement> m_addIconToIconDataStatement; - OwnPtr<SQLiteStatement> m_getImageDataStatement; - OwnPtr<SQLiteStatement> m_deletePageURLsForIconURLStatement; - OwnPtr<SQLiteStatement> m_deleteIconFromIconInfoStatement; - OwnPtr<SQLiteStatement> m_deleteIconFromIconDataStatement; - OwnPtr<SQLiteStatement> m_updateIconInfoStatement; - OwnPtr<SQLiteStatement> m_updateIconDataStatement; - OwnPtr<SQLiteStatement> m_setIconInfoStatement; - OwnPtr<SQLiteStatement> m_setIconDataStatement; + std::unique_ptr<SQLiteStatement> m_setIconIDForPageURLStatement; + std::unique_ptr<SQLiteStatement> m_removePageURLStatement; + std::unique_ptr<SQLiteStatement> m_getIconIDForIconURLStatement; + std::unique_ptr<SQLiteStatement> m_getImageDataForIconURLStatement; + std::unique_ptr<SQLiteStatement> m_addIconToIconInfoStatement; + std::unique_ptr<SQLiteStatement> m_addIconToIconDataStatement; + std::unique_ptr<SQLiteStatement> m_getImageDataStatement; + std::unique_ptr<SQLiteStatement> m_deletePageURLsForIconURLStatement; + std::unique_ptr<SQLiteStatement> m_deleteIconFromIconInfoStatement; + std::unique_ptr<SQLiteStatement> m_deleteIconFromIconDataStatement; + std::unique_ptr<SQLiteStatement> m_updateIconInfoStatement; + std::unique_ptr<SQLiteStatement> m_updateIconDataStatement; + std::unique_ptr<SQLiteStatement> m_setIconInfoStatement; + std::unique_ptr<SQLiteStatement> m_setIconDataStatement; }; #endif // !ENABLE(ICONDATABASE) } // namespace WebCore - -#endif // IconDatabase_h |