summaryrefslogtreecommitdiffstats
path: root/webkit/quota
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 03:31:31 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 03:31:31 +0000
commit4b66b659788f41749e431b109b89ce8aa67952f4 (patch)
treef2b497ba81493714b2363740b080486281a3cf51 /webkit/quota
parent74aafb471d019ab7e6197d19fc58e32c430f5c38 (diff)
downloadchromium_src-4b66b659788f41749e431b109b89ce8aa67952f4.zip
chromium_src-4b66b659788f41749e431b109b89ce8aa67952f4.tar.gz
chromium_src-4b66b659788f41749e431b109b89ce8aa67952f4.tar.bz2
Added DeleteOriginData to QuotaClient
BUG=61676 TEST=SandboxQuotaClientTest.DeleteOriginTest Review URL: http://codereview.chromium.org/7003021 Patch from Taiju Tsuiki <tzik@google.com>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota')
-rw-r--r--webkit/quota/mock_storage_client.cc30
-rw-r--r--webkit/quota/mock_storage_client.h7
-rw-r--r--webkit/quota/quota_client.h9
-rw-r--r--webkit/quota/quota_manager.h2
-rw-r--r--webkit/quota/quota_manager_unittest.cc55
5 files changed, 99 insertions, 4 deletions
diff --git a/webkit/quota/mock_storage_client.cc b/webkit/quota/mock_storage_client.cc
index e2e8a69..39958d1 100644
--- a/webkit/quota/mock_storage_client.cc
+++ b/webkit/quota/mock_storage_client.cc
@@ -52,6 +52,8 @@ MockStorageClient::~MockStorageClient() {
STLDeleteContainerPointers(usage_callbacks_.begin(), usage_callbacks_.end());
STLDeleteContainerPointers(
origins_callbacks_.begin(), origins_callbacks_.end());
+ STLDeleteContainerPointers(
+ deletion_callbacks_.begin(), deletion_callbacks_.end());
}
void MockStorageClient::AddMockOriginData(
@@ -111,6 +113,16 @@ void MockStorageClient::GetOriginsForHost(
type, host, callback));
}
+void MockStorageClient::DeleteOriginData(
+ const GURL& origin, StorageType type,
+ DeletionCallback* callback) {
+ deletion_callbacks_.insert(callback);
+ base::MessageLoopProxy::CreateForCurrentThread()->PostTask(
+ FROM_HERE, runnable_factory_.NewRunnableMethod(
+ &MockStorageClient::RunDeleteOriginData,
+ origin, type, callback));
+}
+
void MockStorageClient::RunGetOriginUsage(
const GURL& origin_url, StorageType type, GetUsageCallback* callback_ptr) {
usage_callbacks_.erase(callback_ptr);
@@ -151,4 +163,22 @@ void MockStorageClient::RunGetOriginsForHost(
callback->Run(origins);
}
+void MockStorageClient::RunDeleteOriginData(
+ const GURL& origin_url,
+ StorageType type,
+ DeletionCallback* callback_ptr) {
+ OriginDataMap::iterator itr
+ = origin_data_.find(make_pair(origin_url, type));
+ if (itr != origin_data_.end()) {
+ int64 delta = itr->second;
+ quota_manager_proxy_->
+ NotifyStorageModified(id(), origin_url, type, -delta);
+ origin_data_.erase(itr);
+ }
+
+ scoped_ptr<DeletionCallback> callback(callback_ptr);
+ deletion_callbacks_.erase(callback_ptr);
+ callback->Run(kQuotaStatusOk);
+}
+
} // namespace quota
diff --git a/webkit/quota/mock_storage_client.h b/webkit/quota/mock_storage_client.h
index cf0299a..6d8def2 100644
--- a/webkit/quota/mock_storage_client.h
+++ b/webkit/quota/mock_storage_client.h
@@ -39,6 +39,9 @@ class MockStorageClient : public QuotaClient {
GetOriginsCallback* callback) OVERRIDE;
virtual void GetOriginsForHost(StorageType type, const std::string& host,
GetOriginsCallback* callback) OVERRIDE;
+ virtual void DeleteOriginData(const GURL& origin,
+ StorageType type,
+ DeletionCallback* callback) OVERRIDE;
private:
void RunGetOriginUsage(const GURL& origin_url,
@@ -49,6 +52,9 @@ class MockStorageClient : public QuotaClient {
void RunGetOriginsForHost(StorageType type,
const std::string& host,
GetOriginsCallback* callback);
+ void RunDeleteOriginData(const GURL& origin_url,
+ StorageType type,
+ DeletionCallback* callback);
scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
const ID id_;
@@ -58,6 +64,7 @@ class MockStorageClient : public QuotaClient {
std::set<GetUsageCallback*> usage_callbacks_;
std::set<GetOriginsCallback*> origins_callbacks_;
+ std::set<DeletionCallback*> deletion_callbacks_;
ScopedRunnableMethodFactory<MockStorageClient> runnable_factory_;
diff --git a/webkit/quota/quota_client.h b/webkit/quota/quota_client.h
index 3e46159..d9499eb 100644
--- a/webkit/quota/quota_client.h
+++ b/webkit/quota/quota_client.h
@@ -5,8 +5,9 @@
#ifndef WEBKIT_QUOTA_QUOTA_CLIENT_H_
#define WEBKIT_QUOTA_QUOTA_CLIENT_H_
-#include <set>
#include <list>
+#include <set>
+#include <string>
#include "base/callback_old.h"
#include "base/time.h"
@@ -23,6 +24,7 @@ class QuotaClient {
public:
typedef Callback1<int64>::Type GetUsageCallback;
typedef Callback1<const std::set<GURL>&>::Type GetOriginsCallback;
+ typedef Callback1<QuotaStatusCode>::Type DeletionCallback;
virtual ~QuotaClient() {}
@@ -57,6 +59,11 @@ class QuotaClient {
virtual void GetOriginsForHost(StorageType type,
const std::string& host,
GetOriginsCallback* callback) = 0;
+
+ // Called by the QuotaManager.
+ virtual void DeleteOriginData(const GURL& origin,
+ StorageType type,
+ DeletionCallback* callback) = 0;
};
typedef std::list<QuotaClient*> QuotaClientList;
diff --git a/webkit/quota/quota_manager.h b/webkit/quota/quota_manager.h
index 0d63c84..955cab5 100644
--- a/webkit/quota/quota_manager.h
+++ b/webkit/quota/quota_manager.h
@@ -14,9 +14,9 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/ref_counted.h"
#include "webkit/quota/quota_client.h"
#include "webkit/quota/quota_task.h"
#include "webkit/quota/quota_types.h"
diff --git a/webkit/quota/quota_manager_unittest.cc b/webkit/quota/quota_manager_unittest.cc
index fd6e671..3c519b4 100644
--- a/webkit/quota/quota_manager_unittest.cc
+++ b/webkit/quota/quota_manager_unittest.cc
@@ -4,8 +4,6 @@
#include <vector>
-#include "testing/gtest/include/gtest/gtest.h"
-
#include "base/file_util.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
@@ -13,6 +11,7 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/stl_util-inl.h"
+#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"
#include "webkit/quota/mock_storage_client.h"
@@ -132,6 +131,15 @@ class QuotaManagerTest : public testing::Test {
&QuotaManagerTest::DidGetUsageAndQuotaAdditional));
}
+ void DeleteOriginData(QuotaClient* client,
+ const GURL& origin,
+ StorageType type) {
+ quota_status_ = kQuotaStatusUnknown;
+ client->DeleteOriginData(origin, type,
+ callback_factory_.NewCallback(
+ &QuotaManagerTest::DidDelete));
+ }
+
void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) {
quota_status_ = status;
usage_ = usage;
@@ -158,6 +166,10 @@ class QuotaManagerTest : public testing::Test {
usage_ = usage;
}
+ void DidDelete(QuotaStatusCode status) {
+ quota_status_ = status;
+ }
+
void set_additional_callback_count(int c) { additional_callback_count_ = c; }
int additional_callback_count() const { return additional_callback_count_; }
void DidGetUsageAndQuotaAdditional(
@@ -667,4 +679,43 @@ TEST_F(QuotaManagerTest, GetUsage_WithModification) {
EXPECT_EQ(usage(), 4000 + 50000 + 900000000);
}
+TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) {
+ static const MockOriginData kData[] = {
+ { "http://foo.com/", kStorageTypeTemporary, 1 },
+ { "http://foo.com:1/", kStorageTypeTemporary, 20 },
+ { "http://foo.com/", kStorageTypePersistent, 300 },
+ { "http://bar.com/", kStorageTypeTemporary, 4000 },
+ };
+ MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData));
+ RegisterClient(client);
+
+ GetGlobalUsage(kStorageTypeTemporary);
+ MessageLoop::current()->RunAllPending();
+ int64 predelete_global_tmp = usage();
+
+ GetHostUsage("foo.com", kStorageTypeTemporary);
+ MessageLoop::current()->RunAllPending();
+ int64 predelete_host_tmp = usage();
+
+ GetHostUsage("foo.com", kStorageTypePersistent);
+ MessageLoop::current()->RunAllPending();
+ int64 predelete_host_pers = usage();
+
+ DeleteOriginData(client, GURL("http://foo.com/"), kStorageTypeTemporary);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(kQuotaStatusOk, status());
+
+ GetGlobalUsage(kStorageTypeTemporary);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(predelete_global_tmp - 1, usage());
+
+ GetHostUsage("foo.com", kStorageTypeTemporary);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(predelete_host_tmp - 1, usage());
+
+ GetHostUsage("foo.com", kStorageTypePersistent);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(predelete_host_pers, usage());
+}
+
} // namespace quota