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

Side by Side Diff: chrome/browser/ui/webui/quota_internals_proxy.cc

Issue 10067033: RefCounted types should not have public destructors, chrome/browser/ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fix Created 8 years, 8 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
« no previous file with comments | « chrome/browser/ui/webui/quota_internals_proxy.h ('k') | chrome/browser/ui/webui/tracing_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/quota_internals_proxy.h" 5 #include "chrome/browser/ui/webui/quota_internals_proxy.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "chrome/browser/ui/webui/quota_internals_handler.h" 11 #include "chrome/browser/ui/webui/quota_internals_handler.h"
12 #include "chrome/browser/ui/webui/quota_internals_types.h" 12 #include "chrome/browser/ui/webui/quota_internals_types.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 14
15 using content::BrowserThread; 15 using content::BrowserThread;
16 16
17 namespace quota_internals { 17 namespace quota_internals {
18 18
19 QuotaInternalsProxy::QuotaInternalsProxy(QuotaInternalsHandler* handler) 19 QuotaInternalsProxy::QuotaInternalsProxy(QuotaInternalsHandler* handler)
20 : handler_(handler), 20 : handler_(handler),
21 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 21 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
22 } 22 }
23 23
24 QuotaInternalsProxy::~QuotaInternalsProxy() {}
25
26 #define RELAY_TO_HANDLER(func, arg_t) \
27 void QuotaInternalsProxy::func(arg_t arg) { \
28 if (!handler_) \
29 return; \
30 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { \
31 BrowserThread::PostTask( \
32 BrowserThread::UI, FROM_HERE, \
33 base::Bind(&QuotaInternalsProxy::func, this, arg)); \
34 return; \
35 } \
36 \
37 handler_->func(arg); \
38 }
39
40 RELAY_TO_HANDLER(ReportAvailableSpace, int64)
41 RELAY_TO_HANDLER(ReportGlobalInfo, const GlobalStorageInfo&)
42 RELAY_TO_HANDLER(ReportPerHostInfo, const std::vector<PerHostStorageInfo>&)
43 RELAY_TO_HANDLER(ReportPerOriginInfo, const std::vector<PerOriginStorageInfo>&)
44 RELAY_TO_HANDLER(ReportStatistics, const Statistics&)
45
46 #undef RELAY_TO_HANDLER
47
48 void QuotaInternalsProxy::RequestInfo( 24 void QuotaInternalsProxy::RequestInfo(
49 scoped_refptr<quota::QuotaManager> quota_manager) { 25 scoped_refptr<quota::QuotaManager> quota_manager) {
50 DCHECK(quota_manager); 26 DCHECK(quota_manager);
51 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 27 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
52 BrowserThread::PostTask( 28 BrowserThread::PostTask(
53 BrowserThread::IO, FROM_HERE, 29 BrowserThread::IO, FROM_HERE,
54 base::Bind(&QuotaInternalsProxy::RequestInfo, this, quota_manager)); 30 base::Bind(&QuotaInternalsProxy::RequestInfo, this, quota_manager));
55 return; 31 return;
56 } 32 }
57 33
(...skipping 22 matching lines...) Expand all
80 56
81 quota_manager_->DumpOriginInfoTable( 57 quota_manager_->DumpOriginInfoTable(
82 base::Bind(&QuotaInternalsProxy::DidDumpOriginInfoTable, 58 base::Bind(&QuotaInternalsProxy::DidDumpOriginInfoTable,
83 weak_factory_.GetWeakPtr())); 59 weak_factory_.GetWeakPtr()));
84 60
85 std::map<std::string, std::string> stats; 61 std::map<std::string, std::string> stats;
86 quota_manager_->GetStatistics(&stats); 62 quota_manager_->GetStatistics(&stats);
87 ReportStatistics(stats); 63 ReportStatistics(stats);
88 } 64 }
89 65
66 QuotaInternalsProxy::~QuotaInternalsProxy() {}
67
68 #define RELAY_TO_HANDLER(func, arg_t) \
69 void QuotaInternalsProxy::func(arg_t arg) { \
70 if (!handler_) \
71 return; \
72 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { \
73 BrowserThread::PostTask( \
74 BrowserThread::UI, FROM_HERE, \
75 base::Bind(&QuotaInternalsProxy::func, this, arg)); \
76 return; \
77 } \
78 \
79 handler_->func(arg); \
80 }
81
82 RELAY_TO_HANDLER(ReportAvailableSpace, int64)
83 RELAY_TO_HANDLER(ReportGlobalInfo, const GlobalStorageInfo&)
84 RELAY_TO_HANDLER(ReportPerHostInfo, const std::vector<PerHostStorageInfo>&)
85 RELAY_TO_HANDLER(ReportPerOriginInfo, const std::vector<PerOriginStorageInfo>&)
86 RELAY_TO_HANDLER(ReportStatistics, const Statistics&)
87
88 #undef RELAY_TO_HANDLER
89
90 void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status, 90 void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status,
91 int64 space) { 91 int64 space) {
92 if (status == quota::kQuotaStatusOk) 92 if (status == quota::kQuotaStatusOk)
93 ReportAvailableSpace(space); 93 ReportAvailableSpace(space);
94 } 94 }
95 95
96 void QuotaInternalsProxy::DidGetGlobalQuota(quota::QuotaStatusCode status, 96 void QuotaInternalsProxy::DidGetGlobalQuota(quota::QuotaStatusCode status,
97 quota::StorageType type, 97 quota::StorageType type,
98 int64 quota) { 98 int64 quota) {
99 if (status == quota::kQuotaStatusOk) { 99 if (status == quota::kQuotaStatusOk) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (report_pending_.size() >= 10 || hosts_pending_.empty()) { 160 if (report_pending_.size() >= 10 || hosts_pending_.empty()) {
161 ReportPerHostInfo(report_pending_); 161 ReportPerHostInfo(report_pending_);
162 report_pending_.clear(); 162 report_pending_.clear();
163 } 163 }
164 164
165 if (!hosts_pending_.empty()) 165 if (!hosts_pending_.empty())
166 GetHostUsage(hosts_pending_.begin()->first, 166 GetHostUsage(hosts_pending_.begin()->first,
167 hosts_pending_.begin()->second); 167 hosts_pending_.begin()->second);
168 } 168 }
169 169
170 void QuotaInternalsProxy::VisitHost(const std::string& host,
171 quota::StorageType type) {
172 if (hosts_visited_.insert(std::make_pair(host, type)).second) {
173 hosts_pending_.insert(std::make_pair(host, type));
174 if (hosts_pending_.size() == 1) {
175 GetHostUsage(host, type);
176 }
177 }
178 }
179
180 void QuotaInternalsProxy::GetHostUsage(const std::string& host,
181 quota::StorageType type) {
182 DCHECK(quota_manager_);
183 quota_manager_->GetHostUsage(
184 host, type,
185 base::Bind(&QuotaInternalsProxy::DidGetHostUsage,
186 weak_factory_.GetWeakPtr()));
187 }
188
189 void QuotaInternalsProxy::RequestPerOriginInfo(quota::StorageType type) { 170 void QuotaInternalsProxy::RequestPerOriginInfo(quota::StorageType type) {
190 DCHECK(quota_manager_); 171 DCHECK(quota_manager_);
191 172
192 std::set<GURL> origins; 173 std::set<GURL> origins;
193 quota_manager_->GetCachedOrigins(type, &origins); 174 quota_manager_->GetCachedOrigins(type, &origins);
194 175
195 std::vector<PerOriginStorageInfo> origin_info; 176 std::vector<PerOriginStorageInfo> origin_info;
196 origin_info.reserve(origins.size()); 177 origin_info.reserve(origins.size());
197 178
198 std::set<std::string> hosts; 179 std::set<std::string> hosts;
199 std::vector<PerHostStorageInfo> host_info; 180 std::vector<PerHostStorageInfo> host_info;
200 181
201 for (std::set<GURL>::iterator itr(origins.begin()); 182 for (std::set<GURL>::iterator itr(origins.begin());
202 itr != origins.end(); ++itr) { 183 itr != origins.end(); ++itr) {
203 PerOriginStorageInfo info(*itr, type); 184 PerOriginStorageInfo info(*itr, type);
204 info.set_in_use(quota_manager_->IsOriginInUse(*itr)); 185 info.set_in_use(quota_manager_->IsOriginInUse(*itr));
205 origin_info.push_back(info); 186 origin_info.push_back(info);
206 187
207 std::string host(net::GetHostOrSpecFromURL(*itr)); 188 std::string host(net::GetHostOrSpecFromURL(*itr));
208 if (hosts.insert(host).second) { 189 if (hosts.insert(host).second) {
209 PerHostStorageInfo info(host, type); 190 PerHostStorageInfo info(host, type);
210 host_info.push_back(info); 191 host_info.push_back(info);
211 VisitHost(host, type); 192 VisitHost(host, type);
212 } 193 }
213 } 194 }
214 ReportPerOriginInfo(origin_info); 195 ReportPerOriginInfo(origin_info);
215 ReportPerHostInfo(host_info); 196 ReportPerHostInfo(host_info);
216 } 197 }
217 198
199 void QuotaInternalsProxy::VisitHost(const std::string& host,
200 quota::StorageType type) {
201 if (hosts_visited_.insert(std::make_pair(host, type)).second) {
202 hosts_pending_.insert(std::make_pair(host, type));
203 if (hosts_pending_.size() == 1) {
204 GetHostUsage(host, type);
205 }
206 }
207 }
208
209 void QuotaInternalsProxy::GetHostUsage(const std::string& host,
210 quota::StorageType type) {
211 DCHECK(quota_manager_);
212 quota_manager_->GetHostUsage(
213 host, type,
214 base::Bind(&QuotaInternalsProxy::DidGetHostUsage,
215 weak_factory_.GetWeakPtr()));
216 }
217
218 } // namespace quota_internals 218 } // namespace quota_internals
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/quota_internals_proxy.h ('k') | chrome/browser/ui/webui/tracing_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698