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

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: '' 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 void QuotaInternalsProxy::ReportAvailableSpace(int64 available_space) {
22 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
23 BrowserThread::PostTask(
24 BrowserThread::UI, FROM_HERE,
25 NewRunnableMethod(this, &QuotaInternalsProxy::ReportAvailableSpace,
26 available_space));
27 return;
28 }
29 if (handler_)
30 handler_->ReportAvailableSpace(available_space);
31 }
32
33 void QuotaInternalsProxy::ReportGlobalData(const GlobalData& data) {
34 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
35 BrowserThread::PostTask(
36 BrowserThread::UI, FROM_HERE,
37 NewRunnableMethod(this, &QuotaInternalsProxy::ReportGlobalData,
38 data));
39 return;
40 }
41 if (handler_)
42 handler_->ReportGlobalData(data);
43 }
44
45 void QuotaInternalsProxy::ReportHostData(const std::vector<HostData>& hosts) {
46 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
47 BrowserThread::PostTask(
48 BrowserThread::UI, FROM_HERE,
49 NewRunnableMethod(this, &QuotaInternalsProxy::ReportHostData,
50 hosts));
51 return;
52 }
53 if (handler_)
54 handler_->ReportHostData(hosts);
55 }
56
57 void QuotaInternalsProxy::ReportOriginData(
58 const std::vector<OriginData>& origins) {
59 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
60 BrowserThread::PostTask(
61 BrowserThread::UI, FROM_HERE,
62 NewRunnableMethod(this, &QuotaInternalsProxy::ReportOriginData,
63 origins));
64 return;
65 }
66 if (handler_)
67 handler_->ReportOriginData(origins);
68 }
69
70 void QuotaInternalsProxy::ReportStatistics(const Statistics& stats) {
71 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
72 BrowserThread::PostTask(
73 BrowserThread::UI, FROM_HERE,
74 NewRunnableMethod(this, &QuotaInternalsProxy::ReportStatistics,
75 stats));
76 return;
77 }
78 if (handler_)
79 handler_->ReportStatistics(stats);
80 }
81
82 void QuotaInternalsProxy::RequestData(
83 scoped_refptr<quota::QuotaManager> quota_manager) {
84 DCHECK(quota_manager);
85 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
86 BrowserThread::PostTask(
87 BrowserThread::IO, FROM_HERE,
88 NewRunnableMethod(this, &QuotaInternalsProxy::RequestData,
89 quota_manager));
90 return;
91 }
92
93 quota_manager_ = quota_manager;
94 quota_manager_->GetAvailableSpace(
95 callback_factory_.NewCallback(
96 &QuotaInternalsProxy::DidGetAvailableSpace));
97
98 quota_manager_->GetTemporaryGlobalQuota(
99 callback_factory_.NewCallback(
100 &QuotaInternalsProxy::DidGetGlobalQuota));
101
102 quota_manager_->GetGlobalUsage(
103 quota::kStorageTypeTemporary,
104 callback_factory_.NewCallback(
105 &QuotaInternalsProxy::DidGetGlobalUsage));
106
107 quota_manager_->GetGlobalUsage(
108 quota::kStorageTypePersistent,
109 callback_factory_.NewCallback(
110 &QuotaInternalsProxy::DidGetGlobalUsage));
111
112 quota_manager_->DumpQuotaTable(
113 callback_factory_.NewCallback(
114 &QuotaInternalsProxy::DidDumpQuotaTable));
115
116 quota_manager_->DumpOriginInfoTable(
117 callback_factory_.NewCallback(
118 &QuotaInternalsProxy::DidDumpOriginInfoTable));
119
120 std::map<std::string, std::string> stats;
121 quota_manager_->GetStatistics(&stats);
122 ReportStatistics(stats);
123 }
124
125 void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status,
126 int64 space) {
127 if (status == quota::kQuotaStatusOk)
128 ReportAvailableSpace(space);
129 }
130
131 void QuotaInternalsProxy::DidGetGlobalQuota(quota::QuotaStatusCode status,
132 quota::StorageType type,
133 int64 quota) {
134 if (status == quota::kQuotaStatusOk)
135 ReportGlobalData(GlobalData(type, -1, -1, quota));
136 }
137
138 void QuotaInternalsProxy::DidGetGlobalUsage(quota::StorageType type,
139 int64 usage,
140 int64 unlimited_usage) {
141 ReportGlobalData(GlobalData(type, usage, unlimited_usage, -1));
142 RequestPerOriginData(type);
143 }
144
145 void QuotaInternalsProxy::DidDumpQuotaTable(const QuotaTableEntries& entries) {
146 std::vector<HostData> host_data;
147 host_data.reserve(entries.size());
148
149 typedef QuotaTableEntries::const_iterator iterator;
150 for (iterator itr(entries.begin()); itr != entries.end(); ++itr) {
151 host_data.push_back(HostData(itr->host, itr->type, -1, itr->quota));
152 }
153
154 ReportHostData(host_data);
155 }
156
157 void QuotaInternalsProxy::DidDumpOriginInfoTable(
158 const OriginInfoTableEntries& entries) {
159 std::vector<OriginData> origin_data;
160 origin_data.reserve(entries.size());
161
162 typedef OriginInfoTableEntries::const_iterator iterator;
163 for (iterator itr(entries.begin()); itr != entries.end(); ++itr) {
164 origin_data.push_back(
165 OriginData(itr->origin, itr->type,
166 -1, itr->used_count,
167 itr->last_access_time,
168 itr->last_modified_time));
169 }
170
171 ReportOriginData(origin_data);
172 }
173
174 void QuotaInternalsProxy::DidGetHostUsage(const std::string& host,
175 quota::StorageType type,
176 int64 usage) {
177 DCHECK(type == quota::kStorageTypeTemporary ||
178 type == quota::kStorageTypePersistent);
179
180 report_pending_.push_back(HostData(host, type, usage, -1));
181 hosts_pending_.erase(make_pair(host, type));
182 if (report_pending_.size() >= 10 || hosts_pending_.empty()) {
183 ReportHostData(report_pending_);
184 report_pending_.clear();
185 }
186
187 if (!hosts_pending_.empty())
188 GetHostUsage(hosts_pending_.begin()->first,
189 hosts_pending_.begin()->second);
190 }
191
192 void QuotaInternalsProxy::VisitHost(const std::string& host,
193 quota::StorageType type) {
194 if (hosts_visited_.insert(std::make_pair(host, type)).second) {
195 hosts_pending_.insert(std::make_pair(host, type));
196 if (hosts_pending_.size() == 1) {
197 GetHostUsage(host, type);
198 }
199 }
200 }
201
202 void QuotaInternalsProxy::GetHostUsage(const std::string& host,
203 quota::StorageType type) {
204 DCHECK(quota_manager_);
205 quota_manager_->GetHostUsage(
206 host, type,
207 callback_factory_.NewCallback(
208 &QuotaInternalsProxy::DidGetHostUsage));
209 }
210
211 void QuotaInternalsProxy::RequestPerOriginData(quota::StorageType type) {
212 DCHECK(quota_manager_);
213
214 std::set<GURL> origins;
215 quota_manager_->GetCachedOrigins(type, &origins);
216
217 std::vector<OriginData> origin_data;
218 origin_data.reserve(origins.size());
219
220 std::set<std::string> hosts;
221 std::vector<HostData> host_data;
222
223 for (std::set<GURL>::iterator itr(origins.begin());
224 itr != origins.end(); ++itr) {
225 origin_data.push_back(
226 OriginData(*itr, type,
227 quota_manager_->IsOriginInUse(*itr) ? 1 : 0, -1,
kinuko 2011/07/04 08:58:29 The fact that the caller needs to explicitly give
tzik 2011/07/06 22:49:04 Done. Sounds good.
228 base::Time(),
229 base::Time()));
230
231 std::string host(net::GetHostOrSpecFromURL(*itr));
232 if (hosts.insert(host).second) {
233 host_data.push_back(HostData(host, type, -1, -1));
234 VisitHost(host, type);
235 }
236 }
237 ReportOriginData(origin_data);
238 ReportHostData(host_data);
239 }
240
241 } // namespace quota_internals
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698