Commit 6306a9c7 authored by jorlow@chromium.org's avatar jorlow@chromium.org
Browse files

2011-02-14 Jeremy Orlow <jorlow@chromium.org>

        Reviewed by Darin Fisher.

        Add initial support for per-origin quotas to IndexedDB
        https://bugs.webkit.org/show_bug.cgi?id=54421

        Add support for non-persistent per-origin quotas. If one is
        specified, it overrides the default.

        No tests as this is only exposed via the Chromium webkit API.

        * storage/IDBFactoryBackendImpl.cpp:
        (WebCore::IDBFactoryBackendImpl::open):
        (WebCore::IDBFactoryBackendImpl::setQuota):
        * storage/IDBFactoryBackendImpl.h:
        * storage/IDBFactoryBackendInterface.h:
2011-02-14  Jeremy Orlow  <jorlow@chromium.org>

        Reviewed by Darin Fisher.

        Add initial support for per-origin quotas to IndexedDB
        https://bugs.webkit.org/show_bug.cgi?id=54421

        * public/WebIDBFactory.h:
        (WebKit::WebIDBFactory::setQuota):
        * src/AssertMatchingEnums.cpp:
        * src/IDBFactoryBackendProxy.cpp:
        (WebCore::IDBFactoryBackendProxy::setQuota):
        * src/IDBFactoryBackendProxy.h:
        * src/WebIDBFactoryImpl.cpp:
        (WebKit::WebIDBFactoryImpl::setQuota):
        * src/WebIDBFactoryImpl.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@78645 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3a0207f5
2011-02-14 Jeremy Orlow <jorlow@chromium.org>
Reviewed by Darin Fisher.
Add initial support for per-origin quotas to IndexedDB
https://bugs.webkit.org/show_bug.cgi?id=54421
Add support for non-persistent per-origin quotas. If one is
specified, it overrides the default.
No tests as this is only exposed via the Chromium webkit API.
* storage/IDBFactoryBackendImpl.cpp:
(WebCore::IDBFactoryBackendImpl::open):
(WebCore::IDBFactoryBackendImpl::setQuota):
* storage/IDBFactoryBackendImpl.h:
* storage/IDBFactoryBackendInterface.h:
2011-02-15 Adam Barth <abarth@webkit.org>
 
