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