summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/renderer_host/database_message_filter.cc83
-rw-r--r--content/browser/renderer_host/database_message_filter.h4
-rw-r--r--content/common/database_messages.h17
-rw-r--r--content/common/database_util.cc17
-rw-r--r--content/common/database_util.h14
-rw-r--r--content/common/db_message_filter.cc21
-rw-r--r--content/common/db_message_filter.h6
-rw-r--r--content/renderer/renderer_webkitclient_impl.cc13
-rw-r--r--content/renderer/renderer_webkitclient_impl.h2
-rw-r--r--content/worker/worker_webkitclient_impl.cc13
-rw-r--r--content/worker/worker_webkitclient_impl.h2
-rw-r--r--webkit/database/database_tracker.h20
-rw-r--r--webkit/glue/webkitclient_impl.cc5
-rw-r--r--webkit/glue/webkitclient_impl.h2
-rw-r--r--webkit/support/simple_database_system.cc42
-rw-r--r--webkit/support/simple_database_system.h4
-rw-r--r--webkit/support/test_webkit_client.cc9
-rw-r--r--webkit/support/test_webkit_client.h2
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.cc6
-rw-r--r--webkit/tools/test_shell/test_shell_webkit_init.h2
20 files changed, 234 insertions, 50 deletions
diff --git a/content/browser/renderer_host/database_message_filter.cc b/content/browser/renderer_host/database_message_filter.cc
index fe0c9a0..13883dc 100644
--- a/content/browser/renderer_host/database_message_filter.cc
+++ b/content/browser/renderer_host/database_message_filter.cc
@@ -16,19 +16,53 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "webkit/database/database_util.h"
#include "webkit/database/vfs_backend.h"
+#include "webkit/quota/quota_manager.h"
#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
#endif
+using quota::QuotaManager;
+using quota::QuotaManagerProxy;
+using quota::QuotaStatusCode;
using WebKit::WebSecurityOrigin;
using webkit_database::DatabaseTracker;
using webkit_database::DatabaseUtil;
using webkit_database::VfsBackend;
+namespace {
+
+class MyGetUsageAndQuotaCallback
+ : public QuotaManager::GetUsageAndQuotaCallback {
+ public:
+ MyGetUsageAndQuotaCallback(
+ DatabaseMessageFilter* sender, IPC::Message* reply_msg)
+ : sender_(sender), reply_msg_(reply_msg) {}
+
+ virtual void RunWithParams(
+ const Tuple3<QuotaStatusCode, int64, int64>& params) {
+ Run(params.a, params.b, params.c);
+ }
+
+ void Run(QuotaStatusCode status, int64 usage, int64 quota) {
+ int64 available = 0;
+ if ((status == quota::kQuotaStatusOk) && (usage < quota))
+ available = quota - usage;
+ DatabaseHostMsg_GetSpaceAvailable::WriteReplyParams(
+ reply_msg_.get(), available);
+ sender_->Send(reply_msg_.release());
+ }
+
+ private:
+ scoped_refptr<DatabaseMessageFilter> sender_;
+ scoped_ptr<IPC::Message> reply_msg_;
+};
+
const int kNumDeleteRetries = 2;
const int kDelayDeleteRetryMs = 100;
+} // namespace
+
DatabaseMessageFilter::DatabaseMessageFilter(
webkit_database::DatabaseTracker* db_tracker)
: db_tracker_(db_tracker),
@@ -53,22 +87,23 @@ void DatabaseMessageFilter::AddObserver() {
void DatabaseMessageFilter::RemoveObserver() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ db_tracker_->RemoveObserver(this);
// If the renderer process died without closing all databases,
// then we need to manually close those connections
db_tracker_->CloseDatabases(database_connections_);
database_connections_.RemoveAllConnections();
-
- db_tracker_->RemoveObserver(this);
}
void DatabaseMessageFilter::OverrideThreadForMessage(
const IPC::Message& message,
BrowserThread::ID* thread) {
- if (IPC_MESSAGE_CLASS(message) == DatabaseMsgStart)
+ if (message.type() == DatabaseHostMsg_GetSpaceAvailable::ID)
+ *thread = BrowserThread::IO;
+ else if (IPC_MESSAGE_CLASS(message) == DatabaseMsgStart)
*thread = BrowserThread::FILE;
- if (message.type() == DatabaseHostMsg_OpenFile::ID && !observer_added_) {
+ if (message.type() == DatabaseHostMsg_Opened::ID && !observer_added_) {
observer_added_ = true;
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
@@ -89,6 +124,8 @@ bool DatabaseMessageFilter::OnMessageReceived(
OnDatabaseGetFileAttributes)
IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetFileSize,
OnDatabaseGetFileSize)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetSpaceAvailable,
+ OnDatabaseGetSpaceAvailable)
IPC_MESSAGE_HANDLER(DatabaseHostMsg_Opened, OnDatabaseOpened)
IPC_MESSAGE_HANDLER(DatabaseHostMsg_Modified, OnDatabaseModified)
IPC_MESSAGE_HANDLER(DatabaseHostMsg_Closed, OnDatabaseClosed)
@@ -220,7 +257,7 @@ void DatabaseMessageFilter::OnDatabaseGetFileAttributes(
}
void DatabaseMessageFilter::OnDatabaseGetFileSize(
- const string16& vfs_file_name, IPC::Message* reply_msg) {
+ const string16& vfs_file_name, IPC::Message* reply_msg) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
int64 size = 0;
FilePath db_file =
@@ -232,18 +269,40 @@ void DatabaseMessageFilter::OnDatabaseGetFileSize(
Send(reply_msg);
}
+void DatabaseMessageFilter::OnDatabaseGetSpaceAvailable(
+ const string16& origin_identifier, IPC::Message* reply_msg) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(db_tracker_->quota_manager_proxy());
+
+ QuotaManager* quota_manager =
+ db_tracker_->quota_manager_proxy()->quota_manager();
+ if (!quota_manager) {
+ NOTREACHED(); // The system is shutting down, messages are unexpected.
+ DatabaseHostMsg_GetSpaceAvailable::WriteReplyParams(
+ reply_msg, static_cast<int64>(0));
+ Send(reply_msg);
+ return;
+ }
+
+ quota_manager->GetUsageAndQuota(
+ DatabaseUtil::GetOriginFromIdentifier(origin_identifier),
+ quota::kStorageTypeTemporary,
+ new MyGetUsageAndQuotaCallback(this, reply_msg));
+}
+
void DatabaseMessageFilter::OnDatabaseOpened(const string16& origin_identifier,
const string16& database_name,
const string16& description,
int64 estimated_size) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
int64 database_size = 0;
- int64 space_available = 0;
- database_connections_.AddConnection(origin_identifier, database_name);
+ int64 space_available_not_used = 0;
db_tracker_->DatabaseOpened(origin_identifier, database_name, description,
- estimated_size, &database_size, &space_available);
+ estimated_size, &database_size,
+ &space_available_not_used);
+ database_connections_.AddConnection(origin_identifier, database_name);
Send(new DatabaseMsg_UpdateSize(origin_identifier, database_name,
- database_size, space_available));
+ database_size));
}
void DatabaseMessageFilter::OnDatabaseModified(
@@ -270,19 +329,19 @@ void DatabaseMessageFilter::OnDatabaseClosed(const string16& origin_identifier,
return;
}
- db_tracker_->DatabaseClosed(origin_identifier, database_name);
database_connections_.RemoveConnection(origin_identifier, database_name);
+ db_tracker_->DatabaseClosed(origin_identifier, database_name);
}
void DatabaseMessageFilter::OnDatabaseSizeChanged(
const string16& origin_identifier,
const string16& database_name,
int64 database_size,
- int64 space_available) {
+ int64 space_available_not_used) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
if (database_connections_.IsOriginUsed(origin_identifier)) {
Send(new DatabaseMsg_UpdateSize(origin_identifier, database_name,
- database_size, space_available));
+ database_size));
}
}
diff --git a/content/browser/renderer_host/database_message_filter.h b/content/browser/renderer_host/database_message_filter.h
index 1cfc659..c7f9a98 100644
--- a/content/browser/renderer_host/database_message_filter.h
+++ b/content/browser/renderer_host/database_message_filter.h
@@ -49,6 +49,10 @@ class DatabaseMessageFilter
void OnDatabaseGetFileSize(const string16& vfs_file_name,
IPC::Message* reply_msg);
+ // Quota message handler (io thread)
+ void OnDatabaseGetSpaceAvailable(const string16& origin_identifier,
+ IPC::Message* reply_msg);
+
// Database tracker message handlers (file thread)
void OnDatabaseOpened(const string16& origin_identifier,
const string16& database_name,
diff --git a/content/common/database_messages.h b/content/common/database_messages.h
index f8d2d18..a9dc55b 100644
--- a/content/common/database_messages.h
+++ b/content/common/database_messages.h
@@ -13,12 +13,20 @@
// Database messages sent from the browser to the renderer.
// Notifies the child process of the new database size
-IPC_MESSAGE_CONTROL4(DatabaseMsg_UpdateSize,
+IPC_MESSAGE_CONTROL3(DatabaseMsg_UpdateSize,
string16 /* the origin */,
string16 /* the database name */,
- int64 /* the new database size */,
+ int64 /* the new database size */)
+
+// Notifies the child process of the new space available
+IPC_MESSAGE_CONTROL2(DatabaseMsg_UpdateSpaceAvailable,
+ string16 /* the origin */,
int64 /* space available to origin */)
+// Notifies the child process to reset it's cached value for the origin.
+IPC_MESSAGE_CONTROL1(DatabaseMsg_ResetSpaceAvailable,
+ string16 /* the origin */)
+
// Asks the child process to close a database immediately
IPC_MESSAGE_CONTROL2(DatabaseMsg_CloseImmediately,
string16 /* the origin */,
@@ -48,6 +56,11 @@ IPC_SYNC_MESSAGE_CONTROL1_1(DatabaseHostMsg_GetFileSize,
string16 /* vfs file name */,
int64 /* the size of the given DB file */)
+// Asks the browser process for the amount of space available to an origin
+IPC_SYNC_MESSAGE_CONTROL1_1(DatabaseHostMsg_GetSpaceAvailable,
+ string16 /* origin identifier */,
+ int64 /* remaining space available */)
+
// Notifies the browser process that a new database has been opened
IPC_MESSAGE_CONTROL4(DatabaseHostMsg_Opened,
string16 /* origin identifier */,
diff --git a/content/common/database_util.cc b/content/common/database_util.cc
index 71cd6c9..fc40873 100644
--- a/content/common/database_util.cc
+++ b/content/common/database_util.cc
@@ -13,7 +13,7 @@
using WebKit::WebKitClient;
using WebKit::WebString;
-WebKitClient::FileHandle DatabaseUtil::databaseOpenFile(
+WebKitClient::FileHandle DatabaseUtil::DatabaseOpenFile(
const WebString& vfs_file_name, int desired_flags) {
IPC::PlatformFileForTransit file_handle =
IPC::InvalidPlatformFileForTransit();
@@ -26,7 +26,7 @@ WebKitClient::FileHandle DatabaseUtil::databaseOpenFile(
return IPC::PlatformFileForTransitToPlatformFile(file_handle);
}
-int DatabaseUtil::databaseDeleteFile(
+int DatabaseUtil::DatabaseDeleteFile(
const WebString& vfs_file_name, bool sync_dir) {
int rv = SQLITE_IOERR_DELETE;
scoped_refptr<IPC::SyncMessageFilter> filter(
@@ -36,7 +36,7 @@ int DatabaseUtil::databaseDeleteFile(
return rv;
}
-long DatabaseUtil::databaseGetFileAttributes(const WebString& vfs_file_name) {
+long DatabaseUtil::DatabaseGetFileAttributes(const WebString& vfs_file_name) {
int32 rv = -1;
scoped_refptr<IPC::SyncMessageFilter> filter(
ChildThread::current()->sync_message_filter());
@@ -44,10 +44,19 @@ long DatabaseUtil::databaseGetFileAttributes(const WebString& vfs_file_name) {
return rv;
}
-long long DatabaseUtil::databaseGetFileSize(const WebString& vfs_file_name) {
+long long DatabaseUtil::DatabaseGetFileSize(const WebString& vfs_file_name) {
int64 rv = 0LL;
scoped_refptr<IPC::SyncMessageFilter> filter(
ChildThread::current()->sync_message_filter());
filter->Send(new DatabaseHostMsg_GetFileSize(vfs_file_name, &rv));
return rv;
}
+
+long long DatabaseUtil::DatabaseGetSpaceAvailable(
+ const WebString& origin_identifier) {
+ int64 rv = 0LL;
+ scoped_refptr<IPC::SyncMessageFilter> filter(
+ ChildThread::current()->sync_message_filter());
+ filter->Send(new DatabaseHostMsg_GetSpaceAvailable(origin_identifier, &rv));
+ return rv;
+}
diff --git a/content/common/database_util.h b/content/common/database_util.h
index 1f78b21..cf2d706 100644
--- a/content/common/database_util.h
+++ b/content/common/database_util.h
@@ -12,12 +12,16 @@
// WorkerWebKitClientImpl to handle database file accesses.
class DatabaseUtil {
public:
- static WebKit::WebKitClient::FileHandle databaseOpenFile(
+ static WebKit::WebKitClient::FileHandle DatabaseOpenFile(
const WebKit::WebString& vfs_file_name, int desired_flags);
- static int databaseDeleteFile(const WebKit::WebString& vfs_file_name,
- bool sync_dir);
- static long databaseGetFileAttributes(const WebKit::WebString& vfs_file_name);
- static long long databaseGetFileSize(const WebKit::WebString& vfs_file_name);
+ static int DatabaseDeleteFile(
+ const WebKit::WebString& vfs_file_name, bool sync_dir);
+ static long DatabaseGetFileAttributes(
+ const WebKit::WebString& vfs_file_name);
+ static long long DatabaseGetFileSize(
+ const WebKit::WebString& vfs_file_name);
+ static long long DatabaseGetSpaceAvailable(
+ const WebKit::WebString& origin_identifier);
};
#endif // CONTENT_COMMON_DATABASE_UTIL_H_
diff --git a/content/common/db_message_filter.cc b/content/common/db_message_filter.cc
index 8b86589..132346e 100644
--- a/content/common/db_message_filter.cc
+++ b/content/common/db_message_filter.cc
@@ -15,6 +15,10 @@ bool DBMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DBMessageFilter, message)
IPC_MESSAGE_HANDLER(DatabaseMsg_UpdateSize, OnDatabaseUpdateSize)
+ IPC_MESSAGE_HANDLER(DatabaseMsg_UpdateSpaceAvailable,
+ OnDatabaseUpdateSpaceAvailable)
+ IPC_MESSAGE_HANDLER(DatabaseMsg_ResetSpaceAvailable,
+ OnDatabaseResetSpaceAvailable)
IPC_MESSAGE_HANDLER(DatabaseMsg_CloseImmediately,
OnDatabaseCloseImmediately)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -24,10 +28,21 @@ bool DBMessageFilter::OnMessageReceived(const IPC::Message& message) {
void DBMessageFilter::OnDatabaseUpdateSize(const string16& origin_identifier,
const string16& database_name,
- int64 database_size,
- int64 space_available) {
+ int64 database_size) {
WebKit::WebDatabase::updateDatabaseSize(
- origin_identifier, database_name, database_size, space_available);
+ origin_identifier, database_name, database_size);
+}
+
+void DBMessageFilter::OnDatabaseUpdateSpaceAvailable(
+ const string16& origin_identifier,
+ int64 space_available) {
+ WebKit::WebDatabase::updateSpaceAvailable(
+ origin_identifier, space_available);
+}
+
+void DBMessageFilter::OnDatabaseResetSpaceAvailable(
+ const string16& origin_identifier) {
+ WebKit::WebDatabase::resetSpaceAvailable(origin_identifier);
}
void DBMessageFilter::OnDatabaseCloseImmediately(
diff --git a/content/common/db_message_filter.h b/content/common/db_message_filter.h
index 40af94b..9547166 100644
--- a/content/common/db_message_filter.h
+++ b/content/common/db_message_filter.h
@@ -19,8 +19,10 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter {
void OnDatabaseUpdateSize(const string16& origin_identifier,
const string16& database_name,
- int64 database_size,
- int64 space_available);
+ int64 database_size);
+ void OnDatabaseUpdateSpaceAvailable(const string16& origin_identifier,
+ int64 space_available);
+ void OnDatabaseResetSpaceAvailable(const string16& origin_identifier);
void OnDatabaseCloseImmediately(const string16& origin_identifier,
const string16& database_name);
};
diff --git a/content/renderer/renderer_webkitclient_impl.cc b/content/renderer/renderer_webkitclient_impl.cc
index c68cc58..b2c4e11 100644
--- a/content/renderer/renderer_webkitclient_impl.cc
+++ b/content/renderer/renderer_webkitclient_impl.cc
@@ -495,22 +495,27 @@ bool RendererWebKitClientImpl::SandboxSupport::loadFont(NSFont* srcFont,
WebKitClient::FileHandle RendererWebKitClientImpl::databaseOpenFile(
const WebString& vfs_file_name, int desired_flags) {
- return DatabaseUtil::databaseOpenFile(vfs_file_name, desired_flags);
+ return DatabaseUtil::DatabaseOpenFile(vfs_file_name, desired_flags);
}
int RendererWebKitClientImpl::databaseDeleteFile(
const WebString& vfs_file_name, bool sync_dir) {
- return DatabaseUtil::databaseDeleteFile(vfs_file_name, sync_dir);
+ return DatabaseUtil::DatabaseDeleteFile(vfs_file_name, sync_dir);
}
long RendererWebKitClientImpl::databaseGetFileAttributes(
const WebString& vfs_file_name) {
- return DatabaseUtil::databaseGetFileAttributes(vfs_file_name);
+ return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name);
}
long long RendererWebKitClientImpl::databaseGetFileSize(
const WebString& vfs_file_name) {
- return DatabaseUtil::databaseGetFileSize(vfs_file_name);
+ return DatabaseUtil::DatabaseGetFileSize(vfs_file_name);
+}
+
+long long RendererWebKitClientImpl::databaseGetSpaceAvailableForOrigin(
+ const WebString& origin_identifier) {
+ return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier);
}
WebKit::WebSharedWorkerRepository*
diff --git a/content/renderer/renderer_webkitclient_impl.h b/content/renderer/renderer_webkitclient_impl.h
index 606bf73..9b61bc4 100644
--- a/content/renderer/renderer_webkitclient_impl.h
+++ b/content/renderer/renderer_webkitclient_impl.h
@@ -57,6 +57,8 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
const WebKit::WebString& vfs_file_name);
virtual long long databaseGetFileSize(
const WebKit::WebString& vfs_file_name);
+ virtual long long databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier);
virtual WebKit::WebString signedPublicKeyAndChallengeString(
unsigned key_size_index,
const WebKit::WebString& challenge,
diff --git a/content/worker/worker_webkitclient_impl.cc b/content/worker/worker_webkitclient_impl.cc
index 0da3322..75a822b 100644
--- a/content/worker/worker_webkitclient_impl.cc
+++ b/content/worker/worker_webkitclient_impl.cc
@@ -178,22 +178,27 @@ WebSharedWorkerRepository* WorkerWebKitClientImpl::sharedWorkerRepository() {
WebKitClient::FileHandle WorkerWebKitClientImpl::databaseOpenFile(
const WebString& vfs_file_name, int desired_flags) {
- return DatabaseUtil::databaseOpenFile(vfs_file_name, desired_flags);
+ return DatabaseUtil::DatabaseOpenFile(vfs_file_name, desired_flags);
}
int WorkerWebKitClientImpl::databaseDeleteFile(
const WebString& vfs_file_name, bool sync_dir) {
- return DatabaseUtil::databaseDeleteFile(vfs_file_name, sync_dir);
+ return DatabaseUtil::DatabaseDeleteFile(vfs_file_name, sync_dir);
}
long WorkerWebKitClientImpl::databaseGetFileAttributes(
const WebString& vfs_file_name) {
- return DatabaseUtil::databaseGetFileAttributes(vfs_file_name);
+ return DatabaseUtil::DatabaseGetFileAttributes(vfs_file_name);
}
long long WorkerWebKitClientImpl::databaseGetFileSize(
const WebString& vfs_file_name) {
- return DatabaseUtil::databaseGetFileSize(vfs_file_name);
+ return DatabaseUtil::DatabaseGetFileSize(vfs_file_name);
+}
+
+long long WorkerWebKitClientImpl::databaseGetSpaceAvailableForOrigin(
+ const WebString& origin_identifier) {
+ return DatabaseUtil::DatabaseGetSpaceAvailable(origin_identifier);
}
WebMimeRegistry::SupportsType WorkerWebKitClientImpl::supportsMIMEType(
diff --git a/content/worker/worker_webkitclient_impl.h b/content/worker/worker_webkitclient_impl.h
index dd2c0a7..d38db0e 100644
--- a/content/worker/worker_webkitclient_impl.h
+++ b/content/worker/worker_webkitclient_impl.h
@@ -57,6 +57,8 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl,
const WebKit::WebString& vfs_file_name);
virtual long long databaseGetFileSize(
const WebKit::WebString& vfs_file_name);
+ virtual long long databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier);
virtual WebKit::WebBlobRegistry* blobRegistry();
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h
index 2246a13..9894ea8 100644
--- a/webkit/database/database_tracker.h
+++ b/webkit/database/database_tracker.h
@@ -70,9 +70,8 @@ class OriginInfo {
// This class manages the main database, and keeps track of per origin quotas.
//
// The data in this class is not thread-safe, so all methods of this class
-// should be called on the same thread. The only exception is
-// database_directory() which returns a constant that is initialized when
-// the DatabaseTracker instance is created.
+// should be called on the same thread. The only exceptions are the ctor(),
+// the dtor() and the database_directory() and quota_manager_proxy() getters.
//
// Furthermore, some methods of this class have to read/write data from/to
// the disk. Therefore, in a multi-threaded application, all methods of this
@@ -124,10 +123,16 @@ class DatabaseTracker
virtual bool GetAllOriginIdentifiers(std::vector<string16>* origin_ids);
virtual bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info);
+ // TODO(michaeln): remove quota related stuff when quota manager
+ // integration is complete
void SetOriginQuota(const string16& origin_identifier, int64 new_quota);
int64 GetDefaultQuota() { return default_quota_; }
- // Sets the default quota for all origins. Should be used in tests only.
- void SetDefaultQuota(int64 quota);
+ void SetDefaultQuota(int64 quota); // for testing
+
+ // Safe to call on any thread.
+ quota::QuotaManagerProxy* quota_manager_proxy() const {
+ return quota_manager_proxy_.get();
+ }
bool IsDatabaseScheduledForDeletion(const string16& origin_identifier,
const string16& database_name);
@@ -151,8 +156,9 @@ class DatabaseTracker
// Delete all databases that belong to the given origin. Returns net::OK on
// success, net::FAILED if not all databases could be deleted, and
// net::ERR_IO_PENDING and |callback| is invoked upon completion, if non-NULL.
- int DeleteDataForOrigin(const string16& origin_identifier,
- net::CompletionCallback* callback);
+ // virtual for unit testing only
+ virtual int DeleteDataForOrigin(const string16& origin_identifier,
+ net::CompletionCallback* callback);
bool IsIncognitoProfile() const { return is_incognito_; }
diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc
index 4244bc3f..31c6b13 100644
--- a/webkit/glue/webkitclient_impl.cc
+++ b/webkit/glue/webkitclient_impl.cc
@@ -506,6 +506,11 @@ long long WebKitClientImpl::databaseGetFileSize(
return 0;
}
+long long WebKitClientImpl::databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier) {
+ return 0;
+}
+
WebKit::WebString WebKitClientImpl::signedPublicKeyAndChallengeString(
unsigned key_size_index,
const WebKit::WebString& challenge,
diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h
index 0f3765f..52a216b 100644
--- a/webkit/glue/webkitclient_impl.h
+++ b/webkit/glue/webkitclient_impl.h
@@ -36,6 +36,8 @@ class WebKitClientImpl : public WebKit::WebKitClient {
virtual long databaseGetFileAttributes(
const WebKit::WebString& vfs_file_name);
virtual long long databaseGetFileSize(const WebKit::WebString& vfs_file_name);
+ virtual long long databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier);
virtual WebKit::WebString signedPublicKeyAndChallengeString(
unsigned key_size_index, const WebKit::WebString& challenge,
const WebKit::WebURL& url);
diff --git a/webkit/support/simple_database_system.cc b/webkit/support/simple_database_system.cc
index a2f37ad..30c8388 100644
--- a/webkit/support/simple_database_system.cc
+++ b/webkit/support/simple_database_system.cc
@@ -19,6 +19,7 @@
using webkit_database::DatabaseTracker;
using webkit_database::DatabaseUtil;
+using webkit_database::OriginInfo;
using webkit_database::VfsBackend;
SimpleDatabaseSystem* SimpleDatabaseSystem::instance_ = NULL;
@@ -30,6 +31,7 @@ SimpleDatabaseSystem* SimpleDatabaseSystem::GetInstance() {
SimpleDatabaseSystem::SimpleDatabaseSystem()
: db_thread_("SimpleDBThread"),
+ quota_per_origin_(5 * 1024 * 1024),
open_connections_(new webkit_database::DatabaseConnectionsWrapper) {
DCHECK(!instance_);
instance_ = this;
@@ -120,6 +122,17 @@ int64 SimpleDatabaseSystem::GetFileSize(const string16& vfs_file_name) {
return result;
}
+int64 SimpleDatabaseSystem::GetSpaceAvailable(
+ const string16& origin_identifier) {
+ int64 result = 0;
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(FROM_HERE,
+ NewRunnableMethod(this, &SimpleDatabaseSystem::VfsGetSpaceAvailable,
+ origin_identifier, &result, &done_event));
+ done_event.Wait();
+ return result;
+}
+
void SimpleDatabaseSystem::ClearAllDatabases() {
open_connections_->WaitForAllDatabasesToClose();
db_thread_proxy_->PostTask(FROM_HERE,
@@ -133,7 +146,7 @@ void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) {
quota));
return;
}
- db_tracker_->SetDefaultQuota(quota);
+ quota_per_origin_ = quota;
}
void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier,
@@ -142,12 +155,12 @@ void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier,
int64 estimated_size) {
DCHECK(db_thread_proxy_->BelongsToCurrentThread());
int64 database_size = 0;
- int64 space_available = 0;
+ int64 space_available_not_used = 0;
db_tracker_->DatabaseOpened(
origin_identifier, database_name, description,
- estimated_size, &database_size, &space_available);
+ estimated_size, &database_size, &space_available_not_used);
OnDatabaseSizeChanged(origin_identifier, database_name,
- database_size, space_available);
+ database_size, 0);
}
void SimpleDatabaseSystem::DatabaseModified(const string16& origin_identifier,
@@ -167,13 +180,13 @@ void SimpleDatabaseSystem::OnDatabaseSizeChanged(
const string16& origin_identifier,
const string16& database_name,
int64 database_size,
- int64 space_available) {
+ int64 space_available_not_used) {
DCHECK(db_thread_proxy_->BelongsToCurrentThread());
// We intentionally call into webkit on our background db_thread_
// to better emulate what happens in chrome where this method is
// invoked on the background ipc thread.
WebKit::WebDatabase::updateDatabaseSize(
- origin_identifier, database_name, database_size, space_available);
+ origin_identifier, database_name, database_size);
}
void SimpleDatabaseSystem::OnDatabaseScheduledForDeletion(
@@ -238,6 +251,23 @@ void SimpleDatabaseSystem::VfsGetFileSize(
done_event->Signal();
}
+void SimpleDatabaseSystem::VfsGetSpaceAvailable(
+ const string16& origin_identifier,
+ int64* result, base::WaitableEvent* done_event) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ // This method isn't actually part of the "vfs" interface, but it is
+ // used from within webcore and handled here in the same fashion.
+ OriginInfo info;
+ if (db_tracker_->GetOriginInfo(origin_identifier, &info)) {
+ int64 space_available = quota_per_origin_ - info.TotalSize();
+ *result = space_available < 0 ? 0 : space_available;
+ } else {
+ NOTREACHED();
+ *result = 0;
+ }
+ done_event->Signal();
+}
+
FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile(
const string16& vfs_file_name) {
DCHECK(db_thread_proxy_->BelongsToCurrentThread());
diff --git a/webkit/support/simple_database_system.h b/webkit/support/simple_database_system.h
index 5bedd74..b6aa9b9 100644
--- a/webkit/support/simple_database_system.h
+++ b/webkit/support/simple_database_system.h
@@ -44,6 +44,7 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
int DeleteFile(const string16& vfs_file_name, bool sync_dir);
uint32 GetFileAttributes(const string16& vfs_file_name);
int64 GetFileSize(const string16& vfs_file_name);
+ int64 GetSpaceAvailable(const string16& origin_identifier);
// For use by LayoutTestController, called on the main thread.
void ClearAllDatabases();
@@ -77,6 +78,8 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
uint32* result, base::WaitableEvent* done_event);
void VfsGetFileSize(const string16& vfs_file_name,
int64* result, base::WaitableEvent* done_event);
+ void VfsGetSpaceAvailable(const string16& origin_identifier,
+ int64* result, base::WaitableEvent* done_event);
FilePath GetFullFilePathForVfsFile(const string16& vfs_file_name);
@@ -91,6 +94,7 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
base::Thread db_thread_;
scoped_refptr<base::MessageLoopProxy> db_thread_proxy_;
scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
+ int64 quota_per_origin_;
// Data members to support waiting for all connections to be closed.
scoped_refptr<webkit_database::DatabaseConnectionsWrapper> open_connections_;
diff --git a/webkit/support/test_webkit_client.cc b/webkit/support/test_webkit_client.cc
index 8f43e63..99c4aad 100644
--- a/webkit/support/test_webkit_client.cc
+++ b/webkit/support/test_webkit_client.cc
@@ -195,7 +195,8 @@ int TestWebKitClient::databaseDeleteFile(const WebKit::WebString& vfs_file_name,
long TestWebKitClient::databaseGetFileAttributes(
const WebKit::WebString& vfs_file_name) {
- return SimpleDatabaseSystem::GetInstance()->GetFileAttributes(vfs_file_name);
+ return SimpleDatabaseSystem::GetInstance()->GetFileAttributes(
+ vfs_file_name);
}
long long TestWebKitClient::databaseGetFileSize(
@@ -203,6 +204,12 @@ long long TestWebKitClient::databaseGetFileSize(
return SimpleDatabaseSystem::GetInstance()->GetFileSize(vfs_file_name);
}
+long long TestWebKitClient::databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier) {
+ return SimpleDatabaseSystem::GetInstance()->GetSpaceAvailable(
+ origin_identifier);
+}
+
unsigned long long TestWebKitClient::visitedLinkHash(const char* canonicalURL,
size_t length) {
return 0;
diff --git a/webkit/support/test_webkit_client.h b/webkit/support/test_webkit_client.h
index 8867864..01ca20d 100644
--- a/webkit/support/test_webkit_client.h
+++ b/webkit/support/test_webkit_client.h
@@ -40,6 +40,8 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl {
const WebKit::WebString& vfs_file_name);
virtual long long databaseGetFileSize(
const WebKit::WebString& vfs_file_name);
+ virtual long long databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier);
virtual unsigned long long visitedLinkHash(const char* canonicalURL,
size_t length);
virtual bool isLinkVisited(unsigned long long linkHash);
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc
index a9b29ee..7935ccd 100644
--- a/webkit/tools/test_shell/test_shell_webkit_init.cc
+++ b/webkit/tools/test_shell/test_shell_webkit_init.cc
@@ -153,6 +153,12 @@ long long TestShellWebKitInit::databaseGetFileSize(
return SimpleDatabaseSystem::GetInstance()->GetFileSize(vfs_file_name);
}
+long long TestShellWebKitInit::databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier) {
+ return SimpleDatabaseSystem::GetInstance()->GetSpaceAvailable(
+ origin_identifier);
+}
+
unsigned long long TestShellWebKitInit::visitedLinkHash(
const char* canonicalURL,
size_t length) {
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h
index 0b400cb..8795b46 100644
--- a/webkit/tools/test_shell/test_shell_webkit_init.h
+++ b/webkit/tools/test_shell/test_shell_webkit_init.h
@@ -50,6 +50,8 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
const WebKit::WebString& vfs_file_name);
virtual long long databaseGetFileSize(
const WebKit::WebString& vfs_file_name);
+ virtual long long databaseGetSpaceAvailableForOrigin(
+ const WebKit::WebString& origin_identifier);
virtual unsigned long long visitedLinkHash(const char* canonicalURL,
size_t length);
virtual bool isLinkVisited(unsigned long long linkHash);