summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authortzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 06:48:30 +0000
committertzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-09 06:48:30 +0000
commita9e3ec4a7fa2bc3fa29ce457353376fb7726af0d (patch)
treec938b4f1f975028c0f7d674fb7f67763e9c7f8bf /chrome/browser
parentafecb884880931e4926c28874f4932dc9ae2319c (diff)
downloadchromium_src-a9e3ec4a7fa2bc3fa29ce457353376fb7726af0d.zip
chromium_src-a9e3ec4a7fa2bc3fa29ce457353376fb7726af0d.tar.gz
chromium_src-a9e3ec4a7fa2bc3fa29ce457353376fb7726af0d.tar.bz2
Adding usage entry to chrome://settings/cookies.
BUG=88644,91816,91836 TEST='BrowsingDataQuotaHelperTest.*' Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=95607 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=95779 Review URL: http://codereview.chromium.org/7387007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95959 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browsing_data_quota_helper.cc53
-rw-r--r--chrome/browser/browsing_data_quota_helper.h88
-rw-r--r--chrome/browser/browsing_data_quota_helper_impl.cc163
-rw-r--r--chrome/browser/browsing_data_quota_helper_impl.h75
-rw-r--r--chrome/browser/browsing_data_quota_helper_unittest.cc119
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.cc1
-rw-r--r--chrome/browser/cookies_tree_model.cc104
-rw-r--r--chrome/browser/cookies_tree_model.h50
-rw-r--r--chrome/browser/cookies_tree_model_unittest.cc149
-rw-r--r--chrome/browser/mock_browsing_data_quota_helper.cc42
-rw-r--r--chrome/browser/mock_browsing_data_quota_helper.h37
-rw-r--r--chrome/browser/resources/options/cookies_list.js24
-rw-r--r--chrome/browser/resources/options/cookies_view.css8
-rw-r--r--chrome/browser/ui/webui/cookies_tree_model_util.cc39
-rw-r--r--chrome/browser/ui/webui/cookies_tree_model_util.h3
-rw-r--r--chrome/browser/ui/webui/options/cookies_view_handler.cc4
16 files changed, 902 insertions, 57 deletions
diff --git a/chrome/browser/browsing_data_quota_helper.cc b/chrome/browser/browsing_data_quota_helper.cc
new file mode 100644
index 0000000..f1ea58c
--- /dev/null
+++ b/chrome/browser/browsing_data_quota_helper.cc
@@ -0,0 +1,53 @@
+// 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 "chrome/browser/browsing_data_quota_helper.h"
+
+BrowsingDataQuotaHelper::QuotaInfo::QuotaInfo()
+ : temporary_usage(0),
+ persistent_usage(0) {}
+
+BrowsingDataQuotaHelper::QuotaInfo::QuotaInfo(const std::string& host)
+ : host(host),
+ temporary_usage(0),
+ persistent_usage(0) {}
+
+BrowsingDataQuotaHelper::QuotaInfo::QuotaInfo(const std::string& host,
+ int64 temporary_usage,
+ int64 persistent_usage)
+ : host(host),
+ temporary_usage(temporary_usage),
+ persistent_usage(persistent_usage) {}
+
+BrowsingDataQuotaHelper::QuotaInfo::~QuotaInfo() {}
+
+// static
+void BrowsingDataQuotaHelperDeleter::Destruct(
+ const BrowsingDataQuotaHelper* helper) {
+ helper->io_thread_->DeleteSoon(FROM_HERE, helper);
+}
+
+BrowsingDataQuotaHelper::BrowsingDataQuotaHelper(
+ base::MessageLoopProxy* io_thread)
+ : io_thread_(io_thread) {
+}
+
+BrowsingDataQuotaHelper::~BrowsingDataQuotaHelper() {
+}
+
+bool operator <(const BrowsingDataQuotaHelper::QuotaInfo& lhs,
+ const BrowsingDataQuotaHelper::QuotaInfo& rhs) {
+ if (lhs.host != rhs.host)
+ return lhs.host < rhs.host;
+ if (lhs.temporary_usage != rhs.temporary_usage)
+ return lhs.temporary_usage < rhs.temporary_usage;
+ return lhs.persistent_usage < rhs.persistent_usage;
+}
+
+bool operator ==(const BrowsingDataQuotaHelper::QuotaInfo& lhs,
+ const BrowsingDataQuotaHelper::QuotaInfo& rhs) {
+ return lhs.host == rhs.host &&
+ lhs.temporary_usage == rhs.temporary_usage &&
+ lhs.persistent_usage == rhs.persistent_usage;
+}
diff --git a/chrome/browser/browsing_data_quota_helper.h b/chrome/browser/browsing_data_quota_helper.h
new file mode 100644
index 0000000..2ed0c1b
--- /dev/null
+++ b/chrome/browser/browsing_data_quota_helper.h
@@ -0,0 +1,88 @@
+// 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 CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_H_
+#define CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/callback_old.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop_proxy.h"
+#include "base/time.h"
+#include "content/browser/browser_thread.h"
+#include "webkit/quota/quota_types.h"
+
+class Profile;
+
+namespace quota {
+class QuotaManager;
+}
+
+class BrowsingDataQuotaHelper;
+
+struct BrowsingDataQuotaHelperDeleter {
+ static void Destruct(const BrowsingDataQuotaHelper* helper);
+};
+
+// This class is an interface class to bridge between Cookies Tree and Unified
+// Quota System. This class provides a way to get usage and quota information
+// through the instance.
+//
+// Call Create to create an instance for a profile and call StartFetching with
+// a callback to fetch information asynchronously. If result is no longer needed
+// after StartFetching, call CancelNotification to prevent callback.
+//
+// Parallel fetching is not allowed, a fetching task should start after end of
+// previous task. All method of this class should called from UI thread.
+class BrowsingDataQuotaHelper
+ : public base::RefCountedThreadSafe<BrowsingDataQuotaHelper,
+ BrowsingDataQuotaHelperDeleter> {
+ public:
+ // QuotaInfo contains host-based quota and usage information for persistent
+ // and temporary storage.
+ struct QuotaInfo {
+ QuotaInfo();
+ explicit QuotaInfo(const std::string& host);
+ QuotaInfo(const std::string& host,
+ int64 temporary_usage,
+ int64 persistent_usage);
+ ~QuotaInfo();
+
+ std::string host;
+ int64 temporary_usage;
+ int64 persistent_usage;
+ };
+
+ typedef std::vector<QuotaInfo> QuotaInfoArray;
+ typedef Callback1<const QuotaInfoArray&>::Type FetchResultCallback;
+
+ static BrowsingDataQuotaHelper* Create(Profile* profile);
+
+ virtual void StartFetching(FetchResultCallback* callback) = 0;
+ virtual void CancelNotification() = 0;
+
+ // We don't support deletion now.
+ virtual void DeleteQuotaHost(const std::string& host) {}
+
+ protected:
+ explicit BrowsingDataQuotaHelper(base::MessageLoopProxy* io_thread_);
+ virtual ~BrowsingDataQuotaHelper();
+
+ private:
+ friend class DeleteTask<const BrowsingDataQuotaHelper>;
+ friend struct BrowsingDataQuotaHelperDeleter;
+ scoped_refptr<base::MessageLoopProxy> io_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelper);
+};
+
+bool operator <(const BrowsingDataQuotaHelper::QuotaInfo& lhs,
+ const BrowsingDataQuotaHelper::QuotaInfo& rhs);
+bool operator ==(const BrowsingDataQuotaHelper::QuotaInfo& lhs,
+ const BrowsingDataQuotaHelper::QuotaInfo& rhs);
+
+#endif // CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_H_
diff --git a/chrome/browser/browsing_data_quota_helper_impl.cc b/chrome/browser/browsing_data_quota_helper_impl.cc
new file mode 100644
index 0000000..a3e9e1d
--- /dev/null
+++ b/chrome/browser/browsing_data_quota_helper_impl.cc
@@ -0,0 +1,163 @@
+// 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 "chrome/browser/browsing_data_quota_helper_impl.h"
+
+#include <map>
+#include <set>
+
+#include "base/logging.h"
+#include "chrome/browser/profiles/profile.h"
+#include "webkit/quota/quota_manager.h"
+
+// static
+BrowsingDataQuotaHelper* BrowsingDataQuotaHelper::Create(Profile* profile) {
+ return new BrowsingDataQuotaHelperImpl(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ profile->GetQuotaManager());
+}
+
+BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl(
+ base::MessageLoopProxy* ui_thread,
+ base::MessageLoopProxy* io_thread,
+ quota::QuotaManager* quota_manager)
+ : BrowsingDataQuotaHelper(io_thread),
+ quota_manager_(quota_manager),
+ is_fetching_(false),
+ ui_thread_(ui_thread),
+ io_thread_(io_thread),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ DCHECK(quota_manager);
+}
+
+BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {}
+
+void BrowsingDataQuotaHelperImpl::StartFetching(FetchResultCallback* callback) {
+ DCHECK(callback);
+ DCHECK(!callback_.get());
+ DCHECK(!is_fetching_);
+ callback_.reset(callback);
+ quota_info_.clear();
+ is_fetching_ = true;
+
+ FetchQuotaInfo();
+}
+
+void BrowsingDataQuotaHelperImpl::CancelNotification() {
+ callback_.reset();
+}
+
+void BrowsingDataQuotaHelperImpl::FetchQuotaInfo() {
+ if (!io_thread_->BelongsToCurrentThread()) {
+ io_thread_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &BrowsingDataQuotaHelperImpl::FetchQuotaInfo));
+ return;
+ }
+
+ quota_manager_->GetOriginsModifiedSince(
+ quota::kStorageTypeTemporary,
+ base::Time(),
+ callback_factory_.NewCallback(
+ &BrowsingDataQuotaHelperImpl::GotOrigins));
+}
+
+void BrowsingDataQuotaHelperImpl::GotOrigins(
+ const std::set<GURL>& origins, quota::StorageType type) {
+ for (std::set<GURL>::const_iterator itr = origins.begin();
+ itr != origins.end();
+ ++itr)
+ pending_hosts_.insert(std::make_pair(itr->host(), type));
+
+ DCHECK(type == quota::kStorageTypeTemporary ||
+ type == quota::kStorageTypePersistent);
+
+ if (type == quota::kStorageTypeTemporary) {
+ quota_manager_->GetOriginsModifiedSince(
+ quota::kStorageTypePersistent,
+ base::Time(),
+ callback_factory_.NewCallback(
+ &BrowsingDataQuotaHelperImpl::GotOrigins));
+ } else {
+ // type == quota::kStorageTypePersistent
+ ProcessPendingHosts();
+ }
+}
+
+void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() {
+ if (pending_hosts_.empty()) {
+ OnComplete();
+ return;
+ }
+
+ PendingHosts::iterator itr = pending_hosts_.begin();
+ std::string host = itr->first;
+ quota::StorageType type = itr->second;
+ pending_hosts_.erase(itr);
+ GetHostUsage(host, type);
+}
+
+void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host,
+ quota::StorageType type) {
+ DCHECK(quota_manager_.get());
+ quota_manager_->GetHostUsage(
+ host, type,
+ callback_factory_.NewCallback(
+ &BrowsingDataQuotaHelperImpl::GotHostUsage));
+}
+
+void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host,
+ quota::StorageType type,
+ int64 usage) {
+ switch (type) {
+ case quota::kStorageTypeTemporary:
+ quota_info_[host].temporary_usage = usage;
+ break;
+ case quota::kStorageTypePersistent:
+ quota_info_[host].persistent_usage = usage;
+ break;
+ default:
+ NOTREACHED();
+ }
+ ProcessPendingHosts();
+}
+
+void BrowsingDataQuotaHelperImpl::OnComplete() {
+ // Check if CancelNotification was called
+ if (!callback_.get())
+ return;
+
+ if (!ui_thread_->BelongsToCurrentThread()) {
+ ui_thread_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &BrowsingDataQuotaHelperImpl::OnComplete));
+ return;
+ }
+
+ is_fetching_ = false;
+
+ QuotaInfoArray result;
+ result.reserve(quota_info_.size());
+
+ for (std::map<std::string, QuotaInfo>::iterator itr = quota_info_.begin();
+ itr != quota_info_.end();
+ ++itr) {
+ QuotaInfo* info = &itr->second;
+ // Skip unused entries
+ if (info->temporary_usage <= 0 &&
+ info->persistent_usage <= 0)
+ continue;
+
+ info->host = itr->first;
+ result.push_back(*info);
+ }
+
+ callback_->Run(result);
+ callback_.reset();
+}
diff --git a/chrome/browser/browsing_data_quota_helper_impl.h b/chrome/browser/browsing_data_quota_helper_impl.h
new file mode 100644
index 0000000..83e4516
--- /dev/null
+++ b/chrome/browser/browsing_data_quota_helper_impl.h
@@ -0,0 +1,75 @@
+// 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 CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
+#define CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/callback_old.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_callback_factory.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+#include "chrome/browser/browsing_data_quota_helper.h"
+#include "content/browser/browser_thread.h"
+#include "webkit/quota/quota_types.h"
+
+namespace quota {
+class QuotaManager;
+}
+
+// Implementation of BrowsingDataQuotaHelper. Since a client of
+// BrowsingDataQuotaHelper should live in UI thread and QuotaManager lives in
+// IO thread, we have to communicate over thread using PostTask.
+class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper {
+ public:
+ virtual void StartFetching(FetchResultCallback* callback) OVERRIDE;
+ virtual void CancelNotification() OVERRIDE;
+
+ private:
+ void FetchQuotaInfo();
+ void OnComplete();
+
+ void GetHostUsage(const std::string& host, quota::StorageType type);
+ void ProcessPendingHosts();
+
+ // Callback function for GetOriginModifiedSince.
+ void GotOrigins(const std::set<GURL>& origins, quota::StorageType type);
+
+ // Callback function for GetHostUsage.
+ void GotHostUsage(const std::string& host,
+ quota::StorageType type,
+ int64 usage);
+
+ explicit BrowsingDataQuotaHelperImpl(base::MessageLoopProxy* ui_thread,
+ base::MessageLoopProxy* io_thread,
+ quota::QuotaManager* quota_manager);
+ virtual ~BrowsingDataQuotaHelperImpl();
+
+ scoped_refptr<quota::QuotaManager> quota_manager_;
+ scoped_ptr<FetchResultCallback> callback_;
+
+ typedef std::set<std::pair<std::string, quota::StorageType> > PendingHosts;
+ PendingHosts pending_hosts_;
+ std::map<std::string, QuotaInfo> quota_info_;
+
+ bool is_fetching_;
+
+ scoped_refptr<base::MessageLoopProxy> ui_thread_;
+ scoped_refptr<base::MessageLoopProxy> io_thread_;
+ base::ScopedCallbackFactory<BrowsingDataQuotaHelperImpl> callback_factory_;
+
+ friend class BrowsingDataQuotaHelper;
+ friend class BrowsingDataQuotaHelperTest;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperImpl);
+};
+
+#endif // CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
diff --git a/chrome/browser/browsing_data_quota_helper_unittest.cc b/chrome/browser/browsing_data_quota_helper_unittest.cc
new file mode 100644
index 0000000..5cf5ede
--- /dev/null
+++ b/chrome/browser/browsing_data_quota_helper_unittest.cc
@@ -0,0 +1,119 @@
+// 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 "testing/gtest/include/gtest/gtest.h"
+
+#include "base/memory/scoped_callback_factory.h"
+#include "base/message_loop_proxy.h"
+#include "base/scoped_temp_dir.h"
+#include "chrome/browser/browsing_data_quota_helper_impl.h"
+#include "webkit/quota/mock_storage_client.h"
+#include "webkit/quota/quota_manager.h"
+
+class BrowsingDataQuotaHelperTest : public testing::Test {
+ public:
+ typedef BrowsingDataQuotaHelper::QuotaInfo QuotaInfo;
+ typedef BrowsingDataQuotaHelper::QuotaInfoArray QuotaInfoArray;
+
+ BrowsingDataQuotaHelperTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ db_thread_(BrowserThread::DB, &message_loop_),
+ io_thread_(BrowserThread::IO, &message_loop_),
+ fetching_completed_(true),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
+
+ virtual ~BrowsingDataQuotaHelperTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ EXPECT_TRUE(dir_.CreateUniqueTempDir());
+ quota_manager_ = new quota::QuotaManager(
+ false, dir_.path(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ NULL);
+ helper_ = new BrowsingDataQuotaHelperImpl(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ quota_manager_);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ helper_ = NULL;
+ quota_manager_ = NULL;
+ quota_info_.clear();
+ MessageLoop::current()->RunAllPending();
+ }
+
+ protected:
+ const QuotaInfoArray& quota_info() const {
+ return quota_info_;
+ }
+
+ bool fetching_completed() const {
+ return fetching_completed_;
+ }
+
+ void StartFetching() {
+ fetching_completed_ = false;
+ helper_->StartFetching(
+ callback_factory_.NewCallback(
+ &BrowsingDataQuotaHelperTest::FetchCompleted));
+ }
+
+ void RegisterClient(const quota::MockOriginData* data, std::size_t data_len) {
+ quota::MockStorageClient* client =
+ new quota::MockStorageClient(
+ quota_manager_->proxy(), data, data_len);
+ quota_manager_->proxy()->RegisterClient(client);
+ client->TouchAllOriginsAndNotify();
+ }
+
+ private:
+ void FetchCompleted(const QuotaInfoArray& quota_info) {
+ quota_info_ = quota_info;
+ fetching_completed_ = true;
+ }
+
+ MessageLoop message_loop_;
+ BrowserThread ui_thread_;
+ BrowserThread db_thread_;
+ BrowserThread io_thread_;
+ scoped_refptr<quota::QuotaManager> quota_manager_;
+
+ ScopedTempDir dir_;
+ scoped_refptr<BrowsingDataQuotaHelper> helper_;
+
+ bool fetching_completed_;
+ QuotaInfoArray quota_info_;
+ base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest);
+};
+
+TEST_F(BrowsingDataQuotaHelperTest, Empty) {
+ StartFetching();
+ MessageLoop::current()->RunAllPending();
+ EXPECT_TRUE(fetching_completed());
+ EXPECT_TRUE(quota_info().empty());
+}
+
+TEST_F(BrowsingDataQuotaHelperTest, FetchData) {
+ const quota::MockOriginData kOrigins[] = {
+ {"http://example.com/", quota::kStorageTypeTemporary, 1},
+ {"https://example.com/", quota::kStorageTypeTemporary, 10},
+ {"http://example.com/", quota::kStorageTypePersistent, 100},
+ {"http://example2.com/", quota::kStorageTypeTemporary, 1000},
+ };
+
+ RegisterClient(kOrigins, arraysize(kOrigins));
+ StartFetching();
+ MessageLoop::current()->RunAllPending();
+ EXPECT_TRUE(fetching_completed());
+
+ std::set<QuotaInfo> expected, actual;
+ actual.insert(quota_info().begin(), quota_info().end());
+ expected.insert(QuotaInfo("example.com", 11, 100));
+ expected.insert(QuotaInfo("example2.com", 1000, 0));
+ EXPECT_TRUE(expected == actual);
+}
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index 3950da2..186fa485 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -526,5 +526,6 @@ TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() {
appcaches_->Clone(),
indexed_dbs_->Clone(),
file_systems_->Clone(),
+ NULL,
true);
}
diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc
index 8a001f6..e626f66 100644
--- a/chrome/browser/cookies_tree_model.cc
+++ b/chrome/browser/cookies_tree_model.cc
@@ -68,7 +68,7 @@ void CookieTreeCookieNode::DeleteStoredObjects() {
CookieTreeNode::DetailedInfo CookieTreeCookieNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_COOKIE,
- cookie_, NULL, NULL, NULL, NULL, NULL, NULL);
+ cookie_, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
namespace {
@@ -148,7 +148,7 @@ void CookieTreeAppCacheNode::DeleteStoredObjects() {
CookieTreeNode::DetailedInfo CookieTreeAppCacheNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_APPCACHE,
- NULL, NULL, NULL, NULL, appcache_info_, NULL, NULL);
+ NULL, NULL, NULL, NULL, appcache_info_, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -172,7 +172,7 @@ void CookieTreeDatabaseNode::DeleteStoredObjects() {
CookieTreeNode::DetailedInfo CookieTreeDatabaseNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_DATABASE,
- NULL, database_info_, NULL, NULL, NULL, NULL, NULL);
+ NULL, database_info_, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -198,7 +198,8 @@ CookieTreeNode::DetailedInfo
CookieTreeLocalStorageNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_LOCAL_STORAGE,
- NULL, NULL, local_storage_info_, NULL, NULL, NULL, NULL);
+ NULL, NULL, local_storage_info_, NULL, NULL, NULL, NULL,
+ NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -220,7 +221,7 @@ CookieTreeSessionStorageNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_SESSION_STORAGE,
NULL, NULL, NULL, session_storage_info_, NULL, NULL,
- NULL);
+ NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -245,7 +246,8 @@ void CookieTreeIndexedDBNode::DeleteStoredObjects() {
CookieTreeNode::DetailedInfo CookieTreeIndexedDBNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_INDEXED_DB,
- NULL, NULL, NULL, NULL, NULL, indexed_db_info_, NULL);
+ NULL, NULL, NULL, NULL, NULL, indexed_db_info_, NULL,
+ NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -268,7 +270,29 @@ void CookieTreeFileSystemNode::DeleteStoredObjects() {
CookieTreeNode::DetailedInfo CookieTreeFileSystemNode::GetDetailedInfo() const {
return DetailedInfo(parent()->parent()->GetTitle(),
DetailedInfo::TYPE_FILE_SYSTEM,
- NULL, NULL, NULL, NULL, NULL, NULL, file_system_info_);
+ NULL, NULL, NULL, NULL, NULL, NULL, file_system_info_,
+ NULL);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// CookieTreeQuotaNode, public:
+
+CookieTreeQuotaNode::CookieTreeQuotaNode(
+ BrowsingDataQuotaHelper::QuotaInfo* quota_info)
+ : CookieTreeNode(UTF8ToUTF16(quota_info->host)),
+ quota_info_(quota_info) {
+}
+
+CookieTreeQuotaNode::~CookieTreeQuotaNode() {}
+
+void CookieTreeQuotaNode::DeleteStoredObjects() {
+ GetModel()->quota_helper_->DeleteQuotaHost(quota_info_->host);
+}
+
+CookieTreeNode::DetailedInfo CookieTreeQuotaNode::GetDetailedInfo() const {
+ return DetailedInfo(parent()->parent()->GetTitle(),
+ DetailedInfo::TYPE_QUOTA,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, quota_info_);
}
///////////////////////////////////////////////////////////////////////////////
@@ -310,7 +334,7 @@ CookiesTreeModel* CookieTreeRootNode::GetModel() const {
CookieTreeNode::DetailedInfo CookieTreeRootNode::GetDetailedInfo() const {
return DetailedInfo(string16(),
DetailedInfo::TYPE_ROOT,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -331,6 +355,7 @@ CookieTreeOriginNode::CookieTreeOriginNode(const GURL& url)
appcaches_child_(NULL),
indexed_dbs_child_(NULL),
file_systems_child_(NULL),
+ quota_child_(NULL),
url_(url) {}
CookieTreeOriginNode::~CookieTreeOriginNode() {}
@@ -338,7 +363,7 @@ CookieTreeOriginNode::~CookieTreeOriginNode() {}
CookieTreeNode::DetailedInfo CookieTreeOriginNode::GetDetailedInfo() const {
return DetailedInfo(GetTitle(),
DetailedInfo::TYPE_ORIGIN,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
CookieTreeCookiesNode* CookieTreeOriginNode::GetOrCreateCookiesNode() {
@@ -399,6 +424,15 @@ CookieTreeFileSystemsNode* CookieTreeOriginNode::GetOrCreateFileSystemsNode() {
return file_systems_child_;
}
+CookieTreeQuotaNode* CookieTreeOriginNode::UpdateOrCreateQuotaNode(
+ BrowsingDataQuotaHelper::QuotaInfo* quota_info) {
+ if (quota_child_)
+ return quota_child_;
+ quota_child_ = new CookieTreeQuotaNode(quota_info);
+ AddChildSortedByTitle(quota_child_);
+ return quota_child_;
+}
+
void CookieTreeOriginNode::CreateContentException(
HostContentSettingsMap* content_settings, ContentSetting setting) const {
if (CanCreateContentException()) {
@@ -427,7 +461,7 @@ CookieTreeCookiesNode::~CookieTreeCookiesNode() {
CookieTreeNode::DetailedInfo CookieTreeCookiesNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_COOKIES,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -443,7 +477,7 @@ CookieTreeAppCachesNode::~CookieTreeAppCachesNode() {}
CookieTreeNode::DetailedInfo CookieTreeAppCachesNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_APPCACHES,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -458,7 +492,7 @@ CookieTreeDatabasesNode::~CookieTreeDatabasesNode() {}
CookieTreeNode::DetailedInfo CookieTreeDatabasesNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_DATABASES,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -474,7 +508,7 @@ CookieTreeNode::DetailedInfo
CookieTreeLocalStoragesNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_LOCAL_STORAGES,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -490,7 +524,7 @@ CookieTreeNode::DetailedInfo
CookieTreeSessionStoragesNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_SESSION_STORAGES,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -506,7 +540,7 @@ CookieTreeNode::DetailedInfo
CookieTreeIndexedDBsNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_INDEXED_DBS,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -522,7 +556,7 @@ CookieTreeNode::DetailedInfo
CookieTreeFileSystemsNode::GetDetailedInfo() const {
return DetailedInfo(parent()->GetTitle(),
DetailedInfo::TYPE_FILE_SYSTEMS,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -558,6 +592,7 @@ CookiesTreeModel::CookiesTreeModel(
BrowsingDataAppCacheHelper* appcache_helper,
BrowsingDataIndexedDBHelper* indexed_db_helper,
BrowsingDataFileSystemHelper* file_system_helper,
+ BrowsingDataQuotaHelper* quota_helper,
bool use_cookie_source)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>(
new CookieTreeRootNode(this))),
@@ -568,6 +603,7 @@ CookiesTreeModel::CookiesTreeModel(
session_storage_helper_(session_storage_helper),
indexed_db_helper_(indexed_db_helper),
file_system_helper_(file_system_helper),
+ quota_helper_(quota_helper),
batch_update_(0),
use_cookie_source_(use_cookie_source) {
LoadCookies();
@@ -598,6 +634,11 @@ CookiesTreeModel::CookiesTreeModel(
file_system_helper_->StartFetching(NewCallback(
this, &CookiesTreeModel::OnFileSystemModelInfoLoaded));
}
+
+ if (quota_helper_) {
+ quota_helper_->StartFetching(NewCallback(
+ this, &CookiesTreeModel::OnQuotaModelInfoLoaded));
+ }
}
CookiesTreeModel::~CookiesTreeModel() {
@@ -611,6 +652,8 @@ CookiesTreeModel::~CookiesTreeModel() {
indexed_db_helper_->CancelNotification();
if (file_system_helper_)
file_system_helper_->CancelNotification();
+ if (quota_helper_)
+ quota_helper_->CancelNotification();
}
///////////////////////////////////////////////////////////////////////////////
@@ -650,6 +693,8 @@ int CookiesTreeModel::GetIconIndex(ui::TreeModelNode* node) {
return DATABASE; // ditto
case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
return DATABASE; // ditto
+ case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
+ return -1;
default:
break;
}
@@ -726,6 +771,7 @@ void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) {
PopulateAppCacheInfoWithFilter(filter);
PopulateIndexedDBInfoWithFilter(filter);
PopulateFileSystemInfoWithFilter(filter);
+ PopulateQuotaInfoWithFilter(filter);
NotifyObserverTreeNodeChanged(root);
NotifyObserverEndBatch();
}
@@ -944,6 +990,32 @@ void CookiesTreeModel::PopulateFileSystemInfoWithFilter(
NotifyObserverEndBatch();
}
+void CookiesTreeModel::OnQuotaModelInfoLoaded(
+ const QuotaInfoArray& quota_info) {
+ quota_info_list_ = quota_info;
+ PopulateQuotaInfoWithFilter(std::wstring());
+}
+
+void CookiesTreeModel::PopulateQuotaInfoWithFilter(
+ const std::wstring& filter) {
+ if (quota_info_list_.empty())
+ return;
+ CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
+ NotifyObserverBeginBatch();
+ for (QuotaInfoArray::iterator quota_info = quota_info_list_.begin();
+ quota_info != quota_info_list_.end();
+ ++quota_info) {
+ if (!filter.size() ||
+ (UTF8ToWide(quota_info->host).find(filter) != std::wstring::npos)) {
+ CookieTreeOriginNode* origin_node =
+ root->GetOrCreateOriginNode(GURL("http://" + quota_info->host));
+ origin_node->UpdateOrCreateQuotaNode(&*quota_info);
+ }
+ }
+ NotifyObserverTreeNodeChanged(root);
+ NotifyObserverEndBatch();
+}
+
void CookiesTreeModel::NotifyObserverBeginBatch() {
// Only notify the model once if we're batching in a nested manner.
if (batch_update_++ == 0) {
diff --git a/chrome/browser/cookies_tree_model.h b/chrome/browser/cookies_tree_model.h
index 1f1e8448..bf9dcae 100644
--- a/chrome/browser/cookies_tree_model.h
+++ b/chrome/browser/cookies_tree_model.h
@@ -21,6 +21,7 @@
#include "chrome/browser/browsing_data_file_system_helper.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
+#include "chrome/browser/browsing_data_quota_helper.h"
#include "chrome/common/content_settings.h"
#include "net/base/cookie_monster.h"
#include "ui/base/models/tree_node_model.h"
@@ -36,6 +37,7 @@ class CookieTreeFileSystemsNode;
class CookieTreeFileSystemNode;
class CookieTreeLocalStorageNode;
class CookieTreeLocalStoragesNode;
+class CookieTreeQuotaNode;
class CookieTreeSessionStorageNode;
class CookieTreeSessionStoragesNode;
class CookieTreeIndexedDBNode;
@@ -69,8 +71,9 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
TYPE_APPCACHE, // This is used for CookieTreeAppCacheNode.
TYPE_INDEXED_DBS, // This is used for CookieTreeIndexedDBsNode.
TYPE_INDEXED_DB, // This is used for CookieTreeIndexedDBNode.
- TYPE_FILE_SYSTEMS, // This is used for CookieTreeFileSystemsNode.
- TYPE_FILE_SYSTEM, // This is used for CookieTreeFileSystemNode.
+ TYPE_FILE_SYSTEMS, // This is used for CookieTreeFileSystemsNode.
+ TYPE_FILE_SYSTEM, // This is used for CookieTreeFileSystemNode.
+ TYPE_QUOTA, // This is used for CookieTreeQuotaNode.
};
// TODO(viettrungluu): Figure out whether we want to store |origin| as a
@@ -85,7 +88,8 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
session_storage_info,
const appcache::AppCacheInfo* appcache_info,
const BrowsingDataIndexedDBHelper::IndexedDBInfo* indexed_db_info,
- const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info)
+ const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info,
+ const BrowsingDataQuotaHelper::QuotaInfo* quota_info)
: origin(UTF16ToWideHack(origin)),
node_type(node_type),
cookie(cookie),
@@ -94,13 +98,15 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
session_storage_info(session_storage_info),
appcache_info(appcache_info),
indexed_db_info(indexed_db_info),
- file_system_info(file_system_info) {
+ file_system_info(file_system_info),
+ quota_info(quota_info) {
DCHECK((node_type != TYPE_DATABASE) || database_info);
DCHECK((node_type != TYPE_LOCAL_STORAGE) || local_storage_info);
DCHECK((node_type != TYPE_SESSION_STORAGE) || session_storage_info);
DCHECK((node_type != TYPE_APPCACHE) || appcache_info);
DCHECK((node_type != TYPE_INDEXED_DB) || indexed_db_info);
DCHECK((node_type != TYPE_FILE_SYSTEM) || file_system_info);
+ DCHECK((node_type != TYPE_QUOTA) || quota_info);
}
#if !defined(WCHAR_T_IS_UTF16)
DetailedInfo(const std::wstring& origin, NodeType node_type,
@@ -112,7 +118,8 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
session_storage_info,
const appcache::AppCacheInfo* appcache_info,
const BrowsingDataIndexedDBHelper::IndexedDBInfo* indexed_db_info,
- const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info)
+ const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info,
+ const BrowsingDataQuotaHelper::QuotaInfo* quota_info)
: origin(origin),
node_type(node_type),
cookie(cookie),
@@ -121,13 +128,15 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
session_storage_info(session_storage_info),
appcache_info(appcache_info),
indexed_db_info(indexed_db_info),
- file_system_info(file_system_info) {
+ file_system_info(file_system_info),
+ quota_info(quota_info) {
DCHECK((node_type != TYPE_DATABASE) || database_info);
DCHECK((node_type != TYPE_LOCAL_STORAGE) || local_storage_info);
DCHECK((node_type != TYPE_SESSION_STORAGE) || session_storage_info);
DCHECK((node_type != TYPE_APPCACHE) || appcache_info);
DCHECK((node_type != TYPE_INDEXED_DB) || indexed_db_info);
DCHECK((node_type != TYPE_FILE_SYSTEM) || file_system_info);
+ DCHECK((node_type != TYPE_QUOTA) || quota_info);
}
#endif
@@ -141,6 +150,7 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
const appcache::AppCacheInfo* appcache_info;
const BrowsingDataIndexedDBHelper::IndexedDBInfo* indexed_db_info;
const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info;
+ const BrowsingDataQuotaHelper::QuotaInfo* quota_info;
};
CookieTreeNode() {}
@@ -211,6 +221,8 @@ class CookieTreeOriginNode : public CookieTreeNode {
CookieTreeAppCachesNode* GetOrCreateAppCachesNode();
CookieTreeIndexedDBsNode* GetOrCreateIndexedDBsNode();
CookieTreeFileSystemsNode* GetOrCreateFileSystemsNode();
+ CookieTreeQuotaNode* UpdateOrCreateQuotaNode(
+ BrowsingDataQuotaHelper::QuotaInfo* quota_info);
// Creates an content exception for this origin of type
// CONTENT_SETTINGS_TYPE_COOKIES.
@@ -233,6 +245,7 @@ class CookieTreeOriginNode : public CookieTreeNode {
CookieTreeAppCachesNode* appcaches_child_;
CookieTreeIndexedDBsNode* indexed_dbs_child_;
CookieTreeFileSystemsNode* file_systems_child_;
+ CookieTreeQuotaNode* quota_child_;
// The URL for which this node was initially created.
GURL url_;
@@ -498,6 +511,24 @@ class CookieTreeIndexedDBsNode : public CookieTreeNode {
DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBsNode);
};
+// CookieTreeQuotaNode --------------------------------------------------
+class CookieTreeQuotaNode : public CookieTreeNode {
+ public:
+ // Does not take ownership of quota_info, and quota_info should remain valid
+ // at least as long as the CookieTreeQuotaNode is valid.
+ explicit CookieTreeQuotaNode(BrowsingDataQuotaHelper::QuotaInfo* quota_info);
+ virtual ~CookieTreeQuotaNode();
+
+ virtual void DeleteStoredObjects();
+ virtual DetailedInfo GetDetailedInfo() const;
+
+ private:
+ // quota_info_ is not owned by the node, and is expected to remain valid as
+ // long as the CookieTreeQuotaNode is valid.
+ BrowsingDataQuotaHelper::QuotaInfo* quota_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(CookieTreeQuotaNode);
+};
// CookiesTreeModel -----------------------------------------------------------
class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
@@ -521,6 +552,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
BrowsingDataAppCacheHelper* appcache_helper,
BrowsingDataIndexedDBHelper* indexed_db_helper,
BrowsingDataFileSystemHelper* file_system_helper,
+ BrowsingDataQuotaHelper* quota_helper,
bool use_cookie_source);
virtual ~CookiesTreeModel();
@@ -565,6 +597,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
IndexedDBInfoList;
typedef std::vector<BrowsingDataFileSystemHelper::FileSystemInfo>
FileSystemInfoList;
+ typedef std::vector<BrowsingDataQuotaHelper::QuotaInfo> QuotaInfoArray;
void LoadCookies();
void LoadCookiesWithFilter(const std::wstring& filter);
@@ -579,6 +612,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
const IndexedDBInfoList& indexed_db_info);
void OnFileSystemModelInfoLoaded(
const FileSystemInfoList& file_system_info);
+ void OnQuotaModelInfoLoaded(const QuotaInfoArray& quota_info);
void PopulateAppCacheInfoWithFilter(const std::wstring& filter);
void PopulateDatabaseInfoWithFilter(const std::wstring& filter);
@@ -586,6 +620,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
void PopulateSessionStorageInfoWithFilter(const std::wstring& filter);
void PopulateIndexedDBInfoWithFilter(const std::wstring& filter);
void PopulateFileSystemInfoWithFilter(const std::wstring& filter);
+ void PopulateQuotaInfoWithFilter(const std::wstring& filter);
void NotifyObserverBeginBatch();
void NotifyObserverEndBatch();
@@ -602,10 +637,12 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
scoped_refptr<BrowsingDataLocalStorageHelper> session_storage_helper_;
scoped_refptr<BrowsingDataIndexedDBHelper> indexed_db_helper_;
scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper_;
+ scoped_refptr<BrowsingDataQuotaHelper> quota_helper_;
LocalStorageInfoList local_storage_info_list_;
LocalStorageInfoList session_storage_info_list_;
IndexedDBInfoList indexed_db_info_list_;
FileSystemInfoList file_system_info_list_;
+ QuotaInfoArray quota_info_list_;
// The CookiesTreeModel maintains a separate list of observers that are
// specifically of the type CookiesTreeModel::Observer.
@@ -626,6 +663,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
friend class CookieTreeLocalStorageNode;
friend class CookieTreeIndexedDBNode;
friend class CookieTreeFileSystemNode;
+ friend class CookieTreeQuotaNode;
DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel);
};
diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc
index 20f7080..a880521 100644
--- a/chrome/browser/cookies_tree_model_unittest.cc
+++ b/chrome/browser/cookies_tree_model_unittest.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/mock_browsing_data_database_helper.h"
#include "chrome/browser/mock_browsing_data_file_system_helper.h"
#include "chrome/browser/mock_browsing_data_indexed_db_helper.h"
+#include "chrome/browser/mock_browsing_data_quota_helper.h"
#include "chrome/browser/mock_browsing_data_local_storage_helper.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/testing_browser_process_test.h"
@@ -36,7 +37,7 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
virtual ~CookiesTreeModelTest() {
}
- virtual void SetUp() {
+ virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile());
profile_->CreateRequestContext();
mock_browsing_data_database_helper_ =
@@ -51,6 +52,19 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
new MockBrowsingDataIndexedDBHelper(profile_.get());
mock_browsing_data_file_system_helper_ =
new MockBrowsingDataFileSystemHelper(profile_.get());
+ mock_browsing_data_quota_helper_ =
+ new MockBrowsingDataQuotaHelper(profile_.get());
+ }
+
+ virtual void TearDown() OVERRIDE {
+ mock_browsing_data_quota_helper_ = NULL;
+ mock_browsing_data_file_system_helper_ = NULL;
+ mock_browsing_data_indexed_db_helper_ = NULL;
+ mock_browsing_data_appcache_helper_ = NULL;
+ mock_browsing_data_session_storage_helper_ = NULL;
+ mock_browsing_data_local_storage_helper_ = NULL;
+ mock_browsing_data_database_helper_ = NULL;
+ message_loop_.RunAllPending();
}
CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() {
@@ -65,6 +79,7 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
mock_browsing_data_appcache_helper_,
mock_browsing_data_indexed_db_helper_,
mock_browsing_data_file_system_helper_,
+ mock_browsing_data_quota_helper_,
false);
mock_browsing_data_database_helper_->AddDatabaseSamples();
mock_browsing_data_database_helper_->Notify();
@@ -76,10 +91,13 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
mock_browsing_data_indexed_db_helper_->Notify();
mock_browsing_data_file_system_helper_->AddFileSystemSamples();
mock_browsing_data_file_system_helper_->Notify();
+ mock_browsing_data_quota_helper_->AddQuotaSamples();
+ mock_browsing_data_quota_helper_->Notify();
{
SCOPED_TRACE("Initial State 3 cookies, 2 databases, 2 local storages, "
- "2 session storages, 2 indexed DBs, 3 filesystems");
- // 41 because there's the root, then foo1 -> cookies -> a,
+ "2 session storages, 2 indexed DBs, 3 filesystems, "
+ "2 quotas");
+ // 45 because there's the root, then foo1 -> cookies -> a,
// foo2 -> cookies -> b, foo3 -> cookies -> c,
// dbhost1 -> database -> db1, dbhost2 -> database -> db2,
// fshost1 -> filesystem -> http://fshost1:1/,
@@ -90,8 +108,10 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
// host1 -> sessionstorage -> http://host1:1/,
// host2 -> sessionstorage -> http://host2:2/,
// idbhost1 -> indexeddb -> http://idbhost1:1/,
- // idbhost2 -> indexeddb -> http://idbhost2:2/.
- EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount());
+ // idbhost2 -> indexeddb -> http://idbhost2:2/,
+ // quotahost1 -> quotahost1,
+ // quotahost2 -> quotahost2.
+ EXPECT_EQ(45, cookies_model->GetRoot()->GetTotalNodeCount());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model));
EXPECT_EQ("http://host1:1/,http://host2:2/",
GetDisplayedLocalStorages(cookies_model));
@@ -101,6 +121,8 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
GetDisplayedIndexedDBs(cookies_model));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model));
+ EXPECT_EQ("quotahost1,quotahost2",
+ GetDisplayedQuotas(cookies_model));
}
return cookies_model;
}
@@ -147,6 +169,8 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
return node->GetDetailedInfo().file_system_info->origin.spec() +
",";
+ case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
+ return node->GetDetailedInfo().quota_info->host + ",";
default:
return "";
}
@@ -185,6 +209,11 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
node, CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM);
}
+ std::string GetFileQuotaOfChildren(const CookieTreeNode* node) {
+ return GetNodesOfChildren(
+ node, CookieTreeNode::DetailedInfo::TYPE_QUOTA);
+ }
+
// Get the nodes names displayed in the view (if we had one) in the order
// they are displayed, as a comma seperated string.
// Ex: EXPECT_STREQ("X,Y", GetDisplayedNodes(cookies_view, type).c_str());
@@ -233,6 +262,11 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM);
}
+ std::string GetDisplayedQuotas(CookiesTreeModel* cookies_model) {
+ return GetDisplayedNodes(cookies_model,
+ CookieTreeNode::DetailedInfo::TYPE_QUOTA);
+ }
+
// Do not call on the root.
void DeleteStoredObjects(CookieTreeNode* node) {
node->DeleteStoredObjects();
@@ -259,6 +293,8 @@ class CookiesTreeModelTest : public TestingBrowserProcessTest {
mock_browsing_data_indexed_db_helper_;
scoped_refptr<MockBrowsingDataFileSystemHelper>
mock_browsing_data_file_system_helper_;
+ scoped_refptr<MockBrowsingDataQuotaHelper>
+ mock_browsing_data_quota_helper_;
};
TEST_F(CookiesTreeModelTest, RemoveAll) {
@@ -281,6 +317,8 @@ TEST_F(CookiesTreeModelTest, RemoveAll) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
+ EXPECT_EQ("quotahost1,quotahost2",
+ GetDisplayedQuotas(cookies_model.get()));
}
mock_browsing_data_database_helper_->Reset();
@@ -325,10 +363,46 @@ TEST_F(CookiesTreeModelTest, Remove) {
// 9. `host2`
// 10. `idbhost1`
// 11. `idbhost2`
+ // 12. `quotahost1`
+ // 13. `quotahost2`
//
// Here, we'll remove them one by one, starting from the end, and
// check that the state makes sense.
+ DeleteStoredObjects(cookies_model->GetRoot()->GetChild(13));
+ {
+ SCOPED_TRACE("`quotahost2` removed.");
+ EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
+ EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
+ EXPECT_EQ("http://host1:1/,http://host2:2/",
+ GetDisplayedLocalStorages(cookies_model.get()));
+ EXPECT_EQ("http://host1:1/,http://host2:2/",
+ GetDisplayedSessionStorages(cookies_model.get()));
+ EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
+ GetDisplayedFileSystems(cookies_model.get()));
+ EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
+ GetDisplayedIndexedDBs(cookies_model.get()));
+ EXPECT_EQ("quotahost1",
+ GetDisplayedQuotas(cookies_model.get()));
+ EXPECT_EQ(43, cookies_model->GetRoot()->GetTotalNodeCount());
+ }
+ DeleteStoredObjects(cookies_model->GetRoot()->GetChild(12));
+ {
+ SCOPED_TRACE("`quotahost1` removed.");
+ EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
+ EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
+ EXPECT_EQ("http://host1:1/,http://host2:2/",
+ GetDisplayedLocalStorages(cookies_model.get()));
+ EXPECT_EQ("http://host1:1/,http://host2:2/",
+ GetDisplayedSessionStorages(cookies_model.get()));
+ EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
+ GetDisplayedFileSystems(cookies_model.get()));
+ EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
+ GetDisplayedIndexedDBs(cookies_model.get()));
+ EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount());
+ }
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(11));
{
SCOPED_TRACE("`idbhost2` removed.");
@@ -500,7 +574,7 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
SCOPED_TRACE("First origin removed");
EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
- // 39 because in this case, the origin remains, although the COOKIES
+ // 43 because in this case, the origin remains, although the COOKIES
// node beneath it has been deleted. So, we have
// root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
// dbhost1 -> database -> db1, dbhost2 -> database -> db2,
@@ -510,8 +584,10 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
// host1 -> localstorage -> http://host1:1/,
// host2 -> localstorage -> http://host2:2/,
// idbhost1 -> sessionstorage -> http://idbhost1:1/,
- // idbhost2 -> sessionstorage -> http://idbhost2:2/.
- EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount());
+ // idbhost2 -> sessionstorage -> http://idbhost2:2/,
+ // quotahost1 -> quotahost1,
+ // quotahost2 -> quotahost1.
+ EXPECT_EQ(43, cookies_model->GetRoot()->GetTotalNodeCount());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
EXPECT_EQ("http://host1:1/,http://host2:2/",
GetDisplayedLocalStorages(cookies_model.get()));
@@ -521,6 +597,7 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
}
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0));
@@ -537,7 +614,8 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
- EXPECT_EQ(37, cookies_model->GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
+ EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount());
}
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
@@ -554,7 +632,8 @@ TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
- EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
+ EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount());
}
}
@@ -577,7 +656,8 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
- // 39 because in this case, the origin remains, although the COOKIES
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
+ // 43 because in this case, the origin remains, although the COOKIES
// node beneath it has been deleted. So, we have
// root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
// dbhost1 -> database -> db1, dbhost2 -> database -> db2,
@@ -589,8 +669,10 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
// host1 -> sessionstorage -> http://host1:1/,
// host2 -> sessionstorage -> http://host2:2/,
// idbhost1 -> sessionstorage -> http://idbhost1:1/,
- // idbhost2 -> sessionstorage -> http://idbhost2:2/.
- EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount());
+ // idbhost2 -> sessionstorage -> http://idbhost2:2/,
+ // quotahost1 -> quotahost1,
+ // quotahost2 -> quotahost2.
+ EXPECT_EQ(43, cookies_model->GetRoot()->GetTotalNodeCount());
}
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0));
@@ -607,7 +689,8 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
- EXPECT_EQ(37, cookies_model->GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
+ EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount());
}
DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
@@ -624,7 +707,8 @@ TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
GetDisplayedIndexedDBs(cookies_model.get()));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(cookies_model.get()));
- EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
+ EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount());
}
}
@@ -641,6 +725,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
mock_browsing_data_appcache_helper_,
mock_browsing_data_indexed_db_helper_,
mock_browsing_data_file_system_helper_,
+ mock_browsing_data_quota_helper_,
false);
mock_browsing_data_database_helper_->AddDatabaseSamples();
mock_browsing_data_database_helper_->Notify();
@@ -652,10 +737,13 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
mock_browsing_data_indexed_db_helper_->Notify();
mock_browsing_data_file_system_helper_->AddFileSystemSamples();
mock_browsing_data_file_system_helper_->Notify();
+ mock_browsing_data_quota_helper_->AddQuotaSamples();
+ mock_browsing_data_quota_helper_->Notify();
{
SCOPED_TRACE("Initial State 4 cookies, 2 databases, 2 local storages, "
- "2 session storages, 2 indexed DBs, 3 file systems");
+ "2 session storages, 2 indexed DBs, 3 file systems, "
+ "2 quotas.");
// 42 because there's the root, then foo1 -> cookies -> a,
// foo2 -> cookies -> b, foo3 -> cookies -> c,d
// dbhost1 -> database -> db1, dbhost2 -> database -> db2,
@@ -666,8 +754,10 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
// host1 -> sessionstorage -> http://host1:1/,
// host2 -> sessionstorage -> http://host2:2/,
// idbhost1 -> sessionstorage -> http://idbhost1:1/,
- // idbhost2 -> sessionstorage -> http://idbhost2:2/.
- EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount());
+ // idbhost2 -> sessionstorage -> http://idbhost2:2/,
+ // quotahost1 -> quotahost1,
+ // quotahost2 -> quotahost2.
+ EXPECT_EQ(46, cookies_model.GetRoot()->GetTotalNodeCount());
EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
@@ -679,6 +769,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
GetDisplayedIndexedDBs(&cookies_model));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(&cookies_model));
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
}
DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2));
{
@@ -694,7 +785,8 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
GetDisplayedIndexedDBs(&cookies_model));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(&cookies_model));
- EXPECT_EQ(38, cookies_model.GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
+ EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount());
}
}
@@ -712,6 +804,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
mock_browsing_data_appcache_helper_,
mock_browsing_data_indexed_db_helper_,
mock_browsing_data_file_system_helper_,
+ mock_browsing_data_quota_helper_,
false);
mock_browsing_data_database_helper_->AddDatabaseSamples();
mock_browsing_data_database_helper_->Notify();
@@ -723,10 +816,13 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
mock_browsing_data_indexed_db_helper_->Notify();
mock_browsing_data_file_system_helper_->AddFileSystemSamples();
mock_browsing_data_file_system_helper_->Notify();
+ mock_browsing_data_quota_helper_->AddQuotaSamples();
+ mock_browsing_data_quota_helper_->Notify();
{
SCOPED_TRACE("Initial State 5 cookies, 2 databases, 2 local storages, "
- "2 session storages, 2 indexed DBs");
+ "2 session storages, 2 indexed DBs, 3 filesystems, "
+ "2 quotas.");
// 43 because there's the root, then foo1 -> cookies -> a,
// foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
// dbhost1 -> database -> db1, dbhost2 -> database -> db2,
@@ -738,8 +834,10 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
// host1 -> sessionstorage -> http://host1:1/,
// host2 -> sessionstorage -> http://host2:2/,
// idbhost1 -> sessionstorage -> http://idbhost1:1/,
- // idbhost2 -> sessionstorage -> http://idbhost2:2/.
- EXPECT_EQ(43, cookies_model.GetRoot()->GetTotalNodeCount());
+ // idbhost2 -> sessionstorage -> http://idbhost2:2/,
+ // quotahost1 -> quotahost1,
+ // quotahost2 -> quotahost2.
+ EXPECT_EQ(47, cookies_model.GetRoot()->GetTotalNodeCount());
EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
@@ -751,6 +849,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
GetDisplayedIndexedDBs(&cookies_model));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(&cookies_model));
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
}
DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)->GetChild(0)->
GetChild(1));
@@ -758,7 +857,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
SCOPED_TRACE("Middle cookie in third origin removed");
EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str());
EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str());
- EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ(46, cookies_model.GetRoot()->GetTotalNodeCount());
EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
EXPECT_EQ("http://host1:1/,http://host2:2/",
GetDisplayedLocalStorages(&cookies_model));
@@ -768,6 +867,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
GetDisplayedIndexedDBs(&cookies_model));
EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
GetDisplayedFileSystems(&cookies_model));
+ EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
}
}
@@ -785,6 +885,7 @@ TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
mock_browsing_data_appcache_helper_,
mock_browsing_data_indexed_db_helper_,
mock_browsing_data_file_system_helper_,
+ mock_browsing_data_quota_helper_,
false);
{
SCOPED_TRACE("Initial State 5 cookies");
@@ -823,6 +924,7 @@ TEST_F(CookiesTreeModelTest, OriginOrdering) {
new MockBrowsingDataAppCacheHelper(profile_.get()),
new MockBrowsingDataIndexedDBHelper(profile_.get()),
new MockBrowsingDataFileSystemHelper(profile_.get()),
+ new MockBrowsingDataQuotaHelper(profile_.get()),
false);
{
@@ -852,6 +954,7 @@ TEST_F(CookiesTreeModelTest, ContentSettings) {
new MockBrowsingDataAppCacheHelper(profile_.get()),
new MockBrowsingDataIndexedDBHelper(profile_.get()),
new MockBrowsingDataFileSystemHelper(profile_.get()),
+ new MockBrowsingDataQuotaHelper(profile_.get()),
false);
TestingProfile profile;
diff --git a/chrome/browser/mock_browsing_data_quota_helper.cc b/chrome/browser/mock_browsing_data_quota_helper.cc
new file mode 100644
index 0000000..45d2c41
--- /dev/null
+++ b/chrome/browser/mock_browsing_data_quota_helper.cc
@@ -0,0 +1,42 @@
+// 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 "chrome/browser/mock_browsing_data_quota_helper.h"
+
+MockBrowsingDataQuotaHelper::MockBrowsingDataQuotaHelper(Profile* profile)
+ : BrowsingDataQuotaHelper(BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::IO)) {}
+
+MockBrowsingDataQuotaHelper::~MockBrowsingDataQuotaHelper() {}
+
+void MockBrowsingDataQuotaHelper::StartFetching(
+ FetchResultCallback* callback) {
+ callback_.reset(callback);
+}
+
+void MockBrowsingDataQuotaHelper::CancelNotification() {
+ callback_.reset(NULL);
+}
+
+void MockBrowsingDataQuotaHelper::AddHost(
+ const std::string& host,
+ int64 temporary_usage,
+ int64 persistent_usage) {
+ response_.push_back(QuotaInfo(
+ host,
+ temporary_usage,
+ persistent_usage));
+}
+
+void MockBrowsingDataQuotaHelper::AddQuotaSamples() {
+ AddHost("quotahost1", 1, 2);
+ AddHost("quotahost2", 10, 20);
+}
+
+void MockBrowsingDataQuotaHelper::Notify() {
+ CHECK(callback_.get());
+ callback_->Run(response_);
+ callback_.reset();
+ response_.clear();
+}
diff --git a/chrome/browser/mock_browsing_data_quota_helper.h b/chrome/browser/mock_browsing_data_quota_helper.h
new file mode 100644
index 0000000..333e632
--- /dev/null
+++ b/chrome/browser/mock_browsing_data_quota_helper.h
@@ -0,0 +1,37 @@
+// 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 CHROME_BROWSER_MOCK_BROWSING_DATA_QUOTA_HELPER_H_
+#define CHROME_BROWSER_MOCK_BROWSING_DATA_QUOTA_HELPER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/browsing_data_quota_helper.h"
+
+class MockBrowsingDataQuotaHelper : public BrowsingDataQuotaHelper {
+ public:
+ explicit MockBrowsingDataQuotaHelper(Profile* profile);
+
+ virtual void StartFetching(FetchResultCallback* callback) OVERRIDE;
+ virtual void CancelNotification() OVERRIDE;
+
+ void AddHost(const std::string& host,
+ int64 temporary_usage,
+ int64 persistent_usage);
+ void AddQuotaSamples();
+ void Notify();
+
+ private:
+ virtual ~MockBrowsingDataQuotaHelper();
+
+ scoped_ptr<FetchResultCallback> callback_;
+ std::vector<QuotaInfo> response_;
+ Profile* profile_;
+};
+
+#endif // CHROME_BROWSER_MOCK_BROWSING_DATA_QUOTA_HELPER_H_
diff --git a/chrome/browser/resources/options/cookies_list.js b/chrome/browser/resources/options/cookies_list.js
index d4722cc..1650c11 100644
--- a/chrome/browser/resources/options/cookies_list.js
+++ b/chrome/browser/resources/options/cookies_list.js
@@ -119,6 +119,8 @@ cr.define('options', function() {
this.siteChild.className = 'cookie-site';
this.dataChild = this.ownerDocument.createElement('div');
this.dataChild.className = 'cookie-data';
+ this.sizeChild = this.ownerDocument.createElement('div');
+ this.sizeChild.className = 'cookie-size';
this.itemsChild = this.ownerDocument.createElement('div');
this.itemsChild.className = 'cookie-items';
this.infoChild = this.ownerDocument.createElement('div');
@@ -131,6 +133,7 @@ cr.define('options', function() {
var content = this.contentElement;
content.appendChild(this.siteChild);
content.appendChild(this.dataChild);
+ content.appendChild(this.sizeChild);
content.appendChild(this.itemsChild);
this.itemsChild.appendChild(this.infoChild);
if (this.origin && this.origin.data) {
@@ -250,6 +253,10 @@ cr.define('options', function() {
else
text = list[i];
this.dataChild.textContent = text;
+ if (info.quota && info.quota.totalUsage) {
+ this.sizeChild.textContent = info.quota.totalUsage;
+ }
+
if (this.expanded)
this.updateItems_();
},
@@ -430,18 +437,21 @@ cr.define('options', function() {
for (var i = 0; i < this.children.length; ++i)
this.children[i].collectSummaryInfo(info);
} else if (this.data && !this.data.hasChildren) {
- if (this.data.type == 'cookie')
+ if (this.data.type == 'cookie') {
info.cookies++;
- else if (this.data.type == 'database')
+ } else if (this.data.type == 'database') {
info.database = true;
- else if (this.data.type == 'local_storage')
+ } else if (this.data.type == 'local_storage') {
info.localStorage = true;
- else if (this.data.type == 'app_cache')
+ } else if (this.data.type == 'app_cache') {
info.appCache = true;
- else if (this.data.type == 'indexed_db')
+ } else if (this.data.type == 'indexed_db') {
info.indexedDb = true;
- else if (this.data.type == 'file_system')
+ } else if (this.data.type == 'file_system') {
info.fileSystem = true;
+ } else if (this.data.type == 'quota') {
+ info.quota = this.data;
+ }
}
},
@@ -474,6 +484,8 @@ cr.define('options', function() {
text = localStrings.getString('cookie_file_system');
break;
}
+ if (!text)
+ return;
var div = item.ownerDocument.createElement('div');
div.className = 'cookie-item';
// Help out screen readers and such: this is a clickable thing.
diff --git a/chrome/browser/resources/options/cookies_view.css b/chrome/browser/resources/options/cookies_view.css
index 19c5b42..2aab6b2 100644
--- a/chrome/browser/resources/options/cookies_view.css
+++ b/chrome/browser/resources/options/cookies_view.css
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2010 The Chromium Authors. All rights reserved.
+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.
*/
@@ -88,6 +88,12 @@ list.cookie-list > .deletable-item[selected] .cookie-site {
display: inline-block;
}
+.cookie-size {
+ display: inline-block;
+ float: right;
+ margin-right: 3em;
+}
+
list.cookie-list > .deletable-item[selected] .cookie-data {
-webkit-user-select: text;
}
diff --git a/chrome/browser/ui/webui/cookies_tree_model_util.cc b/chrome/browser/ui/webui/cookies_tree_model_util.cc
index ac744b49..05dc69c 100644
--- a/chrome/browser/ui/webui/cookies_tree_model_util.cc
+++ b/chrome/browser/ui/webui/cookies_tree_model_util.cc
@@ -41,6 +41,13 @@ static const char kKeyModified[] = "modified";
static const char kKeyPersistent[] = "persistent";
static const char kKeyTemporary[] = "temporary";
+static const char kKeyTotalUsage[] = "totalUsage";
+static const char kKeyTemporaryUsage[] = "temporaryUsage";
+static const char kKeyPersistentUsage[] = "persistentUsage";
+static const char kKeyPersistentQuota[] = "persistentQuota";
+
+static const int64 kNegligibleUsage = 1024; // 1KiB
+
// Encodes a pointer value into a hex string.
std::string PointerToHexString(const void* pointer) {
return base::HexEncode(&pointer, sizeof(pointer));
@@ -65,7 +72,7 @@ std::string GetTreeNodeId(CookieTreeNode* node) {
return PointerToHexString(node);
}
-void GetCookieTreeNodeDictionary(const CookieTreeNode& node,
+bool GetCookieTreeNodeDictionary(const CookieTreeNode& node,
DictionaryValue* dict) {
// Use node's address as an id for WebUI to look it up.
dict->SetString(kKeyId, PointerToHexString(&node));
@@ -190,12 +197,36 @@ void GetCookieTreeNodeDictionary(const CookieTreeNode& node,
IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
break;
}
+ case CookieTreeNode::DetailedInfo::TYPE_QUOTA: {
+ dict->SetString(kKeyType, "quota");
+ dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON");
+
+ const BrowsingDataQuotaHelper::QuotaInfo& quota_info =
+ *node.GetDetailedInfo().quota_info;
+ if (quota_info.temporary_usage + quota_info.persistent_usage <=
+ kNegligibleUsage)
+ return false;
+
+ dict->SetString(kKeyOrigin, quota_info.host);
+ dict->SetString(kKeyTotalUsage,
+ UTF16ToUTF8(ui::FormatBytes(
+ quota_info.temporary_usage +
+ quota_info.persistent_usage)));
+ dict->SetString(kKeyTemporaryUsage,
+ UTF16ToUTF8(ui::FormatBytes(
+ quota_info.temporary_usage)));
+ dict->SetString(kKeyPersistentUsage,
+ UTF16ToUTF8(ui::FormatBytes(
+ quota_info.persistent_usage)));
+ break;
+ }
default:
#if defined(OS_MACOSX)
dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER");
#endif
break;
}
+ return true;
}
void GetChildNodeList(CookieTreeNode* parent, int start, int count,
@@ -203,8 +234,10 @@ void GetChildNodeList(CookieTreeNode* parent, int start, int count,
for (int i = 0; i < count; ++i) {
DictionaryValue* dict = new DictionaryValue;
CookieTreeNode* child = parent->GetChild(start + i);
- GetCookieTreeNodeDictionary(*child, dict);
- nodes->Append(dict);
+ if (GetCookieTreeNodeDictionary(*child, dict))
+ nodes->Append(dict);
+ else
+ delete dict;
}
}
diff --git a/chrome/browser/ui/webui/cookies_tree_model_util.h b/chrome/browser/ui/webui/cookies_tree_model_util.h
index 2b27b65..2331292 100644
--- a/chrome/browser/ui/webui/cookies_tree_model_util.h
+++ b/chrome/browser/ui/webui/cookies_tree_model_util.h
@@ -21,7 +21,8 @@ namespace cookies_tree_model_util {
std::string GetTreeNodeId(CookieTreeNode* node);
// Populate given |dict| with cookie tree node properties.
-void GetCookieTreeNodeDictionary(const CookieTreeNode& node,
+// Returns false if the |node| does not need to be shown.
+bool GetCookieTreeNodeDictionary(const CookieTreeNode& node,
base::DictionaryValue* dict);
// Append the children nodes of |parent| in specified range to |nodes| list.
diff --git a/chrome/browser/ui/webui/options/cookies_view_handler.cc b/chrome/browser/ui/webui/options/cookies_view_handler.cc
index b2c1c7c..b046077 100644
--- a/chrome/browser/ui/webui/options/cookies_view_handler.cc
+++ b/chrome/browser/ui/webui/options/cookies_view_handler.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/browsing_data_database_helper.h"
#include "chrome/browser/browsing_data_file_system_helper.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
+#include "chrome/browser/browsing_data_quota_helper.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/cookies_tree_model_util.h"
@@ -66,7 +67,7 @@ void CookiesViewHandler::GetLocalizedValues(
{ "label_file_system_temporary_usage",
IDS_COOKIES_FILE_SYSTEM_TEMPORARY_USAGE_LABEL },
{ "label_file_system_persistent_usage",
- IDS_COOKIES_FILE_SYSTEM_PERSISTENT_USAGE_LABEL }
+ IDS_COOKIES_FILE_SYSTEM_PERSISTENT_USAGE_LABEL },
};
RegisterStrings(localized_strings, resources, arraysize(resources));
@@ -151,6 +152,7 @@ void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
new BrowsingDataAppCacheHelper(profile),
BrowsingDataIndexedDBHelper::Create(profile),
BrowsingDataFileSystemHelper::Create(profile),
+ BrowsingDataQuotaHelper::Create(profile),
false));
cookies_tree_model_->AddCookiesTreeObserver(this);
}