diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/database/database_tracker.h | 20 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 5 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 2 | ||||
-rw-r--r-- | webkit/support/simple_database_system.cc | 42 | ||||
-rw-r--r-- | webkit/support/simple_database_system.h | 4 | ||||
-rw-r--r-- | webkit/support/test_webkit_client.cc | 9 | ||||
-rw-r--r-- | webkit/support/test_webkit_client.h | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.cc | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 2 |
9 files changed, 78 insertions, 14 deletions
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); |