Chromium Code Reviews| Index: content/browser/renderer_host/database_message_filter.cc |
| =================================================================== |
| --- content/browser/renderer_host/database_message_filter.cc (revision 85641) |
| +++ content/browser/renderer_host/database_message_filter.cc (working copy) |
| @@ -16,19 +16,50 @@ |
| #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) { |
| + // Params are <status, usage, quota> |
|
darin (slow to review)
2011/05/24 04:56:11
nit: create local variables with these names? it
michaeln
2011/05/24 19:43:10
Done.
|
| + int64 available = 0; |
| + if ((params.a == quota::kQuotaStatusOk) && (params.b < params.c)) |
| + available = params.c - params.b; |
| + 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 +84,23 @@ |
| 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 +121,8 @@ |
| 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 +254,7 @@ |
| } |
| 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 +266,40 @@ |
| 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; |
| + int64 space_available_not_used = 0; |
| + db_tracker_->DatabaseOpened(origin_identifier, database_name, description, |
| + estimated_size, &database_size, |
| + &space_available_not_used); |
| database_connections_.AddConnection(origin_identifier, database_name); |
| - db_tracker_->DatabaseOpened(origin_identifier, database_name, description, |
| - estimated_size, &database_size, &space_available); |
| Send(new DatabaseMsg_UpdateSize(origin_identifier, database_name, |
| - database_size, space_available)); |
| + database_size)); |
| } |
| void DatabaseMessageFilter::OnDatabaseModified( |
| @@ -270,19 +326,19 @@ |
| return; |
| } |
| + database_connections_.RemoveConnection(origin_identifier, database_name); |
| db_tracker_->DatabaseClosed(origin_identifier, database_name); |
| - database_connections_.RemoveConnection(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)); |
| } |
| } |