Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5316)

Unified Diff: chrome/browser/ui/webui/quota_internals_proxy.cc

Issue 7084024: Add chrome://quota-internals/ (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/quota_internals_proxy.cc
diff --git a/chrome/browser/ui/webui/quota_internals_proxy.cc b/chrome/browser/ui/webui/quota_internals_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..565cd7c22ff60ad196ffedd893dc0eb4a9849606
--- /dev/null
+++ b/chrome/browser/ui/webui/quota_internals_proxy.cc
@@ -0,0 +1,254 @@
+// 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/ui/webui/quota_internals_proxy.h"
+
+#include <set>
+#include <string>
+
+#include "chrome/browser/ui/webui/quota_internals_handler.h"
+#include "chrome/browser/ui/webui/quota_internals_types.h"
+#include "net/base/net_util.h"
+
+namespace quota_internals {
+
+QuotaInternalsProxy::QuotaInternalsProxy(QuotaInternalsHandler* handler)
+ : handler_(handler),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+}
+
+void QuotaInternalsProxy::ReportAvailableSpace(int64 available_space) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &QuotaInternalsProxy::ReportAvailableSpace,
+ available_space));
+ return;
+ }
+ if (handler_)
+ handler_->ReportAvailableSpace(available_space);
+}
+
+void QuotaInternalsProxy::ReportGlobalInfo(const GlobalStorageInfo& info) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &QuotaInternalsProxy::ReportGlobalInfo,
+ info));
+ return;
+ }
+ if (handler_)
+ handler_->ReportGlobalInfo(info);
+}
+
+void QuotaInternalsProxy::ReportPerHostInfo(
+ const std::vector<PerHostStorageInfo>& hosts) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &QuotaInternalsProxy::ReportPerHostInfo,
+ hosts));
+ return;
+ }
+ if (handler_)
Evan Stade 2011/07/07 20:58:17 seems like you could move this check above the thr
tzik 2011/07/07 23:00:35 Done.
+ handler_->ReportPerHostInfo(hosts);
+}
+
+void QuotaInternalsProxy::ReportPerOriginInfo(
+ const std::vector<PerOriginStorageInfo>& origins) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &QuotaInternalsProxy::ReportPerOriginInfo,
+ origins));
+ return;
+ }
+ if (handler_)
+ handler_->ReportPerOriginInfo(origins);
+}
+
+void QuotaInternalsProxy::ReportStatistics(const Statistics& stats) {
Evan Stade 2011/07/07 20:58:17 you use this pattern a lot, it seems ripe for a ma
tzik 2011/07/07 23:00:35 Done.
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &QuotaInternalsProxy::ReportStatistics,
+ stats));
+ return;
+ }
+ if (handler_)
+ handler_->ReportStatistics(stats);
+}
+
+void QuotaInternalsProxy::RequestInfo(
+ scoped_refptr<quota::QuotaManager> quota_manager) {
+ DCHECK(quota_manager);
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &QuotaInternalsProxy::RequestInfo,
+ quota_manager));
+ return;
+ }
+
+ quota_manager_ = quota_manager;
+ quota_manager_->GetAvailableSpace(
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidGetAvailableSpace));
+
+ quota_manager_->GetTemporaryGlobalQuota(
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidGetGlobalQuota));
+
+ quota_manager_->GetGlobalUsage(
+ quota::kStorageTypeTemporary,
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidGetGlobalUsage));
+
+ quota_manager_->GetGlobalUsage(
+ quota::kStorageTypePersistent,
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidGetGlobalUsage));
+
+ quota_manager_->DumpQuotaTable(
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidDumpQuotaTable));
+
+ quota_manager_->DumpOriginInfoTable(
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidDumpOriginInfoTable));
+
+ std::map<std::string, std::string> stats;
+ quota_manager_->GetStatistics(&stats);
+ ReportStatistics(stats);
+}
+
+void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status,
+ int64 space) {
+ if (status == quota::kQuotaStatusOk)
+ ReportAvailableSpace(space);
+}
+
+void QuotaInternalsProxy::DidGetGlobalQuota(quota::QuotaStatusCode status,
+ quota::StorageType type,
+ int64 quota) {
+ if (status == quota::kQuotaStatusOk) {
+ GlobalStorageInfo info(type);
+ info.set_quota(quota);
+ ReportGlobalInfo(info);
+ }
+}
+
+void QuotaInternalsProxy::DidGetGlobalUsage(quota::StorageType type,
+ int64 usage,
+ int64 unlimited_usage) {
+ GlobalStorageInfo info(type);
+ info.set_usage(usage);
+ info.set_unlimited_usage(unlimited_usage);
+
+ ReportGlobalInfo(info);
+ RequestPerOriginInfo(type);
+}
+
+void QuotaInternalsProxy::DidDumpQuotaTable(const QuotaTableEntries& entries) {
+ std::vector<PerHostStorageInfo> host_info;
+ host_info.reserve(entries.size());
+
+ typedef QuotaTableEntries::const_iterator iterator;
+ for (iterator itr(entries.begin()); itr != entries.end(); ++itr) {
+ PerHostStorageInfo info(itr->host, itr->type);
+ info.set_quota(itr->quota);
+ host_info.push_back(info);
+ }
+
+ ReportPerHostInfo(host_info);
+}
+
+void QuotaInternalsProxy::DidDumpOriginInfoTable(
+ const OriginInfoTableEntries& entries) {
+ std::vector<PerOriginStorageInfo> origin_info;
+ origin_info.reserve(entries.size());
+
+ typedef OriginInfoTableEntries::const_iterator iterator;
+ for (iterator itr(entries.begin()); itr != entries.end(); ++itr) {
+ PerOriginStorageInfo info(itr->origin, itr->type);
+ info.set_used_count(itr->used_count);
+ info.set_last_access_time(itr->last_access_time);
+ info.set_last_modified_time(itr->last_modified_time);
+
+ origin_info.push_back(info);
+ }
+
+ ReportPerOriginInfo(origin_info);
+}
+
+void QuotaInternalsProxy::DidGetHostUsage(const std::string& host,
+ quota::StorageType type,
+ int64 usage) {
+ DCHECK(type == quota::kStorageTypeTemporary ||
+ type == quota::kStorageTypePersistent);
+
+ PerHostStorageInfo info(host, type);
+ info.set_usage(usage);
+
+ report_pending_.push_back(info);
+ hosts_pending_.erase(make_pair(host, type));
+ if (report_pending_.size() >= 10 || hosts_pending_.empty()) {
+ ReportPerHostInfo(report_pending_);
+ report_pending_.clear();
+ }
+
+ if (!hosts_pending_.empty())
+ GetHostUsage(hosts_pending_.begin()->first,
+ hosts_pending_.begin()->second);
+}
+
+void QuotaInternalsProxy::VisitHost(const std::string& host,
+ quota::StorageType type) {
+ if (hosts_visited_.insert(std::make_pair(host, type)).second) {
+ hosts_pending_.insert(std::make_pair(host, type));
+ if (hosts_pending_.size() == 1) {
+ GetHostUsage(host, type);
+ }
+ }
+}
+
+void QuotaInternalsProxy::GetHostUsage(const std::string& host,
+ quota::StorageType type) {
+ DCHECK(quota_manager_);
+ quota_manager_->GetHostUsage(
+ host, type,
+ callback_factory_.NewCallback(
+ &QuotaInternalsProxy::DidGetHostUsage));
+}
+
+void QuotaInternalsProxy::RequestPerOriginInfo(quota::StorageType type) {
+ DCHECK(quota_manager_);
+
+ std::set<GURL> origins;
+ quota_manager_->GetCachedOrigins(type, &origins);
+
+ std::vector<PerOriginStorageInfo> origin_info;
+ origin_info.reserve(origins.size());
+
+ std::set<std::string> hosts;
+ std::vector<PerHostStorageInfo> host_info;
+
+ for (std::set<GURL>::iterator itr(origins.begin());
+ itr != origins.end(); ++itr) {
+ PerOriginStorageInfo info(*itr, type);
+ info.set_in_use(quota_manager_->IsOriginInUse(*itr));
+ origin_info.push_back(info);
+
+ std::string host(net::GetHostOrSpecFromURL(*itr));
+ if (hosts.insert(host).second) {
+ PerHostStorageInfo info(host, type);
+ host_info.push_back(info);
+ VisitHost(host, type);
+ }
+ }
+ ReportPerOriginInfo(origin_info);
+ ReportPerHostInfo(host_info);
+}
+
+} // namespace quota_internals

Powered by Google App Engine
This is Rietveld 408576698