Commit 98bc4499 authored by dgrogan@chromium.org's avatar dgrogan@chromium.org

Implement GetOrigins for indexeddb quota

BUG=83652
TEST=llvm/Debug/unit_tests --gtest_filter=IndexedDBQuotaClientTest.* && llvm/Debug/browser_tests --gtest_filter=IndexedDBBrowser*:BrowsingDataIndexedDBHelperTest.*

Review URL: http://codereview.chromium.org/7310022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91796 0039d316-1c4b-4281-b951-d872f2087c98
parent 354a4d6b
...@@ -65,8 +65,8 @@ IndexedDBContext::IndexedDBContext( ...@@ -65,8 +65,8 @@ IndexedDBContext::IndexedDBContext(
special_storage_policy_(special_storage_policy) { special_storage_policy_(special_storage_policy) {
data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory); data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory);
if (quota_manager_proxy) { if (quota_manager_proxy) {
// quota_manager_proxy->RegisterClient( quota_manager_proxy->RegisterClient(
// new IndexedDBQuotaClient(webkit_thread_loop, this)); new IndexedDBQuotaClient(webkit_thread_loop, this));
} }
} }
...@@ -118,3 +118,20 @@ bool IndexedDBContext::IsUnlimitedStorageGranted( ...@@ -118,3 +118,20 @@ bool IndexedDBContext::IsUnlimitedStorageGranted(
const GURL& origin) const { const GURL& origin) const {
return special_storage_policy_->IsStorageUnlimited(origin); return special_storage_policy_->IsStorageUnlimited(origin);
} }
// TODO(dgrogan): Merge this code with the similar loop in
// BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread.
void IndexedDBContext::GetAllOriginIdentifiers(
std::vector<string16>* origin_ids) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
file_util::FileEnumerator file_enumerator(data_path_,
false, file_util::FileEnumerator::DIRECTORIES);
for (FilePath file_path = file_enumerator.Next(); !file_path.empty();
file_path = file_enumerator.Next()) {
if (file_path.Extension() == IndexedDBContext::kIndexedDBExtension) {
WebKit::WebString origin_id_webstring =
webkit_glue::FilePathToWebString(file_path.BaseName());
origin_ids->push_back(origin_id_webstring);
}
}
}
...@@ -62,6 +62,8 @@ class IndexedDBContext : public base::RefCountedThreadSafe<IndexedDBContext> { ...@@ -62,6 +62,8 @@ class IndexedDBContext : public base::RefCountedThreadSafe<IndexedDBContext> {
// Does a particular origin get unlimited storage? // Does a particular origin get unlimited storage?
bool IsUnlimitedStorageGranted(const GURL& origin) const; bool IsUnlimitedStorageGranted(const GURL& origin) const;
void GetAllOriginIdentifiers(std::vector<string16>* origin_ids);
#ifdef UNIT_TEST #ifdef UNIT_TEST
// For unit tests allow to override the |data_path_|. // For unit tests allow to override the |data_path_|.
void set_data_path(const FilePath& data_path) { data_path_ = data_path; } void set_data_path(const FilePath& data_path) { data_path_ = data_path; }
......
...@@ -66,7 +66,15 @@ class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { ...@@ -66,7 +66,15 @@ class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask {
virtual bool ShouldAddOrigin(const GURL& origin) = 0; virtual bool ShouldAddOrigin(const GURL& origin) = 0;
virtual void RunOnTargetThread() OVERRIDE { virtual void RunOnTargetThread() OVERRIDE {
// TODO(dgrogan): Implement. std::vector<string16> origin_identifiers;
indexed_db_context_->GetAllOriginIdentifiers(&origin_identifiers);
for (std::vector<string16>::const_iterator iter =
origin_identifiers.begin();
iter != origin_identifiers.end(); ++iter) {
GURL origin = DatabaseUtil::GetOriginFromIdentifier(*iter);
if (ShouldAddOrigin(origin))
origins_.insert(origin);
}
} }
std::set<GURL> origins_; std::set<GURL> origins_;
......
...@@ -27,10 +27,12 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -27,10 +27,12 @@ class IndexedDBQuotaClientTest : public testing::Test {
public: public:
const GURL kOriginA; const GURL kOriginA;
const GURL kOriginB; const GURL kOriginB;
const GURL kOriginOther;
IndexedDBQuotaClientTest() IndexedDBQuotaClientTest()
: kOriginA("http://host"), : kOriginA("http://host"),
kOriginB("http://host:8000"), kOriginB("http://host:8000"),
kOriginOther("http://other"),
usage_(0), usage_(0),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
message_loop_(MessageLoop::TYPE_IO), message_loop_(MessageLoop::TYPE_IO),
...@@ -68,6 +70,29 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -68,6 +70,29 @@ class IndexedDBQuotaClientTest : public testing::Test {
return usage_; return usage_;
} }
const std::set<GURL>& GetOriginsForType(
quota::QuotaClient* client,
quota::StorageType type) {
origins_.clear();
client->GetOriginsForType(type,
callback_factory_.NewCallback(
&IndexedDBQuotaClientTest::OnGetOriginsComplete));
MessageLoop::current()->RunAllPending();
return origins_;
}
const std::set<GURL>& GetOriginsForHost(
quota::QuotaClient* client,
quota::StorageType type,
const std::string& host) {
origins_.clear();
client->GetOriginsForHost(type, host,
callback_factory_.NewCallback(
&IndexedDBQuotaClientTest::OnGetOriginsComplete));
MessageLoop::current()->RunAllPending();
return origins_;
}
IndexedDBContext* idb_context() { return idb_context_.get(); } IndexedDBContext* idb_context() { return idb_context_.get(); }
void SetFileSizeTo(const FilePath& path, int size) { void SetFileSizeTo(const FilePath& path, int size) {
...@@ -91,8 +116,13 @@ class IndexedDBQuotaClientTest : public testing::Test { ...@@ -91,8 +116,13 @@ class IndexedDBQuotaClientTest : public testing::Test {
usage_ = usage; usage_ = usage;
} }
void OnGetOriginsComplete(const std::set<GURL>& origins) {
origins_ = origins;
}
ScopedTempDir temp_dir_; ScopedTempDir temp_dir_;
int64 usage_; int64 usage_;
std::set<GURL> origins_;
scoped_refptr<IndexedDBContext> idb_context_; scoped_refptr<IndexedDBContext> idb_context_;
base::ScopedCallbackFactory<IndexedDBQuotaClientTest> callback_factory_; base::ScopedCallbackFactory<IndexedDBQuotaClientTest> callback_factory_;
MessageLoop message_loop_; MessageLoop message_loop_;
...@@ -118,3 +148,45 @@ TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) { ...@@ -118,3 +148,45 @@ TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) {
EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp)); EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp));
EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm)); EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm));
} }
TEST_F(IndexedDBQuotaClientTest, GetOriginsForHost) {
IndexedDBQuotaClient client(
base::MessageLoopProxy::CreateForCurrentThread(),
idb_context());
EXPECT_EQ(kOriginA.host(), kOriginB.host());
EXPECT_NE(kOriginA.host(), kOriginOther.host());
std::set<GURL> origins = GetOriginsForHost(&client, kTemp, kOriginA.host());
EXPECT_TRUE(origins.empty());
AddFakeIndexedDB(kOriginA, 1000);
origins = GetOriginsForHost(&client, kTemp, kOriginA.host());
EXPECT_EQ(origins.size(), 1ul);
EXPECT_TRUE(origins.find(kOriginA) != origins.end());
AddFakeIndexedDB(kOriginB, 1000);
origins = GetOriginsForHost(&client, kTemp, kOriginA.host());
EXPECT_EQ(origins.size(), 2ul);
EXPECT_TRUE(origins.find(kOriginA) != origins.end());
EXPECT_TRUE(origins.find(kOriginB) != origins.end());
EXPECT_TRUE(GetOriginsForHost(&client, kPerm, kOriginA.host()).empty());
EXPECT_TRUE(GetOriginsForHost(&client, kTemp, kOriginOther.host()).empty());
}
TEST_F(IndexedDBQuotaClientTest, GetOriginsForType) {
IndexedDBQuotaClient client(
base::MessageLoopProxy::CreateForCurrentThread(),
idb_context());
EXPECT_TRUE(GetOriginsForType(&client, kTemp).empty());
EXPECT_TRUE(GetOriginsForType(&client, kPerm).empty());
AddFakeIndexedDB(kOriginA, 1000);
std::set<GURL> origins = GetOriginsForType(&client, kTemp);
EXPECT_EQ(origins.size(), 1ul);
EXPECT_TRUE(origins.find(kOriginA) != origins.end());
EXPECT_TRUE(GetOriginsForType(&client, kPerm).empty());
}
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