diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 04:31:17 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 04:31:17 +0000 |
commit | 4f271522c62764add4e828c014dd54cdcebf5d8a (patch) | |
tree | a2de7ce3b5e824e5cdf4686c1fd7f796fa2ba291 /webkit/quota | |
parent | 4c9042348038907cdc36bb33eeeecffd6332bf8f (diff) | |
download | chromium_src-4f271522c62764add4e828c014dd54cdcebf5d8a.zip chromium_src-4f271522c62764add4e828c014dd54cdcebf5d8a.tar.gz chromium_src-4f271522c62764add4e828c014dd54cdcebf5d8a.tar.bz2 |
Don't crash when quota is queried on file:///
BUG=none
TEST=QuotaManagerTest.QuotaForEmptyHost
Review URL: http://codereview.chromium.org/7020016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota')
-rw-r--r-- | webkit/quota/quota_manager.cc | 27 | ||||
-rw-r--r-- | webkit/quota/quota_manager_unittest.cc | 11 |
2 files changed, 30 insertions, 8 deletions
diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc index 2d89d5a..0688ec0 100644 --- a/webkit/quota/quota_manager.cc +++ b/webkit/quota/quota_manager.cc @@ -474,7 +474,6 @@ class QuotaManager::PersistentHostQuotaQueryTask host_(host), quota_(-1), callback_(callback) { - DCHECK(!host_.empty()); } protected: virtual void RunOnTargetThread() OVERRIDE { @@ -505,7 +504,6 @@ class QuotaManager::PersistentHostQuotaUpdateTask host_(host), new_quota_(new_quota), callback_(callback) { - DCHECK(!host_.empty()); DCHECK_GE(new_quota_, 0); } protected: @@ -894,34 +892,47 @@ void QuotaManager::SetTemporaryGlobalQuota(int64 new_quota, } void QuotaManager::GetPersistentHostQuota(const std::string& host, - HostQuotaCallback* callback) { + HostQuotaCallback* callback_ptr) { + scoped_ptr<HostQuotaCallback> callback(callback_ptr); LazyInitialize(); + if (host.empty()) { + // This could happen if we are called on file:///. + // TODO(kinuko) We may want to respect --allow-file-access-from-files + // command line switch. + callback->Run(kQuotaStatusOk, host, kStorageTypePersistent, 0); + return; + } scoped_refptr<PersistentHostQuotaQueryTask> task( new PersistentHostQuotaQueryTask( - this, database_.get(), db_thread_, host, callback)); + this, database_.get(), db_thread_, host, callback.release())); task->Start(); } void QuotaManager::SetPersistentHostQuota(const std::string& host, int64 new_quota, - HostQuotaCallback* callback) { + HostQuotaCallback* callback_ptr) { + scoped_ptr<HostQuotaCallback> callback(callback_ptr); LazyInitialize(); + if (host.empty()) { + // This could happen if we are called on file:///. + callback->Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0); + return; + } if (new_quota < 0) { callback->Run(kQuotaErrorInvalidModification, host, kStorageTypePersistent, -1); - delete callback; return; } if (!db_disabled_) { scoped_refptr<PersistentHostQuotaUpdateTask> task( new PersistentHostQuotaUpdateTask( - this, database_.get(), db_thread_, host, new_quota, callback)); + this, database_.get(), db_thread_, host, new_quota, + callback.release())); task->Start(); } else { callback->Run(kQuotaErrorInvalidAccess, host, kStorageTypePersistent, -1); - delete callback; } } diff --git a/webkit/quota/quota_manager_unittest.cc b/webkit/quota/quota_manager_unittest.cc index 4df5787..db9b960 100644 --- a/webkit/quota/quota_manager_unittest.cc +++ b/webkit/quota/quota_manager_unittest.cc @@ -1377,4 +1377,15 @@ TEST_F(QuotaManagerTest, DumpLastAccessTimeTable) { } EXPECT_TRUE(entries.empty()); } + +TEST_F(QuotaManagerTest, QuotaForEmptyHost) { + GetPersistentHostQuota(std::string()); + MessageLoop::current()->RunAllPending(); + EXPECT_EQ(kQuotaStatusOk, status()); + EXPECT_EQ(0, quota()); + + SetPersistentHostQuota(std::string(), 10); + MessageLoop::current()->RunAllPending(); + EXPECT_EQ(kQuotaErrorNotSupported, status()); +} } // namespace quota |