summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 00:34:32 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 00:34:32 +0000
commitdb4d4981a0089230ac88060d7c817e054de3f2e2 (patch)
tree2cfd032c1fdb6aece674d7a83d8a39ffeb410578 /content
parent80c2915f7a7e3857b52fceb22fd7ce30a4e3ec20 (diff)
downloadchromium_src-db4d4981a0089230ac88060d7c817e054de3f2e2.zip
chromium_src-db4d4981a0089230ac88060d7c817e054de3f2e2.tar.gz
chromium_src-db4d4981a0089230ac88060d7c817e054de3f2e2.tar.bz2
Use the QuotaManager to determine the space available to WebSQLDatabases. Since activity outside of the database system now affect how much space is available, our strategy for informing the client side of the new limit needed to change. It's not enough to just send the new limit when a change within the DB system has occurred.
This change depends on a webkit/webcore change. https://bugs.webkit.org/show_bug.cgi?id=60985 In this CL the renderer will ask the browser for the limit when needed. But also in this CL are ipc plumbing additions to support notifying the renderer as changes occur. That plumbing will be utilized in a later CL. * [Chrome] DatabaseMessageFilter uses the QuotaManager respond to the SpaceAvailable query. * [DRT] SimpleDatabaseSystem uses quota_per_origin_ data member to respond to the SpaceAvailable query. * Mostly mind numbing plumbing for WebKit API additions. // Sync getter for use on webcore's background db threads to // call out to chrome to get the value. long long WebKitClient::databaseGetSpaceAvailableForOrigin(origin_identifier); // Split the existing updateDatabaseSize method into three methods. Chrome calls into these. static void WebDatabase::updateDatabaseSize(originIdentifier, dbname, spaceAvailable); static void WebDatabase::updateSpaceAvailable(originIdentifier, spaceAvailable); static void WebDatabase::resetSpaceAvailable(originIdentifier); Review URL: http://codereview.chromium.org/7037018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-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
11 files changed, 156 insertions, 36 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();