Reviewed by Darin Adler.
......@@ -207,9 +207,15 @@ static bool migrateDatabase(SQLiteDatabase& sqliteDatabase)
return true;
}
void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir, int64_t maximumSize)
void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir, int64_t defaultQuota)
{
ASSERT(defaultQuota >= 0);
String fileIdentifier = securityOrigin->databaseIdentifier();
if (!m_defaultQuotaMap.contains(fileIdentifier))
m_defaultQuotaMap.set(fileIdentifier, defaultQuota);
else
ASSERT(m_defaultQuotaMap.get(fileIdentifier) == defaultQuota); // FIXME: Handle this case more elegently if it ever matters.
String uniqueIdentifier = fileIdentifier + "@" + name;
IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
if (it != m_databaseBackendMap.end()) {
......@@ -217,6 +223,10 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
return;
}
int64_t quota = defaultQuota;
if (m_currentQuotaMap.contains(fileIdentifier))
quota = m_currentQuotaMap.contains(fileIdentifier);
// FIXME: Everything from now on should be done on another thread.
RefPtr<IDBSQLiteDatabase> sqliteDatabase;
......@@ -224,7 +234,7 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
if (it2 != m_sqliteDatabaseMap.end())
sqliteDatabase = it2->second;
else {
sqliteDatabase = openSQLiteDatabase(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
sqliteDatabase = openSQLiteDatabase(securityOrigin.get(), dataDir, quota, fileIdentifier, this);
if (!sqliteDatabase || !createTables(sqliteDatabase->db()) || !migrateDatabase(sqliteDatabase->db())) {
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
......@@ -239,6 +249,26 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
}
void IDBFactoryBackendImpl::setQuota(PassRefPtr<SecurityOrigin> securityOrigin, int64_t quota, bool persistent)
{
ASSERT(!persistent); // FIXME: Impelment persistence.
String fileIdentifier = securityOrigin->databaseIdentifier();
if (quota == defaultQuota) {
m_currentQuotaMap.remove(fileIdentifier);
if (!m_defaultQuotaMap.contains(fileIdentifier)) {
ASSERT(m_sqliteDatabaseMap.find(fileIdentifier) == m_sqliteDatabaseMap.end());
return;
}
quota = m_defaultQuotaMap.get(fileIdentifier);
} else
m_currentQuotaMap.set(fileIdentifier, quota);
SQLiteDatabaseMap::iterator it2 = m_sqliteDatabaseMap.find(fileIdentifier);
if (it2 != m_sqliteDatabaseMap.end())
it2->second->db().setMaximumSize(quota); // FIXME: What if we set a quota to something smaller than the file currently is?
}
} // namespace WebCore
#endif // ENABLE(INDEXED_DATABASE)
......@@ -54,7 +54,9 @@ public:
void removeIDBDatabaseBackend(const String& uniqueIdentifier);
void removeSQLiteDatabase(const String& uniqueIdentifier);
virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t maximumSize);
virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t defaultQuota);
virtual void setQuota(PassRefPtr<SecurityOrigin>, int64_t quota, bool persistent);
private:
IDBFactoryBackendImpl();
......@@ -65,6 +67,10 @@ private:
typedef HashMap<String, IDBSQLiteDatabase*> SQLiteDatabaseMap;
SQLiteDatabaseMap m_sqliteDatabaseMap;
typedef HashMap<String, int64_t> QuotaMap;
QuotaMap m_currentQuotaMap;
QuotaMap m_defaultQuotaMap;
RefPtr<IDBTransactionCoordinator> m_transactionCoordinator;
// Only one instance of the factory should exist at any given time.
......
......@@ -51,7 +51,11 @@ public:
static PassRefPtr<IDBFactoryBackendInterface> create();
virtual ~IDBFactoryBackendInterface() { }
virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t maximumSize) = 0;
virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t defaultQuota) = 0;
static const int64_t defaultQuota = -1;
static const int64_t unlimitedQuota = 0;
virtual void setQuota(PassRefPtr<SecurityOrigin>, int64_t quota, bool persistent) = 0;
};
} // namespace WebCore
......
2011-02-14 Jeremy Orlow <jorlow@chromium.org>
Reviewed by Darin Fisher.
Add initial support for per-origin quotas to IndexedDB
https://bugs.webkit.org/show_bug.cgi?id=54421
* public/WebIDBFactory.h:
(WebKit::WebIDBFactory::setQuota):
* src/AssertMatchingEnums.cpp:
* src/IDBFactoryBackendProxy.cpp:
(WebCore::IDBFactoryBackendProxy::setQuota):
* src/IDBFactoryBackendProxy.h:
* src/WebIDBFactoryImpl.cpp:
(WebKit::WebIDBFactoryImpl::setQuota):
* src/WebIDBFactoryImpl.h:
2011-02-15 Jia Pu <jpu@apple.com>
 
