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* filter, IPC::Message* reply_msg) |
| + : reply_msg_(reply_msg) {} |
| + |
| + virtual void RunWithParams( |
| + const Tuple3<QuotaStatusCode, int64, int64>& params) { |
| + // Params are <status, usage, quota> |
| + int64 available = 0; |
| + if ((params.a == quota::kQuotaStatusOk) && (params.b < params.c)) |
| + available = params.c - params.b; |
| + DatabaseHostMsg_GetSpaceAvailable::WriteReplyParams( |
| + reply_msg_.get(), available); |
| + filter_->Send(reply_msg_.release()); |
| + } |
| + |
| + private: |
| + scoped_refptr<DatabaseMessageFilter> filter_; |
| + 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), |
| @@ -65,10 +96,12 @@ |
| 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 +122,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 +255,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 +267,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, 0LL); |
| + Send(reply_msg); |
| + return; |
| + } |
| + |
| + // TODO(michaeln): Is there a different API that should be used for this? |
| + quota_manager->GetUsageAndQuota( |
|
michaeln
2011/05/19 07:03:34
Hi Kinuko, my local build got into an odd state wh
|
| + 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; |
| database_connections_.AddConnection(origin_identifier, database_name); |
| db_tracker_->DatabaseOpened(origin_identifier, database_name, description, |
| - estimated_size, &database_size, &space_available); |
| + estimated_size, &database_size, |
| + &space_available_not_used); |
| Send(new DatabaseMsg_UpdateSize(origin_identifier, database_name, |
| - database_size, space_available)); |
| + database_size)); |
| } |
| void DatabaseMessageFilter::OnDatabaseModified( |
| @@ -278,11 +335,11 @@ |
| 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)); |
| } |
| } |