Commit db4d4981 authored by michaeln@google.com's avatar michaeln@google.com

Use the QuotaManager to determine the space available to WebSQLDatabases....

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
parent 80c2915f
......@@ -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));
}
}
......
......@@ -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,
......
......@@ -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 */,
......
......@@ -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;
}
......@@ -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_
......@@ -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(
......
......@@ -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);
};
......
......@@ -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*
......
......@@ -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,
......
......@@ -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(
......
......@@ -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();
......
......@@ -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_; }
......
......@@ -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,
......
......@@ -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);
......
......@@ -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());
......
......@@ -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_;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
......
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