summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/loader/icon
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/loader/icon')
-rw-r--r--Source/WebCore/loader/icon/IconDatabase.cpp184
-rw-r--r--Source/WebCore/loader/icon/IconDatabase.h92
-rw-r--r--Source/WebCore/loader/icon/IconDatabaseBase.cpp69
-rw-r--r--Source/WebCore/loader/icon/IconDatabaseBase.h221
-rw-r--r--Source/WebCore/loader/icon/IconDatabaseClient.h19
-rw-r--r--Source/WebCore/loader/icon/IconDatabaseNone.cpp218
6 files changed, 505 insertions, 298 deletions
diff --git a/Source/WebCore/loader/icon/IconDatabase.cpp b/Source/WebCore/loader/icon/IconDatabase.cpp
index 26f3bb7..e5578e0 100644
--- a/Source/WebCore/loader/icon/IconDatabase.cpp
+++ b/Source/WebCore/loader/icon/IconDatabase.cpp
@@ -58,7 +58,6 @@
namespace WebCore {
-static IconDatabase* sharedIconDatabase = 0;
static int databaseCleanupCounter = 0;
// This version number is in the DB and marks the current generation of the schema
@@ -85,21 +84,22 @@ static String urlForLogging(const String& url)
}
#endif
+class DefaultIconDatabaseClient : public IconDatabaseClient {
+public:
+ virtual bool performImport() { return true; }
+ virtual void didImportIconURLForPageURL(const String&) { }
+ virtual void didImportIconDataForPageURL(const String&) { }
+ virtual void didChangeIconForPageURL(const String&) { }
+ virtual void didRemoveAllIcons() { }
+ virtual void didFinishURLImport() { }
+};
+
static IconDatabaseClient* defaultClient()
{
- static IconDatabaseClient* defaultClient = new IconDatabaseClient();
+ static IconDatabaseClient* defaultClient = new DefaultIconDatabaseClient();
return defaultClient;
}
-IconDatabase& iconDatabase()
-{
- if (!sharedIconDatabase) {
- ScriptController::initializeThreading();
- sharedIconDatabase = new IconDatabase;
- }
- return *sharedIconDatabase;
-}
-
// ************************
// *** Main Thread Only ***
// ************************
@@ -117,7 +117,7 @@ void IconDatabase::setClient(IconDatabaseClient* client)
m_client = client;
}
-bool IconDatabase::open(const String& databasePath)
+bool IconDatabase::open(const String& directory, const String& filename)
{
ASSERT_NOT_SYNC_THREAD();
@@ -129,10 +129,10 @@ bool IconDatabase::open(const String& databasePath)
return false;
}
- m_databaseDirectory = databasePath.crossThreadString();
+ m_databaseDirectory = directory.crossThreadString();
// Formulate the full path for the database file
- m_completeDatabasePath = pathByAppendingComponent(m_databaseDirectory, defaultDatabaseFilename());
+ m_completeDatabasePath = pathByAppendingComponent(m_databaseDirectory, filename);
// Lock here as well as first thing in the thread so the thread doesn't actually commence until the createThread() call
// completes and m_syncThreadRunning is properly set
@@ -217,7 +217,7 @@ void IconDatabase::removeAllIcons()
wakeSyncThread();
}
-Image* IconDatabase::iconForPageURL(const String& pageURLOriginal, const IntSize& size)
+Image* IconDatabase::synchronousIconForPageURL(const String& pageURLOriginal, const IntSize& size)
{
ASSERT_NOT_SYNC_THREAD();
@@ -301,10 +301,10 @@ void IconDatabase::readIconForPageURLFromDisk(const String& pageURL)
// The effect of asking for an Icon for a pageURL automatically queues it to be read from disk
// if it hasn't already been set in memory. The special IntSize (0, 0) is a special way of telling
// that method "I don't care about the actual Image, i just want you to make sure you're getting it from disk.
- iconForPageURL(pageURL, IntSize(0,0));
+ synchronousIconForPageURL(pageURL, IntSize(0, 0));
}
-String IconDatabase::iconURLForPageURL(const String& pageURLOriginal)
+String IconDatabase::synchronousIconURLForPageURL(const String& pageURLOriginal)
{
ASSERT_NOT_SYNC_THREAD();
@@ -565,7 +565,7 @@ void IconDatabase::setIconDataForIconURL(PassRefPtr<SharedBuffer> dataOriginal,
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]);
+ m_client->didChangeIconForPageURL(pageURLs[i]);
pool.cycle();
}
@@ -637,11 +637,11 @@ void IconDatabase::setIconURLForPageURL(const String& iconURLOriginal, const Str
LOG(IconDatabase, "Dispatching notification that we changed an icon mapping for url %s", urlForLogging(pageURL).ascii().data());
AutodrainedPool pool;
- m_client->dispatchDidAddIconForPageURL(pageURL);
+ m_client->didChangeIconForPageURL(pageURL);
}
}
-IconLoadDecision IconDatabase::loadDecisionForIconURL(const String& iconURL, DocumentLoader* notificationDocumentLoader)
+IconLoadDecision IconDatabase::synchronousLoadDecisionForIconURL(const String& iconURL, DocumentLoader* notificationDocumentLoader)
{
ASSERT_NOT_SYNC_THREAD();
@@ -667,12 +667,13 @@ IconLoadDecision IconDatabase::loadDecisionForIconURL(const String& iconURL, Doc
// Otherwise - since we refuse to perform I/O on the main thread to find out for sure - we return the answer that says
// "You might be asked to load this later, so flag that"
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);
- m_loadersPendingDecision.add(notificationDocumentLoader);
+ if (notificationDocumentLoader)
+ m_loadersPendingDecision.add(notificationDocumentLoader);
return IconLoadUnknown;
}
-bool IconDatabase::iconDataKnownForIconURL(const String& iconURL)
+bool IconDatabase::synchronousIconDataKnownForIconURL(const String& iconURL)
{
ASSERT_NOT_SYNC_THREAD();
@@ -775,6 +776,7 @@ IconDatabase::IconDatabase()
, m_imported(false)
, m_isImportedSet(false)
{
+ LOG(IconDatabase, "Creating IconDatabase %p", this);
ASSERT(isMainThread());
}
@@ -1257,7 +1259,7 @@ void IconDatabase::performURLImport()
{
MutexLocker locker(m_pendingReadingLock);
if (m_pageURLsPendingImport.contains(pageURL)) {
- m_client->dispatchDidAddIconForPageURL(pageURL);
+ dispatchDidImportIconURLForPageURLOnMainThread(pageURL);
m_pageURLsPendingImport.remove(pageURL);
pool.cycle();
@@ -1292,7 +1294,6 @@ void IconDatabase::performURLImport()
// Loop through the urls pending import
// Remove unretained ones if database cleanup is allowed
// Keep a set of ones that are retained and pending notification
-
{
MutexLocker locker(m_urlAndIconLock);
@@ -1331,13 +1332,16 @@ void IconDatabase::performURLImport()
// Now that we don't hold any locks, perform the actual notifications
for (unsigned i = 0; i < urlsToNotify.size(); ++i) {
LOG(IconDatabase, "Notifying icon info known for pageURL %s", urlsToNotify[i].ascii().data());
- m_client->dispatchDidAddIconForPageURL(urlsToNotify[i]);
+ dispatchDidImportIconURLForPageURLOnMainThread(urlsToNotify[i]);
if (shouldStopThreadActivity())
return;
pool.cycle();
}
+ // Notify the client that the URL import is complete in case it's managing its own pending notifications.
+ dispatchDidFinishURLImportOnMainThread();
+
// Notify all DocumentLoaders that were waiting for an icon load decision on the main thread
callOnMainThread(notifyPendingLoadDecisionsOnMainThread, this);
}
@@ -1540,7 +1544,7 @@ bool IconDatabase::readFromDatabase()
HashSet<String>::iterator end = urlsToNotify.end();
for (unsigned iteration = 0; iter != end; ++iter, ++iteration) {
LOG(IconDatabase, "Notifying icon received for pageURL %s", urlForLogging(*iter).ascii().data());
- m_client->dispatchDidAddIconForPageURL(*iter);
+ dispatchDidImportIconDataForPageURLOnMainThread(*iter);
if (shouldStopThreadActivity())
return didAnyWork;
@@ -1738,7 +1742,7 @@ void IconDatabase::removeAllIconsOnThread()
createDatabaseTables(m_syncDB);
LOG(IconDatabase, "Dispatching notification that we removed all icons");
- m_client->dispatchDidRemoveAllIcons();
+ dispatchDidRemoveAllIconsOnMainThread();
}
void IconDatabase::deleteAllPreparedStatements()
@@ -2111,6 +2115,132 @@ void IconDatabase::setWasExcludedFromBackup()
SQLiteStatement(m_syncDB, "INSERT INTO IconDatabaseInfo (key, value) VALUES ('ExcludedFromBackup', 1)").executeCommand();
}
+class ClientWorkItem {
+public:
+ ClientWorkItem(IconDatabaseClient* client)
+ : m_client(client)
+ { }
+ virtual void performWork() = 0;
+ virtual ~ClientWorkItem() { }
+
+protected:
+ IconDatabaseClient* m_client;
+};
+
+class ImportedIconURLForPageURLWorkItem : public ClientWorkItem {
+public:
+ ImportedIconURLForPageURLWorkItem(IconDatabaseClient* client, const String& pageURL)
+ : ClientWorkItem(client)
+ , m_pageURL(new String(pageURL.threadsafeCopy()))
+ { }
+
+ virtual ~ImportedIconURLForPageURLWorkItem()
+ {
+ delete m_pageURL;
+ }
+
+ virtual void performWork()
+ {
+ ASSERT(m_client);
+ m_client->didImportIconURLForPageURL(*m_pageURL);
+ m_client = 0;
+ }
+
+private:
+ String* m_pageURL;
+};
+
+class ImportedIconDataForPageURLWorkItem : public ClientWorkItem {
+public:
+ ImportedIconDataForPageURLWorkItem(IconDatabaseClient* client, const String& pageURL)
+ : ClientWorkItem(client)
+ , m_pageURL(new String(pageURL.threadsafeCopy()))
+ { }
+
+ virtual ~ImportedIconDataForPageURLWorkItem()
+ {
+ delete m_pageURL;
+ }
+
+ virtual void performWork()
+ {
+ ASSERT(m_client);
+ m_client->didImportIconDataForPageURL(*m_pageURL);
+ m_client = 0;
+ }
+
+private:
+ String* m_pageURL;
+};
+
+class RemovedAllIconsWorkItem : public ClientWorkItem {
+public:
+ RemovedAllIconsWorkItem(IconDatabaseClient* client)
+ : ClientWorkItem(client)
+ { }
+
+ virtual void performWork()
+ {
+ ASSERT(m_client);
+ m_client->didRemoveAllIcons();
+ m_client = 0;
+ }
+};
+
+class FinishedURLImport : public ClientWorkItem {
+public:
+ FinishedURLImport(IconDatabaseClient* client)
+ : ClientWorkItem(client)
+ { }
+
+ virtual void performWork()
+ {
+ ASSERT(m_client);
+ m_client->didFinishURLImport();
+ m_client = 0;
+ }
+};
+
+static void performWorkItem(void* context)
+{
+ ClientWorkItem* item = static_cast<ClientWorkItem*>(context);
+ item->performWork();
+ delete item;
+}
+
+void IconDatabase::dispatchDidImportIconURLForPageURLOnMainThread(const String& pageURL)
+{
+ ASSERT_ICON_SYNC_THREAD();
+
+ ImportedIconURLForPageURLWorkItem* work = new ImportedIconURLForPageURLWorkItem(m_client, pageURL);
+ callOnMainThread(performWorkItem, work);
+}
+
+void IconDatabase::dispatchDidImportIconDataForPageURLOnMainThread(const String& pageURL)
+{
+ ASSERT_ICON_SYNC_THREAD();
+
+ ImportedIconDataForPageURLWorkItem* work = new ImportedIconDataForPageURLWorkItem(m_client, pageURL);
+ callOnMainThread(performWorkItem, work);
+}
+
+void IconDatabase::dispatchDidRemoveAllIconsOnMainThread()
+{
+ ASSERT_ICON_SYNC_THREAD();
+
+ RemovedAllIconsWorkItem* work = new RemovedAllIconsWorkItem(m_client);
+ callOnMainThread(performWorkItem, work);
+}
+
+void IconDatabase::dispatchDidFinishURLImportOnMainThread()
+{
+ ASSERT_ICON_SYNC_THREAD();
+
+ FinishedURLImport* work = new FinishedURLImport(m_client);
+ callOnMainThread(performWorkItem, work);
+}
+
+
} // namespace WebCore
#endif // ENABLE(ICONDATABASE)
diff --git a/Source/WebCore/loader/icon/IconDatabase.h b/Source/WebCore/loader/icon/IconDatabase.h
index 8617430..7392245 100644
--- a/Source/WebCore/loader/icon/IconDatabase.h
+++ b/Source/WebCore/loader/icon/IconDatabase.h
@@ -27,17 +27,20 @@
#ifndef IconDatabase_h
#define IconDatabase_h
+#include "IconDatabaseBase.h"
#include "Timer.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
+#endif // ENABLE(ICONDATABASE)
namespace WebCore {
@@ -56,41 +59,48 @@ class SharedBuffer;
class SQLTransaction;
#endif
-enum IconLoadDecision {
- IconLoadYes,
- IconLoadNo,
- IconLoadUnknown
+#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 void delayDatabaseCleanup() { }
+ static String defaultDatabaseFilename() { return "WebpageIcons.db"; }
};
+#else
-class IconDatabase {
- WTF_MAKE_NONCOPYABLE(IconDatabase); WTF_MAKE_FAST_ALLOCATED;
+class IconDatabase : public IconDatabaseBase {
+ WTF_MAKE_FAST_ALLOCATED;
+
// *** Main Thread Only ***
public:
- void setClient(IconDatabaseClient*);
+ static PassOwnPtr<IconDatabase> create() { return new IconDatabase; }
+ ~IconDatabase();
+
+ virtual void setClient(IconDatabaseClient*);
- bool open(const String& path);
- void close();
+ virtual bool open(const String& directory, const String& filename);
+ virtual void close();
- void removeAllIcons();
+ virtual void removeAllIcons();
- Image* iconForPageURL(const String&, const IntSize&);
void readIconForPageURLFromDisk(const String&);
- String iconURLForPageURL(const String&);
- Image* defaultIcon(const IntSize&);
- void retainIconForPageURL(const String&);
- void releaseIconForPageURL(const String&);
+ virtual Image* defaultIcon(const IntSize&);
- void setIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String&);
- void setIconURLForPageURL(const String& iconURL, const String& pageURL);
+ 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);
- IconLoadDecision loadDecisionForIconURL(const String&, DocumentLoader*);
- bool iconDataKnownForIconURL(const String&);
+ virtual Image* synchronousIconForPageURL(const String&, const IntSize&);
+ virtual String synchronousIconURLForPageURL(const String&);
+ virtual bool synchronousIconDataKnownForIconURL(const String&);
+ virtual IconLoadDecision synchronousLoadDecisionForIconURL(const String&, DocumentLoader*);
- void setEnabled(bool enabled);
- bool isEnabled() const;
+ virtual void setEnabled(bool);
+ virtual bool isEnabled() const;
- void setPrivateBrowsingEnabled(bool flag);
+ virtual void setPrivateBrowsingEnabled(bool flag);
bool isPrivateBrowsingEnabled() const;
static void delayDatabaseCleanup();
@@ -98,17 +108,15 @@ public:
static void checkIntegrityBeforeOpening();
// Support for WebCoreStatistics in WebKit
- size_t pageURLMappingCount();
- size_t retainedPageURLCount();
- size_t iconRecordCount();
- size_t iconRecordCountWithData();
+ virtual size_t pageURLMappingCount();
+ virtual size_t retainedPageURLCount();
+ virtual size_t iconRecordCount();
+ virtual size_t iconRecordCountWithData();
private:
IconDatabase();
- ~IconDatabase();
- friend IconDatabase& iconDatabase();
+ friend IconDatabaseBase& iconDatabase();
-#if ENABLE(ICONDATABASE)
static void notifyPendingLoadDecisionsOnMainThread(void*);
void notifyPendingLoadDecisions();
@@ -123,15 +131,13 @@ private:
HashSet<RefPtr<DocumentLoader> > m_loadersPendingDecision;
RefPtr<IconRecord> m_defaultIconRecord;
-#endif // ENABLE(ICONDATABASE)
// *** Any Thread ***
public:
- bool isOpen() const;
- String databasePath() const;
+ virtual bool isOpen() const;
+ virtual String databasePath() const;
static String defaultDatabaseFilename();
-#if ENABLE(ICONDATABASE)
private:
PassRefPtr<IconRecord> getOrCreateIconRecord(const String& iconURL);
PageURLRecord* getOrCreatePageURLRecord(const String& pageURL);
@@ -166,17 +172,15 @@ private:
HashSet<String> m_pageURLsPendingImport;
HashSet<String> m_pageURLsInterestedInIcons;
HashSet<IconRecord*> m_iconsPendingReading;
-#endif // ENABLE(ICONDATABASE)
// *** Sync Thread Only ***
public:
// Should be used only on the sync thread and only by the Safari 2 Icons import procedure
- void importIconURLForPageURL(const String& iconURL, const String& pageURL);
- void importIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String& iconURL);
+ virtual void importIconURLForPageURL(const String& iconURL, const String& pageURL);
+ virtual void importIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String& iconURL);
- bool shouldStopThreadActivity() const;
+ virtual bool shouldStopThreadActivity() const;
-#if ENABLE(ICONDATABASE)
private:
static void* iconDatabaseSyncThreadStart(void *);
void* iconDatabaseSyncThread();
@@ -213,6 +217,12 @@ private:
void removeIconFromSQLDatabase(const String& iconURL);
void writeIconSnapshotToSQLDatabase(const IconSnapshot&);
+ // Methods to dispatch client callbacks on the main thread
+ void dispatchDidImportIconURLForPageURLOnMainThread(const String&);
+ void dispatchDidImportIconDataForPageURLOnMainThread(const String&);
+ void dispatchDidRemoveAllIconsOnMainThread();
+ void dispatchDidFinishURLImportOnMainThread();
+
// 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;
@@ -236,11 +246,9 @@ private:
OwnPtr<SQLiteStatement> m_updateIconDataStatement;
OwnPtr<SQLiteStatement> m_setIconInfoStatement;
OwnPtr<SQLiteStatement> m_setIconDataStatement;
-#endif // ENABLE(ICONDATABASE)
};
-// Function to obtain the global icon database.
-IconDatabase& iconDatabase();
+#endif // !ENABLE(ICONDATABASE)
} // namespace WebCore
diff --git a/Source/WebCore/loader/icon/IconDatabaseBase.cpp b/Source/WebCore/loader/icon/IconDatabaseBase.cpp
new file mode 100644
index 0000000..f552412
--- /dev/null
+++ b/Source/WebCore/loader/icon/IconDatabaseBase.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * 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
+ * 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
+ * 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
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "IconDatabaseBase.h"
+
+#include "IconDatabase.h"
+#include "SharedBuffer.h"
+
+namespace WebCore {
+
+String IconDatabaseBase::synchronousIconURLForPageURL(const String&)
+{
+ return String();
+}
+
+String IconDatabaseBase::databasePath() const
+{
+ return String();
+}
+
+bool IconDatabaseBase::open(const String&, const String&)
+{
+ return false;
+}
+
+static IconDatabaseBase* globalDatabase = 0;
+
+// Functions to get/set the global icon database.
+IconDatabaseBase& iconDatabase()
+{
+ if (globalDatabase)
+ return *globalDatabase;
+
+ static IconDatabaseBase* defaultDatabase = 0;
+ if (!defaultDatabase)
+ defaultDatabase = new IconDatabase;
+
+ return *defaultDatabase;
+}
+
+void setGlobalIconDatabase(IconDatabaseBase* newGlobalDatabase)
+{
+ globalDatabase = newGlobalDatabase;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/loader/icon/IconDatabaseBase.h b/Source/WebCore/loader/icon/IconDatabaseBase.h
new file mode 100644
index 0000000..bc665ba
--- /dev/null
+++ b/Source/WebCore/loader/icon/IconDatabaseBase.h
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * 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
+ * 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
+ * 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
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef IconDatabaseBase_h
+#define IconDatabaseBase_h
+
+#include "SharedBuffer.h"
+
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class DocumentLoader;
+class IconDatabaseClient;
+class Image;
+class IntSize;
+
+enum IconLoadDecision {
+ IconLoadYes,
+ IconLoadNo,
+ IconLoadUnknown
+};
+
+class CallbackBase : public RefCounted<CallbackBase> {
+public:
+ virtual ~CallbackBase()
+ {
+ }
+
+ uint64_t callbackID() const { return m_callbackID; }
+
+protected:
+ CallbackBase(void* context)
+ : m_context(context)
+ , m_callbackID(generateCallbackID())
+ {
+ }
+
+ void* context() const { return m_context; }
+
+private:
+ static uint64_t generateCallbackID()
+ {
+ static uint64_t uniqueCallbackID = 1;
+ return uniqueCallbackID++;
+ }
+
+ void* m_context;
+ uint64_t m_callbackID;
+};
+
+template<typename EnumType>
+class EnumCallback : public CallbackBase {
+public:
+ typedef void (*CallbackFunction)(EnumType, void*);
+
+ static PassRefPtr<EnumCallback> create(void* context, CallbackFunction callback)
+ {
+ return adoptRef(new EnumCallback(context, callback));
+ }
+
+ virtual ~EnumCallback()
+ {
+ ASSERT(!m_callback);
+ }
+
+ void performCallback(EnumType result)
+ {
+ if (!m_callback)
+ return;
+ m_callback(result, context());
+ m_callback = 0;
+ }
+
+ void invalidate()
+ {
+ m_callback = 0;
+ }
+
+private:
+ EnumCallback(void* context, CallbackFunction callback)
+ : CallbackBase(context)
+ , m_callback(callback)
+ {
+ ASSERT(m_callback);
+ }
+
+ CallbackFunction m_callback;
+};
+
+template<typename ObjectType>
+class ObjectCallback : public CallbackBase {
+public:
+ typedef void (*CallbackFunction)(ObjectType, void*);
+
+ static PassRefPtr<ObjectCallback> create(void* context, CallbackFunction callback)
+ {
+ return adoptRef(new ObjectCallback(context, callback));
+ }
+
+ virtual ~ObjectCallback()
+ {
+ ASSERT(!m_callback);
+ }
+
+ void performCallback(ObjectType result)
+ {
+ if (!m_callback)
+ return;
+ m_callback(result, context());
+ m_callback = 0;
+ }
+
+ void invalidate()
+ {
+ m_callback = 0;
+ }
+
+private:
+ ObjectCallback(void* context, CallbackFunction callback)
+ : CallbackBase(context)
+ , m_callback(callback)
+ {
+ ASSERT(m_callback);
+ }
+
+ CallbackFunction m_callback;
+};
+
+typedef EnumCallback<IconLoadDecision> IconLoadDecisionCallback;
+typedef ObjectCallback<SharedBuffer*> IconDataCallback;
+
+class IconDatabaseBase {
+ WTF_MAKE_NONCOPYABLE(IconDatabaseBase);
+
+protected:
+ IconDatabaseBase() { }
+
+public:
+ virtual ~IconDatabaseBase() { }
+
+ // Used internally by WebCore
+ virtual bool isEnabled() const { return false; }
+
+ virtual void retainIconForPageURL(const String&) { }
+ virtual void releaseIconForPageURL(const String&) { }
+
+ virtual void setIconURLForPageURL(const String&, const String&) { }
+ virtual void setIconDataForIconURL(PassRefPtr<SharedBuffer>, const String&) { }
+
+ // Synchronous calls used internally by WebCore.
+ // Usage should be replaced by asynchronous calls.
+ virtual String synchronousIconURLForPageURL(const String&);
+ virtual bool synchronousIconDataKnownForIconURL(const String&) { return false; }
+ virtual IconLoadDecision synchronousLoadDecisionForIconURL(const String&, DocumentLoader*) { return IconLoadNo; }
+ virtual Image* synchronousIconForPageURL(const String&, const IntSize&) { return 0; }
+
+ // Asynchronous calls we should use to replace the above when supported.
+ virtual bool supportsAsynchronousMode() { return false; }
+ virtual void loadDecisionForIconURL(const String&, PassRefPtr<IconLoadDecisionCallback>) { }
+ virtual void iconDataForIconURL(const String&, PassRefPtr<IconDataCallback>) { }
+
+
+ // Used within one or more WebKit ports.
+ // We should try to remove these dependencies from the IconDatabaseBase class.
+ virtual void setEnabled(bool) { }
+
+ virtual Image* defaultIcon(const IntSize&) { return 0; }
+
+ virtual size_t pageURLMappingCount() { return 0; }
+ virtual size_t retainedPageURLCount() { return 0; }
+ virtual size_t iconRecordCount() { return 0; }
+ virtual size_t iconRecordCountWithData() { return 0; }
+
+ virtual void importIconURLForPageURL(const String&, const String&) { }
+ virtual void importIconDataForIconURL(PassRefPtr<SharedBuffer>, const String&) { }
+ virtual bool shouldStopThreadActivity() const { return true; }
+
+ virtual bool open(const String& directory, const String& filename);
+ virtual void close() { }
+ virtual void removeAllIcons() { }
+
+ virtual void setPrivateBrowsingEnabled(bool) { }
+ virtual void setClient(IconDatabaseClient*) { }
+
+ virtual bool isOpen() const { return false; }
+ virtual String databasePath() const;
+
+};
+
+// Functions to get/set the global icon database.
+IconDatabaseBase& iconDatabase();
+void setGlobalIconDatabase(IconDatabaseBase*);
+
+} // namespace WebCore
+
+#endif // IconDatabaseBase_h
diff --git a/Source/WebCore/loader/icon/IconDatabaseClient.h b/Source/WebCore/loader/icon/IconDatabaseClient.h
index f97a2a8..3d5f349 100644
--- a/Source/WebCore/loader/icon/IconDatabaseClient.h
+++ b/Source/WebCore/loader/icon/IconDatabaseClient.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,23 +29,20 @@
#ifndef IconDatabaseClient_h
#define IconDatabaseClient_h
-#include <wtf/FastAllocBase.h>
#include <wtf/Forward.h>
-#include <wtf/Noncopyable.h>
-
-// All of these client methods will be called from a non-main thread
-// Take appropriate measures
namespace WebCore {
class IconDatabaseClient {
- WTF_MAKE_NONCOPYABLE(IconDatabaseClient); WTF_MAKE_FAST_ALLOCATED;
public:
- IconDatabaseClient() { }
virtual ~IconDatabaseClient() { }
- virtual bool performImport() { return true; }
- virtual void dispatchDidRemoveAllIcons() { }
- virtual void dispatchDidAddIconForPageURL(const String& /*pageURL*/) { }
+
+ virtual bool performImport() = 0;
+ virtual void didImportIconURLForPageURL(const String&) = 0;
+ virtual void didImportIconDataForPageURL(const String&) = 0;
+ virtual void didChangeIconForPageURL(const String&) = 0;
+ virtual void didRemoveAllIcons() = 0;
+ virtual void didFinishURLImport() = 0;
};
} // namespace WebCore
diff --git a/Source/WebCore/loader/icon/IconDatabaseNone.cpp b/Source/WebCore/loader/icon/IconDatabaseNone.cpp
deleted file mode 100644
index de28cdd..0000000
--- a/Source/WebCore/loader/icon/IconDatabaseNone.cpp
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * 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
- * 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
- * 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
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "IconDatabase.h"
-
-#if !ENABLE(ICONDATABASE)
-
-#include "PlatformString.h"
-#include "SharedBuffer.h"
-#include <wtf/StdLibExtras.h>
-
-namespace WebCore {
-
-static IconDatabase* sharedIconDatabase = 0;
-
-// This version number is in the DB and marks the current generation of the schema
-// Theoretically once the switch is flipped this should never change
-// Currently, an out-of-date schema causes the DB to be wiped and reset. This isn't
-// so bad during development but in the future, we would need to write a conversion
-// function to advance older released schemas to "current"
-const int currentDatabaseVersion = 5;
-
-// Icons expire once a day
-const int iconExpirationTime = 60*60*24;
-// Absent icons are rechecked once a week
-const int missingIconExpirationTime = 60*60*24*7;
-
-const int updateTimerDelay = 5;
-
-String IconDatabase::defaultDatabaseFilename()
-{
- DEFINE_STATIC_LOCAL(String, defaultDatabaseFilename, ("Icons.db"));
- return defaultDatabaseFilename.threadsafeCopy();
-}
-
-IconDatabase& iconDatabase()
-{
- if (!sharedIconDatabase)
- sharedIconDatabase = new IconDatabase;
- return *sharedIconDatabase;
-}
-
-IconDatabase::IconDatabase()
-{
-}
-
-bool IconDatabase::open(const String& /*databasePath*/)
-{
- return false;
-}
-
-bool IconDatabase::isOpen() const
-{
- return false;
-}
-
-void IconDatabase::close()
-{
-}
-
-String IconDatabase::databasePath() const
-{
- return String();
-}
-
-void IconDatabase::removeAllIcons()
-{
-}
-
-void IconDatabase::setPrivateBrowsingEnabled(bool /*flag*/)
-{
-}
-
-bool IconDatabase::isPrivateBrowsingEnabled() const
-{
- return false;
-}
-
-void IconDatabase::readIconForPageURLFromDisk(const String&)
-{
-
-}
-
-Image* IconDatabase::iconForPageURL(const String& /*pageURL*/, const IntSize& size)
-{
- return defaultIcon(size);
-}
-
-
-IconLoadDecision IconDatabase::loadDecisionForIconURL(const String&, DocumentLoader*)
-{
- return IconLoadNo;
-}
-
-bool IconDatabase::iconDataKnownForIconURL(const String&)
-{
- return false;
-}
-
-String IconDatabase::iconURLForPageURL(const String& /*pageURL*/)
-{
- return String();
-}
-
-Image* IconDatabase::defaultIcon(const IntSize& /*size*/)
-{
- return 0;
-}
-
-void IconDatabase::retainIconForPageURL(const String& /*pageURL*/)
-{
-}
-
-void IconDatabase::releaseIconForPageURL(const String& /*pageURL*/)
-{
-}
-
-void IconDatabase::setIconDataForIconURL(PassRefPtr<SharedBuffer> /*data*/, const String& /*iconURL*/)
-{
-}
-
-void IconDatabase::setIconURLForPageURL(const String& /*iconURL*/, const String& /*pageURL*/)
-{
-}
-
-void IconDatabase::setEnabled(bool /*enabled*/)
-{
-}
-
-bool IconDatabase::isEnabled() const
-{
- return false;
-}
-
-IconDatabase::~IconDatabase()
-{
- ASSERT_NOT_REACHED();
-}
-
-void IconDatabase::checkIntegrityBeforeOpening()
-{
-}
-
-void IconDatabase::delayDatabaseCleanup()
-{
-}
-
-void IconDatabase::allowDatabaseCleanup()
-{
-}
-
-size_t IconDatabase::pageURLMappingCount()
-{
- return 0;
-}
-
-size_t IconDatabase::retainedPageURLCount()
-{
- return 0;
-}
-
-size_t IconDatabase::iconRecordCount()
-{
- return 0;
-}
-
-size_t IconDatabase::iconRecordCountWithData()
-{
- return 0;
-}
-
-void IconDatabase::setClient(IconDatabaseClient*)
-{
-}
-
-// ************************
-// *** Sync Thread Only ***
-// ************************
-
-void IconDatabase::importIconURLForPageURL(const String&, const String&)
-{
-}
-
-void IconDatabase::importIconDataForIconURL(PassRefPtr<SharedBuffer>, const String&)
-{
-}
-
-bool IconDatabase::shouldStopThreadActivity() const
-{
- return true;
-}
-
-} // namespace WebCore
-
-#endif // !ENABLE(ICONDATABASE)