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

Side by Side 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: fix clang compile error 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/quota_internals_proxy.h"
6
7 #include <set>
8 #include <string>
9
10 #include "chrome/browser/ui/webui/quota_internals_handler.h"
11 #include "chrome/browser/ui/webui/quota_internals_types.h"
12 #include "net/base/net_util.h"
13
14 namespace quota_internals {
15
16 QuotaInternalsProxy::QuotaInternalsProxy(QuotaInternalsHandler* handler)
17 : handler_(handler),
18 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
19 }
20
21 QuotaInternalsProxy::~QuotaInternalsProxy() {}
22
23 #define RELAY_TO_HANDLER(func, arg_t) \
24 void QuotaInternalsProxy::func(arg_t arg) { \
25 if (!handler_) \
26 return; \
27 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { \
28 BrowserThread::PostTask( \
29 BrowserThread::UI, FROM_HERE, \
30 NewRunnableMethod(this, &QuotaInternalsProxy::func, \
31 arg)); \
32 return; \
33 } \
34 \
35 handler_->func(arg); \
36 }
37
38 RELAY_TO_HANDLER(ReportAvailableSpace, int64)
39 RELAY_TO_HANDLER(ReportGlobalInfo, const GlobalStorageInfo&)
40 RELAY_TO_HANDLER(ReportPerHostInfo, const std::vector<PerHostStorageInfo>&)
41 RELAY_TO_HANDLER(ReportPerOriginInfo, const std::vector<PerOriginStorageInfo>&)
42 RELAY_TO_HANDLER(ReportStatistics, const Statistics&)
43
44 #undef RELAY_TO_HANDLER
45
46 void QuotaInternalsProxy::RequestInfo(
47 scoped_refptr<quota::QuotaManager> quota_manager) {
48 DCHECK(quota_manager);
49 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
50 BrowserThread::PostTask(
51 BrowserThread::IO, FROM_HERE,
52 NewRunnableMethod(this, &QuotaInternalsProxy::RequestInfo,
53 quota_manager));
54 return;
55 }
56
57 quota_manager_ = quota_manager;
58 quota_manager_->GetAvailableSpace(
59 callback_factory_.NewCallback(
60 &QuotaInternalsProxy::DidGetAvailableSpace));
61
62 quota_manager_->GetTemporaryGlobalQuota(
63 callback_factory_.NewCallback(
64 &QuotaInternalsProxy::DidGetGlobalQuota));
65
66 quota_manager_->GetGlobalUsage(
67 quota::kStorageTypeTemporary,
68 callback_factory_.NewCallback(
69 &QuotaInternalsProxy::DidGetGlobalUsage));
70
71 quota_manager_->GetGlobalUsage(
72 quota::kStorageTypePersistent,
73 callback_factory_.NewCallback(
74 &QuotaInternalsProxy::DidGetGlobalUsage));
75
76 quota_manager_->DumpQuotaTable(
77 callback_factory_.NewCallback(
78 &QuotaInternalsProxy::DidDumpQuotaTable));
79
80 quota_manager_->DumpOriginInfoTable(
81 callback_factory_.NewCallback(
82 &QuotaInternalsProxy::DidDumpOriginInfoTable));
83
84 std::map<std::string, std::string> stats;
85 quota_manager_->GetStatistics(&stats);
86 ReportStatistics(stats);
87 }
88
89 void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status,
90 int64 space) {
91 if (status == quota::kQuotaStatusOk)
92 ReportAvailableSpace(space);
93 }
94
95 void QuotaInternalsProxy::DidGetGlobalQuota(quota::QuotaStatusCode status,
96 quota::StorageType type,
97 int64 quota) {
98 if (status == quota::kQuotaStatusOk) {
99 GlobalStorageInfo info(type);
100 info.set_quota(quota);
101 ReportGlobalInfo(info);
102 }
103 }
104
105 void QuotaInternalsProxy::DidGetGlobalUsage(quota::StorageType type,
106 int64 usage,
107 int64 unlimited_usage) {
108 GlobalStorageInfo info(type);
109 info.set_usage(usage);
110 info.set_unlimited_usage(unlimited_usage);
111
112 ReportGlobalInfo(info);
113 RequestPerOriginInfo(type);
114 }
115
116 void QuotaInternalsProxy::DidDumpQuotaTable(const QuotaTableEntries& entries) {
117 std::vector<PerHostStorageInfo> host_info;
118 host_info.reserve(entries.size());
119
120 typedef QuotaTableEntries::const_iterator iterator;
121 for (iterator itr(entries.begin()); itr != entries.end(); ++itr) {
122 PerHostStorageInfo info(itr->host, itr->type);
123 info.set_quota(itr->quota);
124 host_info.push_back(info);
125 }
126
127 ReportPerHostInfo(host_info);
128 }
129
130 void QuotaInternalsProxy::DidDumpOriginInfoTable(
131 const OriginInfoTableEntries& entries) {
132 std::vector<PerOriginStorageInfo> origin_info;
133 origin_info.reserve(entries.size());
134
135 typedef OriginInfoTableEntries::const_iterator iterator;
136 for (iterator itr(entries.begin()); itr != entries.end(); ++itr) {
137 PerOriginStorageInfo info(itr->origin, itr->type);
138 info.set_used_count(itr->used_count);
139 info.set_last_access_time(itr->last_access_time);
140 info.set_last_modified_time(itr->last_modified_time);
141
142 origin_info.push_back(info);
143 }
144
145 ReportPerOriginInfo(origin_info);
146 }
147
148 void QuotaInternalsProxy::DidGetHostUsage(const std::string& host,
149 quota::StorageType type,
150 int64 usage) {
151 DCHECK(type == quota::kStorageTypeTemporary ||
152 type == quota::kStorageTypePersistent);
153
154 PerHostStorageInfo info(host, type);
155 info.set_usage(usage);
156
157 report_pending_.push_back(info);
158 hosts_pending_.erase(make_pair(host, type));
159 if (report_pending_.size() >= 10 || hosts_pending_.empty()) {
160 ReportPerHostInfo(report_pending_);
161 report_pending_.clear();
162 }
163
164 if (!hosts_pending_.empty())
165 GetHostUsage(hosts_pending_.begin()->first,
166 hosts_pending_.begin()->second);
167 }
168
169 void QuotaInternalsProxy::VisitHost(const std::string& host,
170 quota::StorageType type) {
171 if (hosts_visited_.insert(std::make_pair(host, type)).second) {
172 hosts_pending_.insert(std::make_pair(host, type));
173 if (hosts_pending_.size() == 1) {
174 GetHostUsage(host, type);
175 }
176 }
177 }
178
179 void QuotaInternalsProxy::GetHostUsage(const std::string& host,
180 quota::StorageType type) {
181 DCHECK(quota_manager_);
182 quota_manager_->GetHostUsage(
183 host, type,
184 callback_factory_.NewCallback(
185 &QuotaInternalsProxy::DidGetHostUsage));
186 }
187
188 void QuotaInternalsProxy::RequestPerOriginInfo(quota::StorageType type) {
189 DCHECK(quota_manager_);
190
191 std::set<GURL> origins;
192 quota_manager_->GetCachedOrigins(type, &origins);
193
194 std::vector<PerOriginStorageInfo> origin_info;
195 origin_info.reserve(origins.size());
196
197 std::set<std::string> hosts;
198 std::vector<PerHostStorageInfo> host_info;
199
200 for (std::set<GURL>::iterator itr(origins.begin());
201 itr != origins.end(); ++itr) {
202 PerOriginStorageInfo info(*itr, type);
203 info.set_in_use(quota_manager_->IsOriginInUse(*itr));
204 origin_info.push_back(info);
205
206 std::string host(net::GetHostOrSpecFromURL(*itr));
207 if (hosts.insert(host).second) {
208 PerHostStorageInfo info(host, type);
209 host_info.push_back(info);
210 VisitHost(host, type);
211 }
212 }
213 ReportPerOriginInfo(origin_info);
214 ReportPerHostInfo(host_info);
215 }
216
217 } // namespace quota_internals
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/quota_internals_proxy.h ('k') | chrome/browser/ui/webui/quota_internals_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698