summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authormkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-01 16:23:40 +0000
committermkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-01 16:23:40 +0000
commit94704173af5f1f377246351d2db3bc5106692df5 (patch)
treedb35e55da44431240ef29d2e8940705f8019f645 /webkit
parenta0ae316fef92606969c083f696609516ea7b8e1e (diff)
downloadchromium_src-94704173af5f1f377246351d2db3bc5106692df5.zip
chromium_src-94704173af5f1f377246351d2db3bc5106692df5.tar.gz
chromium_src-94704173af5f1f377246351d2db3bc5106692df5.tar.bz2
Time-based removal of temporary file systems via BrowsingDataRemover
QuotaManager takes over much of the functionality that BrowsingDataRemover implemented for FileSystem and Appcache removal. It also handles WebSQL databases, but I've left the database deletion in, as IndexedDBs aren't yet handled correctly, so we need to take care of them explicitly. BUG=63700 TEST=unit_tests, test_shell_tests Review URL: http://codereview.chromium.org/7129018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94913 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/quota/mock_quota_manager.cc136
-rw-r--r--webkit/quota/mock_quota_manager.h83
-rw-r--r--webkit/quota/mock_quota_manager_unittest.cc171
-rw-r--r--webkit/quota/quota_manager.h18
-rw-r--r--webkit/tools/test_shell/test_shell.gypi3
5 files changed, 403 insertions, 8 deletions
diff --git a/webkit/quota/mock_quota_manager.cc b/webkit/quota/mock_quota_manager.cc
new file mode 100644
index 0000000..9df3c6b
--- /dev/null
+++ b/webkit/quota/mock_quota_manager.cc
@@ -0,0 +1,136 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/quota/mock_quota_manager.h"
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/quota/quota_client.h"
+#include "webkit/quota/quota_manager.h"
+#include "webkit/quota/quota_task.h"
+#include "webkit/quota/quota_types.h"
+
+namespace quota {
+
+class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
+ public:
+ GetModifiedSinceTask(MockQuotaManager* manager,
+ const std::set<GURL>& origins,
+ GetOriginsCallback* callback)
+ : QuotaThreadTask(manager, manager->io_thread_),
+ origins_(origins),
+ callback_(callback) {}
+
+ protected:
+ virtual void RunOnTargetThread() OVERRIDE {}
+
+ virtual void Completed() OVERRIDE {
+ callback_->Run(origins_);
+ }
+
+ virtual void Aborted() OVERRIDE {
+ callback_->Run(std::set<GURL>());
+ }
+
+ private:
+ std::set<GURL> origins_;
+ scoped_ptr<GetOriginsCallback> callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(GetModifiedSinceTask);
+};
+
+class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask {
+ public:
+ DeleteOriginDataTask(MockQuotaManager* manager,
+ StatusCallback* callback)
+ : QuotaThreadTask(manager, manager->io_thread_),
+ callback_(callback) {}
+
+ protected:
+ virtual void RunOnTargetThread() OVERRIDE {}
+
+ virtual void Completed() OVERRIDE {
+ callback_->Run(quota::kQuotaStatusOk);
+ }
+
+ virtual void Aborted() OVERRIDE {
+ callback_->Run(quota::kQuotaErrorAbort);
+ }
+
+ private:
+ scoped_ptr<StatusCallback> callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask);
+};
+
+MockQuotaManager::OriginInfo::OriginInfo(
+ const GURL& origin,
+ StorageType type,
+ base::Time modified)
+ : origin(origin),
+ type(type),
+ modified(modified) {
+}
+
+MockQuotaManager::OriginInfo::~OriginInfo() {}
+
+MockQuotaManager::MockQuotaManager(bool is_incognito,
+ const FilePath& profile_path, base::MessageLoopProxy* io_thread,
+ base::MessageLoopProxy* db_thread,
+ SpecialStoragePolicy* special_storage_policy)
+ : QuotaManager(is_incognito, profile_path, io_thread, db_thread,
+ special_storage_policy) {
+}
+
+MockQuotaManager::~MockQuotaManager() {}
+
+bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type,
+ base::Time modified) {
+ origins_.push_back(OriginInfo(origin, type, modified));
+ return true;
+}
+
+bool MockQuotaManager::OriginHasData(const GURL& origin,
+ StorageType type) const {
+ for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
+ current != origins_.end();
+ ++current) {
+ if (current->origin == origin && current->type == type)
+ return true;
+ }
+ return false;
+}
+
+void MockQuotaManager::GetOriginsModifiedSince(StorageType type,
+ base::Time modified_since, GetOriginsCallback* callback) {
+ std::set<GURL> origins_to_return;
+ for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
+ current != origins_.end();
+ ++current) {
+ if (current->type == type && current->modified >= modified_since)
+ origins_to_return.insert(current->origin);
+ }
+ make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return,
+ callback))->Start();
+}
+
+void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type,
+ StatusCallback* callback) {
+ for (std::vector<OriginInfo>::iterator current = origins_.begin();
+ current != origins_.end();
+ ++current) {
+ if (current->origin == origin && current->type == type) {
+ origins_.erase(current);
+ break;
+ }
+ }
+ make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start();
+}
+
+} // namespace quota
diff --git a/webkit/quota/mock_quota_manager.h b/webkit/quota/mock_quota_manager.h
new file mode 100644
index 0000000..636404d
--- /dev/null
+++ b/webkit/quota/mock_quota_manager.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_QUOTA_MOCK_QUOTA_MANAGER_H_
+#define WEBKIT_QUOTA_MOCK_QUOTA_MANAGER_H_
+#pragma once
+
+#include <vector>
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/quota/quota_client.h"
+#include "webkit/quota/quota_manager.h"
+#include "webkit/quota/quota_task.h"
+#include "webkit/quota/quota_types.h"
+
+namespace quota {
+
+// Mocks the pieces of QuotaManager's interface that are used for time-based
+// deletion of a profile's browsing data. Origins can be added to the mock by
+// calling AddOrigin, and that list of origins is then searched through in
+// GetOriginsModifiedSince. Neither GetOriginsModifiedSince nor DeleteOriginData
+// touches the actual origin data stored in the profile.
+class MockQuotaManager : public QuotaManager {
+ public:
+ // Contains the essential bits of information about an origin that the
+ // MockQuotaManager needs to understand: the origin itself, the StorageType,
+ // and its modification time.
+ struct OriginInfo {
+ OriginInfo(const GURL& origin,
+ StorageType type,
+ base::Time modified);
+ ~OriginInfo();
+
+ GURL origin;
+ StorageType type;
+ base::Time modified;
+ };
+
+ MockQuotaManager(bool is_incognito,
+ const FilePath& profile_path,
+ base::MessageLoopProxy* io_thread,
+ base::MessageLoopProxy* db_thread,
+ SpecialStoragePolicy* special_storage_policy);
+
+ virtual ~MockQuotaManager();
+
+ // Adds an origin to the canned list that will be searched through via
+ // GetOriginsModifiedSince.
+ bool AddOrigin(const GURL& origin, StorageType type, base::Time modified);
+
+ // Checks an origin and type against the origins that have been added via
+ // AddOrigin and removed via DeleteOriginData. If the origin exists in the
+ // canned list with the proper StorageType, returns true.
+ bool OriginHasData(const GURL& origin, StorageType type) const;
+
+ // Overrides QuotaManager's implementation with a canned implementation that
+ // allows clients to set up the origin database that should be queried. This
+ // method will only search through the origins added explicitly via AddOrigin.
+ virtual void GetOriginsModifiedSince(StorageType type,
+ base::Time modified_since,
+ GetOriginsCallback* callback) OVERRIDE;
+
+ // Removes an origin from the canned list of origins, but doesn't touch
+ // anything on disk.
+ virtual void DeleteOriginData(const GURL& origin,
+ StorageType type,
+ StatusCallback* callback) OVERRIDE;
+ private:
+ class GetModifiedSinceTask;
+ class DeleteOriginDataTask;
+
+ // The list of stored origins that have been added via AddOrigin.
+ std::vector<OriginInfo> origins_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockQuotaManager);
+};
+
+} // namespace quota
+
+#endif // WEBKIT_QUOTA_MOCK_QUOTA_MANAGER_H_
diff --git a/webkit/quota/mock_quota_manager_unittest.cc b/webkit/quota/mock_quota_manager_unittest.cc
new file mode 100644
index 0000000..ee6a101
--- /dev/null
+++ b/webkit/quota/mock_quota_manager_unittest.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+#include <set>
+
+#include "base/file_util.h"
+#include "base/memory/scoped_callback_factory.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/scoped_temp_dir.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/quota/mock_quota_manager.h"
+#include "webkit/quota/mock_special_storage_policy.h"
+#include "webkit/quota/mock_storage_client.h"
+
+namespace quota {
+
+const char kTestOrigin1[] = "http://host1:1/";
+const char kTestOrigin2[] = "http://host2:1/";
+const char kTestOrigin3[] = "http://host3:1/";
+
+const GURL kOrigin1(kTestOrigin1);
+const GURL kOrigin2(kTestOrigin2);
+const GURL kOrigin3(kTestOrigin3);
+
+class MockQuotaManagerTest : public testing::Test {
+ public:
+ MockQuotaManagerTest()
+ : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ deletion_callback_count_(0) {
+ }
+
+ void SetUp() {
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
+ policy_ = new MockSpecialStoragePolicy;
+ manager_ = new MockQuotaManager(
+ false /* is_incognito */,
+ data_dir_.path(),
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ policy_);
+ }
+
+ void TearDown() {
+ // Make sure the quota manager cleans up correctly.
+ manager_ = NULL;
+ MessageLoop::current()->RunAllPending();
+ }
+
+ void GetModifiedOrigins(StorageType type, base::Time since) {
+ manager_->GetOriginsModifiedSince(type, since,
+ callback_factory_.NewCallback(
+ &MockQuotaManagerTest::GotModifiedOrigins));
+ }
+
+ void GotModifiedOrigins(const std::set<GURL>& origins) {
+ origins_ = origins;
+ }
+
+ void DeleteOriginData(const GURL& origin, StorageType type) {
+ manager_->DeleteOriginData(origin, type,
+ callback_factory_.NewCallback(
+ &MockQuotaManagerTest::DeletedOriginData));
+ }
+
+ void DeletedOriginData(QuotaStatusCode status) {
+ ++deletion_callback_count_;
+ EXPECT_EQ(quota::kQuotaStatusOk, status);
+ }
+
+ int GetDeletionCallbackCount() {
+ return deletion_callback_count_;
+ }
+
+ MockQuotaManager* GetManager() {
+ return manager_.get();
+ }
+
+ const std::set<GURL> GetOrigins() {
+ return origins_;
+ }
+
+ private:
+ ScopedTempDir data_dir_;
+ base::ScopedCallbackFactory<MockQuotaManagerTest> callback_factory_;
+ scoped_refptr<MockQuotaManager> manager_;
+ scoped_refptr<MockSpecialStoragePolicy> policy_;
+
+ int deletion_callback_count_;
+
+ std::set<GURL> origins_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerTest);
+};
+
+TEST_F(MockQuotaManagerTest, BasicOriginManipulation) {
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin1, kStorageTypeTemporary));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypeTemporary));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin1, kStorageTypePersistent));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypePersistent));
+
+ GetManager()->AddOrigin(kOrigin1, kStorageTypeTemporary, base::Time::Now());
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin1, kStorageTypeTemporary));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypeTemporary));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin1, kStorageTypePersistent));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypePersistent));
+
+ GetManager()->AddOrigin(kOrigin1, kStorageTypePersistent, base::Time::Now());
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin1, kStorageTypeTemporary));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypeTemporary));
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin1, kStorageTypePersistent));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypePersistent));
+
+ GetManager()->AddOrigin(kOrigin2, kStorageTypeTemporary, base::Time::Now());
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin1, kStorageTypeTemporary));
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin2, kStorageTypeTemporary));
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin1, kStorageTypePersistent));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypePersistent));
+}
+
+TEST_F(MockQuotaManagerTest, OriginDeletion) {
+ GetManager()->AddOrigin(kOrigin1, kStorageTypeTemporary, base::Time::Now());
+ GetManager()->AddOrigin(kOrigin2, kStorageTypeTemporary, base::Time::Now());
+
+ DeleteOriginData(kOrigin2, kStorageTypeTemporary);
+ MessageLoop::current()->RunAllPending();
+
+ EXPECT_EQ(1, GetDeletionCallbackCount());
+ EXPECT_TRUE(GetManager()->OriginHasData(kOrigin1, kStorageTypeTemporary));
+ EXPECT_FALSE(GetManager()->OriginHasData(kOrigin2, kStorageTypeTemporary));
+}
+
+TEST_F(MockQuotaManagerTest, ModifiedOrigins) {
+ base::Time now = base::Time::Now();
+ base::Time then = base::Time();
+ base::TimeDelta an_hour = base::TimeDelta::FromMilliseconds(3600000);
+ base::TimeDelta a_minute = base::TimeDelta::FromMilliseconds(60000);
+
+ GetModifiedOrigins(kStorageTypeTemporary, then);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_TRUE(GetOrigins().empty());
+
+ GetManager()->AddOrigin(kOrigin1, kStorageTypeTemporary, now - an_hour);
+
+ GetModifiedOrigins(kStorageTypeTemporary, then);
+ MessageLoop::current()->RunAllPending();
+
+ EXPECT_EQ(1UL, GetOrigins().size());
+ EXPECT_EQ(1UL, GetOrigins().count(kOrigin1));
+ EXPECT_EQ(0UL, GetOrigins().count(kOrigin2));
+
+ GetManager()->AddOrigin(kOrigin2, kStorageTypeTemporary, now);
+
+ GetModifiedOrigins(kStorageTypeTemporary, then);
+ MessageLoop::current()->RunAllPending();
+
+ EXPECT_EQ(2UL, GetOrigins().size());
+ EXPECT_EQ(1UL, GetOrigins().count(kOrigin1));
+ EXPECT_EQ(1UL, GetOrigins().count(kOrigin2));
+
+ GetModifiedOrigins(kStorageTypeTemporary, now - a_minute);
+ MessageLoop::current()->RunAllPending();
+
+ EXPECT_EQ(1UL, GetOrigins().size());
+ EXPECT_EQ(0UL, GetOrigins().count(kOrigin1));
+ EXPECT_EQ(1UL, GetOrigins().count(kOrigin2));
+}
+} // Namespace quota
diff --git a/webkit/quota/quota_manager.h b/webkit/quota/quota_manager.h
index 6701f08..f309338 100644
--- a/webkit/quota/quota_manager.h
+++ b/webkit/quota/quota_manager.h
@@ -25,10 +25,11 @@
#include "webkit/quota/quota_types.h"
#include "webkit/quota/special_storage_policy.h"
+class FilePath;
+
namespace base {
class MessageLoopProxy;
}
-class FilePath;
namespace quota_internals {
class QuotaInternalsProxy;
@@ -42,6 +43,7 @@ class QuotaDatabase;
class QuotaManagerProxy;
class QuotaTemporaryStorageEvictor;
class UsageTracker;
+class MockQuotaManager;
// An interface called by QuotaTemporaryStorageEvictor.
class QuotaEvictionHandler {
@@ -126,9 +128,9 @@ class QuotaManager : public QuotaTaskObserver,
}
// Called by UI.
- void DeleteOriginData(const GURL& origin,
- StorageType type,
- StatusCallback* callback);
+ virtual void DeleteOriginData(const GURL& origin,
+ StorageType type,
+ StatusCallback* callback);
// Called by UI and internal modules.
void GetAvailableSpace(AvailableSpaceCallback* callback);
@@ -150,10 +152,9 @@ class QuotaManager : public QuotaTaskObserver,
special_storage_policy_->IsStorageUnlimited(origin);
}
- void GetOriginsModifiedSince(
- StorageType type,
- base::Time modified_since,
- GetOriginsCallback* callback);
+ virtual void GetOriginsModifiedSince(StorageType type,
+ base::Time modified_since,
+ GetOriginsCallback* callback);
bool ResetUsageTracker(StorageType type);
@@ -235,6 +236,7 @@ class QuotaManager : public QuotaTaskObserver,
friend class QuotaManagerProxy;
friend class QuotaManagerTest;
friend class QuotaTemporaryStorageEvictor;
+ friend class MockQuotaManager;
// This initialization method is lazily called on the IO thread
// when the first quota manager API is called.
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index a90900a..9a724e5 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -451,6 +451,9 @@
'../../quota/mock_special_storage_policy.h',
'../../quota/mock_storage_client.cc',
'../../quota/mock_storage_client.h',
+ '../../quota/mock_quota_manager.cc',
+ '../../quota/mock_quota_manager.h',
+ '../../quota/mock_quota_manager_unittest.cc',
'../../quota/quota_database_unittest.cc',
'../../quota/quota_manager_unittest.cc',
'../../quota/quota_temporary_storage_evictor_unittest.cc',