OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quota_internals_proxy.h" | 5 #include "chrome/browser/ui/webui/quota_internals/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/quota_internals_handler.h" | 11 #include "chrome/browser/ui/webui/quota_internals/quota_internals_handler.h" |
12 #include "chrome/browser/ui/webui/quota_internals/quota_internals_types.h" | 12 #include "chrome/browser/ui/webui/quota_internals/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_(this) { | 21 weak_factory_(this) { |
22 } | 22 } |
23 | 23 |
24 void QuotaInternalsProxy::RequestInfo( | 24 void QuotaInternalsProxy::RequestInfo( |
25 scoped_refptr<quota::QuotaManager> quota_manager) { | 25 scoped_refptr<storage::QuotaManager> quota_manager) { |
26 DCHECK(quota_manager.get()); | 26 DCHECK(quota_manager.get()); |
27 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 27 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
28 BrowserThread::PostTask( | 28 BrowserThread::PostTask( |
29 BrowserThread::IO, FROM_HERE, | 29 BrowserThread::IO, FROM_HERE, |
30 base::Bind(&QuotaInternalsProxy::RequestInfo, this, quota_manager)); | 30 base::Bind(&QuotaInternalsProxy::RequestInfo, this, quota_manager)); |
31 return; | 31 return; |
32 } | 32 } |
33 | 33 |
34 quota_manager_ = quota_manager; | 34 quota_manager_ = quota_manager; |
35 quota_manager_->GetAvailableSpace( | 35 quota_manager_->GetAvailableSpace( |
36 base::Bind(&QuotaInternalsProxy::DidGetAvailableSpace, | 36 base::Bind(&QuotaInternalsProxy::DidGetAvailableSpace, |
37 weak_factory_.GetWeakPtr())); | 37 weak_factory_.GetWeakPtr())); |
38 | 38 |
39 quota_manager_->GetTemporaryGlobalQuota( | 39 quota_manager_->GetTemporaryGlobalQuota( |
40 base::Bind(&QuotaInternalsProxy::DidGetGlobalQuota, | 40 base::Bind(&QuotaInternalsProxy::DidGetGlobalQuota, |
41 weak_factory_.GetWeakPtr(), quota::kStorageTypeTemporary)); | 41 weak_factory_.GetWeakPtr(), |
| 42 storage::kStorageTypeTemporary)); |
42 | 43 |
43 quota_manager_->GetGlobalUsage( | 44 quota_manager_->GetGlobalUsage( |
44 quota::kStorageTypeTemporary, | 45 storage::kStorageTypeTemporary, |
45 base::Bind(&QuotaInternalsProxy::DidGetGlobalUsage, | 46 base::Bind(&QuotaInternalsProxy::DidGetGlobalUsage, |
46 weak_factory_.GetWeakPtr(), | 47 weak_factory_.GetWeakPtr(), |
47 quota::kStorageTypeTemporary)); | 48 storage::kStorageTypeTemporary)); |
48 | 49 |
49 quota_manager_->GetGlobalUsage( | 50 quota_manager_->GetGlobalUsage( |
50 quota::kStorageTypePersistent, | 51 storage::kStorageTypePersistent, |
51 base::Bind(&QuotaInternalsProxy::DidGetGlobalUsage, | 52 base::Bind(&QuotaInternalsProxy::DidGetGlobalUsage, |
52 weak_factory_.GetWeakPtr(), | 53 weak_factory_.GetWeakPtr(), |
53 quota::kStorageTypePersistent)); | 54 storage::kStorageTypePersistent)); |
54 | 55 |
55 quota_manager_->GetGlobalUsage( | 56 quota_manager_->GetGlobalUsage( |
56 quota::kStorageTypeSyncable, | 57 storage::kStorageTypeSyncable, |
57 base::Bind(&QuotaInternalsProxy::DidGetGlobalUsage, | 58 base::Bind(&QuotaInternalsProxy::DidGetGlobalUsage, |
58 weak_factory_.GetWeakPtr(), | 59 weak_factory_.GetWeakPtr(), |
59 quota::kStorageTypeSyncable)); | 60 storage::kStorageTypeSyncable)); |
60 | 61 |
61 quota_manager_->DumpQuotaTable( | 62 quota_manager_->DumpQuotaTable( |
62 base::Bind(&QuotaInternalsProxy::DidDumpQuotaTable, | 63 base::Bind(&QuotaInternalsProxy::DidDumpQuotaTable, |
63 weak_factory_.GetWeakPtr())); | 64 weak_factory_.GetWeakPtr())); |
64 | 65 |
65 quota_manager_->DumpOriginInfoTable( | 66 quota_manager_->DumpOriginInfoTable( |
66 base::Bind(&QuotaInternalsProxy::DidDumpOriginInfoTable, | 67 base::Bind(&QuotaInternalsProxy::DidDumpOriginInfoTable, |
67 weak_factory_.GetWeakPtr())); | 68 weak_factory_.GetWeakPtr())); |
68 | 69 |
69 std::map<std::string, std::string> stats; | 70 std::map<std::string, std::string> stats; |
(...skipping 18 matching lines...) Expand all Loading... |
88 } | 89 } |
89 | 90 |
90 RELAY_TO_HANDLER(ReportAvailableSpace, int64) | 91 RELAY_TO_HANDLER(ReportAvailableSpace, int64) |
91 RELAY_TO_HANDLER(ReportGlobalInfo, const GlobalStorageInfo&) | 92 RELAY_TO_HANDLER(ReportGlobalInfo, const GlobalStorageInfo&) |
92 RELAY_TO_HANDLER(ReportPerHostInfo, const std::vector<PerHostStorageInfo>&) | 93 RELAY_TO_HANDLER(ReportPerHostInfo, const std::vector<PerHostStorageInfo>&) |
93 RELAY_TO_HANDLER(ReportPerOriginInfo, const std::vector<PerOriginStorageInfo>&) | 94 RELAY_TO_HANDLER(ReportPerOriginInfo, const std::vector<PerOriginStorageInfo>&) |
94 RELAY_TO_HANDLER(ReportStatistics, const Statistics&) | 95 RELAY_TO_HANDLER(ReportStatistics, const Statistics&) |
95 | 96 |
96 #undef RELAY_TO_HANDLER | 97 #undef RELAY_TO_HANDLER |
97 | 98 |
98 void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status, | 99 void QuotaInternalsProxy::DidGetAvailableSpace(storage::QuotaStatusCode status, |
99 int64 space) { | 100 int64 space) { |
100 if (status == quota::kQuotaStatusOk) | 101 if (status == storage::kQuotaStatusOk) |
101 ReportAvailableSpace(space); | 102 ReportAvailableSpace(space); |
102 } | 103 } |
103 | 104 |
104 void QuotaInternalsProxy::DidGetGlobalQuota(quota::StorageType type, | 105 void QuotaInternalsProxy::DidGetGlobalQuota(storage::StorageType type, |
105 quota::QuotaStatusCode status, | 106 storage::QuotaStatusCode status, |
106 int64 quota) { | 107 int64 quota) { |
107 if (status == quota::kQuotaStatusOk) { | 108 if (status == storage::kQuotaStatusOk) { |
108 GlobalStorageInfo info(type); | 109 GlobalStorageInfo info(type); |
109 info.set_quota(quota); | 110 info.set_quota(quota); |
110 ReportGlobalInfo(info); | 111 ReportGlobalInfo(info); |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
114 void QuotaInternalsProxy::DidGetGlobalUsage(quota::StorageType type, | 115 void QuotaInternalsProxy::DidGetGlobalUsage(storage::StorageType type, |
115 int64 usage, | 116 int64 usage, |
116 int64 unlimited_usage) { | 117 int64 unlimited_usage) { |
117 GlobalStorageInfo info(type); | 118 GlobalStorageInfo info(type); |
118 info.set_usage(usage); | 119 info.set_usage(usage); |
119 info.set_unlimited_usage(unlimited_usage); | 120 info.set_unlimited_usage(unlimited_usage); |
120 | 121 |
121 ReportGlobalInfo(info); | 122 ReportGlobalInfo(info); |
122 RequestPerOriginInfo(type); | 123 RequestPerOriginInfo(type); |
123 } | 124 } |
124 | 125 |
(...skipping 23 matching lines...) Expand all Loading... |
148 info.set_last_access_time(itr->last_access_time); | 149 info.set_last_access_time(itr->last_access_time); |
149 info.set_last_modified_time(itr->last_modified_time); | 150 info.set_last_modified_time(itr->last_modified_time); |
150 | 151 |
151 origin_info.push_back(info); | 152 origin_info.push_back(info); |
152 } | 153 } |
153 | 154 |
154 ReportPerOriginInfo(origin_info); | 155 ReportPerOriginInfo(origin_info); |
155 } | 156 } |
156 | 157 |
157 void QuotaInternalsProxy::DidGetHostUsage(const std::string& host, | 158 void QuotaInternalsProxy::DidGetHostUsage(const std::string& host, |
158 quota::StorageType type, | 159 storage::StorageType type, |
159 int64 usage) { | 160 int64 usage) { |
160 DCHECK(type == quota::kStorageTypeTemporary || | 161 DCHECK(type == storage::kStorageTypeTemporary || |
161 type == quota::kStorageTypePersistent || | 162 type == storage::kStorageTypePersistent || |
162 type == quota::kStorageTypeSyncable); | 163 type == storage::kStorageTypeSyncable); |
163 | 164 |
164 PerHostStorageInfo info(host, type); | 165 PerHostStorageInfo info(host, type); |
165 info.set_usage(usage); | 166 info.set_usage(usage); |
166 | 167 |
167 report_pending_.push_back(info); | 168 report_pending_.push_back(info); |
168 hosts_pending_.erase(make_pair(host, type)); | 169 hosts_pending_.erase(make_pair(host, type)); |
169 if (report_pending_.size() >= 10 || hosts_pending_.empty()) { | 170 if (report_pending_.size() >= 10 || hosts_pending_.empty()) { |
170 ReportPerHostInfo(report_pending_); | 171 ReportPerHostInfo(report_pending_); |
171 report_pending_.clear(); | 172 report_pending_.clear(); |
172 } | 173 } |
173 | 174 |
174 if (!hosts_pending_.empty()) | 175 if (!hosts_pending_.empty()) |
175 GetHostUsage(hosts_pending_.begin()->first, | 176 GetHostUsage(hosts_pending_.begin()->first, |
176 hosts_pending_.begin()->second); | 177 hosts_pending_.begin()->second); |
177 } | 178 } |
178 | 179 |
179 void QuotaInternalsProxy::RequestPerOriginInfo(quota::StorageType type) { | 180 void QuotaInternalsProxy::RequestPerOriginInfo(storage::StorageType type) { |
180 DCHECK(quota_manager_.get()); | 181 DCHECK(quota_manager_.get()); |
181 | 182 |
182 std::set<GURL> origins; | 183 std::set<GURL> origins; |
183 quota_manager_->GetCachedOrigins(type, &origins); | 184 quota_manager_->GetCachedOrigins(type, &origins); |
184 | 185 |
185 std::vector<PerOriginStorageInfo> origin_info; | 186 std::vector<PerOriginStorageInfo> origin_info; |
186 origin_info.reserve(origins.size()); | 187 origin_info.reserve(origins.size()); |
187 | 188 |
188 std::set<std::string> hosts; | 189 std::set<std::string> hosts; |
189 std::vector<PerHostStorageInfo> host_info; | 190 std::vector<PerHostStorageInfo> host_info; |
190 | 191 |
191 for (std::set<GURL>::iterator itr(origins.begin()); | 192 for (std::set<GURL>::iterator itr(origins.begin()); |
192 itr != origins.end(); ++itr) { | 193 itr != origins.end(); ++itr) { |
193 PerOriginStorageInfo info(*itr, type); | 194 PerOriginStorageInfo info(*itr, type); |
194 info.set_in_use(quota_manager_->IsOriginInUse(*itr)); | 195 info.set_in_use(quota_manager_->IsOriginInUse(*itr)); |
195 origin_info.push_back(info); | 196 origin_info.push_back(info); |
196 | 197 |
197 std::string host(net::GetHostOrSpecFromURL(*itr)); | 198 std::string host(net::GetHostOrSpecFromURL(*itr)); |
198 if (hosts.insert(host).second) { | 199 if (hosts.insert(host).second) { |
199 PerHostStorageInfo info(host, type); | 200 PerHostStorageInfo info(host, type); |
200 host_info.push_back(info); | 201 host_info.push_back(info); |
201 VisitHost(host, type); | 202 VisitHost(host, type); |
202 } | 203 } |
203 } | 204 } |
204 ReportPerOriginInfo(origin_info); | 205 ReportPerOriginInfo(origin_info); |
205 ReportPerHostInfo(host_info); | 206 ReportPerHostInfo(host_info); |
206 } | 207 } |
207 | 208 |
208 void QuotaInternalsProxy::VisitHost(const std::string& host, | 209 void QuotaInternalsProxy::VisitHost(const std::string& host, |
209 quota::StorageType type) { | 210 storage::StorageType type) { |
210 if (hosts_visited_.insert(std::make_pair(host, type)).second) { | 211 if (hosts_visited_.insert(std::make_pair(host, type)).second) { |
211 hosts_pending_.insert(std::make_pair(host, type)); | 212 hosts_pending_.insert(std::make_pair(host, type)); |
212 if (hosts_pending_.size() == 1) { | 213 if (hosts_pending_.size() == 1) { |
213 GetHostUsage(host, type); | 214 GetHostUsage(host, type); |
214 } | 215 } |
215 } | 216 } |
216 } | 217 } |
217 | 218 |
218 void QuotaInternalsProxy::GetHostUsage(const std::string& host, | 219 void QuotaInternalsProxy::GetHostUsage(const std::string& host, |
219 quota::StorageType type) { | 220 storage::StorageType type) { |
220 DCHECK(quota_manager_.get()); | 221 DCHECK(quota_manager_.get()); |
221 quota_manager_->GetHostUsage(host, | 222 quota_manager_->GetHostUsage(host, |
222 type, | 223 type, |
223 base::Bind(&QuotaInternalsProxy::DidGetHostUsage, | 224 base::Bind(&QuotaInternalsProxy::DidGetHostUsage, |
224 weak_factory_.GetWeakPtr(), | 225 weak_factory_.GetWeakPtr(), |
225 host, | 226 host, |
226 type)); | 227 type)); |
227 } | 228 } |
228 | 229 |
229 } // namespace quota_internals | 230 } // namespace quota_internals |
OLD | NEW |