Reviewed by Darin Adler.
......@@ -52,8 +52,13 @@ public:
virtual ~WebIDBFactory() { }
// The WebKit implementation of open ignores the WebFrame* parameter.
virtual void open(const WebString& name, WebIDBCallbacks*, const WebSecurityOrigin&, WebFrame*, const WebString& dataDir, unsigned long long maximumSize) { WEBKIT_ASSERT_NOT_REACHED(); }
virtual void open(const WebString& name, WebIDBCallbacks*, const WebSecurityOrigin&, WebFrame*, const WebString& dataDir, unsigned long long defaultQuota) { WEBKIT_ASSERT_NOT_REACHED(); }
virtual void deleteDatabase(const WebString& name, WebIDBCallbacks*, const WebSecurityOrigin&, WebFrame*, const WebString& dataDir) { WEBKIT_ASSERT_NOT_REACHED(); }
// FIXME: Should these constants be in a more global place?
static const long long defaultQuota = -1;
static const long long unlimitedQuota = 0;
virtual void setQuota(const WebSecurityOrigin&, long long quota, bool persistent) { WEBKIT_ASSERT_NOT_REACHED(); }
};
} // namespace WebKit
......
......@@ -45,6 +45,7 @@
#include "GeolocationError.h"
#include "GeolocationPosition.h"
#include "HTMLInputElement.h"
#include "IDBFactoryBackendInterface.h"
#include "IDBKey.h"
#include "MediaPlayer.h"
#include "NotificationPresenter.h"
......@@ -67,6 +68,7 @@
#include "WebFontDescription.h"
#include "WebGeolocationError.h"
#include "WebGeolocationPosition.h"
#include "WebIDBFactory.h"
#include "WebIDBKey.h"
#include "WebInputElement.h"
#include "WebMediaPlayer.h"
......@@ -370,6 +372,9 @@ COMPILE_ASSERT_MATCHING_ENUM(WebView::UserContentInjectInTopFrameOnly, InjectInT
COMPILE_ASSERT_MATCHING_ENUM(WebView::UserStyleInjectInExistingDocuments, InjectInExistingDocuments);
COMPILE_ASSERT_MATCHING_ENUM(WebView::UserStyleInjectInSubsequentDocuments, InjectInSubsequentDocuments);
COMPILE_ASSERT_MATCHING_ENUM(WebIDBFactory::unlimitedQuota, IDBFactoryBackendInterface::unlimitedQuota);
COMPILE_ASSERT_MATCHING_ENUM(WebIDBFactory::defaultQuota, IDBFactoryBackendInterface::defaultQuota);
COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::NullType, IDBKey::NullType);
COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::StringType, IDBKey::StringType);
COMPILE_ASSERT_MATCHING_ENUM(WebIDBKey::DateType, IDBKey::DateType);
......
......@@ -65,6 +65,11 @@ void IDBFactoryBackendProxy::open(const String& name, PassRefPtr<IDBCallbacks> c
m_webIDBFactory->open(name, new WebIDBCallbacksImpl(callbacks), origin, webFrame, dataDir, maximumSize);
}
void IDBFactoryBackendProxy::setQuota(PassRefPtr<SecurityOrigin> origin, int64_t maximumSize, bool persistent)
{
m_webIDBFactory->setQuota(origin, maximumSize, persistent);
}
} // namespace WebCore
#endif // ENABLE(INDEXED_DATABASE)
......
......@@ -46,6 +46,7 @@ public:
PassRefPtr<DOMStringList> databases(void) const;
virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t maximumSize);
virtual void setQuota(PassRefPtr<SecurityOrigin>, int64_t maximumSize, bool persistent);
private:
IDBFactoryBackendProxy();
......
......@@ -58,9 +58,14 @@ WebIDBFactoryImpl::~WebIDBFactoryImpl()
{
}
void WebIDBFactoryImpl::open(const WebString& name, WebIDBCallbacks* callbacks, const WebSecurityOrigin& origin, WebFrame*, const WebString& dataDir, unsigned long long maximumSize)
void WebIDBFactoryImpl::open(const WebString& name, WebIDBCallbacks* callbacks, const WebSecurityOrigin& origin, WebFrame*, const WebString& dataDir, unsigned long long defaultQuota)
{
m_idbFactoryBackend->open(name, IDBCallbacksProxy::create(callbacks), origin, 0, dataDir, maximumSize);
m_idbFactoryBackend->open(name, IDBCallbacksProxy::create(callbacks), origin, 0, dataDir, defaultQuota);
}
void WebIDBFactoryImpl::setQuota(const WebSecurityOrigin& origin, long long quota, bool persistent)
{
m_idbFactoryBackend->setQuota(origin, quota, persistent);
}
} // namespace WebKit
......
......@@ -42,7 +42,9 @@ public:
WebIDBFactoryImpl();
virtual ~WebIDBFactoryImpl();
virtual void open(const WebString& name, WebIDBCallbacks*, const WebSecurityOrigin&, WebFrame*, const WebString& dataDir, unsigned long long maximumSize);
virtual void open(const WebString& name, WebIDBCallbacks*, const WebSecurityOrigin&, WebFrame*, const WebString& dataDir, unsigned long long defaultQuota);
virtual void setQuota(const WebSecurityOrigin&, long long quota, bool persistent);
private:
WTF::RefPtr<WebCore::IDBFactoryBackendInterface> m_idbFactoryBackend;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment