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 #define RELAY_TO_HANDLER(func, arg_t) \ | |
| 22 void QuotaInternalsProxy::func(arg_t arg) { \ | |
| 23 if (!handler_) \ | |
| 24 return; \ | |
| 25 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { \ | |
| 26 BrowserThread::PostTask( \ | |
| 27 BrowserThread::UI, FROM_HERE, \ | |
| 28 NewRunnableMethod(this, &QuotaInternalsProxy::func, \ | |
| 29 arg)); \ | |
| 30 return; \ | |
| 31 } \ | |
| 32 \ | |
| 33 handler_->func(arg); \ | |
| 34 } | |
| 35 | |
| 36 RELAY_TO_HANDLER(ReportAvailableSpace, int64) | |
| 37 RELAY_TO_HANDLER(ReportGlobalInfo, const GlobalStorageInfo&) | |
| 38 RELAY_TO_HANDLER(ReportPerHostInfo, const std::vector<PerHostStorageInfo>&) | |
| 39 RELAY_TO_HANDLER(ReportPerOriginInfo, const std::vector<PerOriginStorageInfo>&) | |
| 40 RELAY_TO_HANDLER(ReportStatistics, const Statistics&) | |
| 41 | |
| 42 #undef RELAY_TO_HANDLER | |
|
Evan Stade
2011/07/11 20:53:23
I don't think you need to worry about undefing thi
| |
| 43 | |
| 44 void QuotaInternalsProxy::RequestInfo( | |
| 45 scoped_refptr<quota::QuotaManager> quota_manager) { | |
| 46 DCHECK(quota_manager); | |
| 47 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
| 48 BrowserThread::PostTask( | |
| 49 BrowserThread::IO, FROM_HERE, | |
| 50 NewRunnableMethod(this, &QuotaInternalsProxy::RequestInfo, | |
| 51 quota_manager)); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 quota_manager_ = quota_manager; | |
| 56 quota_manager_->GetAvailableSpace( | |
| 57 callback_factory_.NewCallback( | |
| 58 &QuotaInternalsProxy::DidGetAvailableSpace)); | |
| 59 | |
| 60 quota_manager_->GetTemporaryGlobalQuota( | |
| 61 callback_factory_.NewCallback( | |
| 62 &QuotaInternalsProxy::DidGetGlobalQuota)); | |
| 63 | |
| 64 quota_manager_->GetGlobalUsage( | |
| 65 quota::kStorageTypeTemporary, | |
| 66 callback_factory_.NewCallback( | |
| 67 &QuotaInternalsProxy::DidGetGlobalUsage)); | |
| 68 | |
| 69 quota_manager_->GetGlobalUsage( | |
| 70 quota::kStorageTypePersistent, | |
| 71 callback_factory_.NewCallback( | |
| 72 &QuotaInternalsProxy::DidGetGlobalUsage)); | |
| 73 | |
| 74 quota_manager_->DumpQuotaTable( | |
| 75 callback_factory_.NewCallback( | |
| 76 &QuotaInternalsProxy::DidDumpQuotaTable)); | |
| 77 | |
| 78 quota_manager_->DumpOriginInfoTable( | |
| 79 callback_factory_.NewCallback( | |
| 80 &QuotaInternalsProxy::DidDumpOriginInfoTable)); | |
| 81 | |
| 82 std::map<std::string, std::string> stats; | |
| 83 quota_manager_->GetStatistics(&stats); | |
| 84 ReportStatistics(stats); | |
| 85 } | |
| 86 | |
| 87 void QuotaInternalsProxy::DidGetAvailableSpace(quota::QuotaStatusCode status, | |
| 88 int64 space) { | |
| 89 if (status == quota::kQuotaStatusOk) | |
| 90 ReportAvailableSpace(space); | |
| 91 } | |
| 92 | |
| 93 void QuotaInternalsProxy::DidGetGlobalQuota(quota::QuotaStatusCode status, | |
| 94 quota::StorageType type, | |
| 95 int64 quota) { | |
| 96 if (status == quota::kQuotaStatusOk) { | |
| 97 GlobalStorageInfo info(type); | |
| 98 info.set_quota(quota); | |
| 99 ReportGlobalInfo(info); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void QuotaInternalsProxy::DidGetGlobalUsage(quota::StorageType type, | |
| 104 int64 usage, | |
| 105 int64 unlimited_usage) { | |
| 106 GlobalStorageInfo info(type); | |
| 107 info.set_usage(usage); | |
| 108 info.set_unlimited_usage(unlimited_usage); | |
| 109 | |
| 110 ReportGlobalInfo(info); | |
| 111 RequestPerOriginInfo(type); | |
| 112 } | |
| 113 | |
| 114 void QuotaInternalsProxy::DidDumpQuotaTable(const QuotaTableEntries& entries) { | |
| 115 std::vector<PerHostStorageInfo> host_info; | |
| 116 host_info.reserve(entries.size()); | |
| 117 | |
| 118 typedef QuotaTableEntries::const_iterator iterator; | |
| 119 for (iterator itr(entries.begin()); itr != entries.end(); ++itr) { | |
| 120 PerHostStorageInfo info(itr->host, itr->type); | |
| 121 info.set_quota(itr->quota); | |
| 122 host_info.push_back(info); | |
| 123 } | |
| 124 | |
| 125 ReportPerHostInfo(host_info); | |
| 126 } | |
| 127 | |
| 128 void QuotaInternalsProxy::DidDumpOriginInfoTable( | |
| 129 const OriginInfoTableEntries& entries) { | |
| 130 std::vector<PerOriginStorageInfo> origin_info; | |
| 131 origin_info.reserve(entries.size()); | |
| 132 | |
| 133 typedef OriginInfoTableEntries::const_iterator iterator; | |
| 134 for (iterator itr(entries.begin()); itr != entries.end(); ++itr) { | |
| 135 PerOriginStorageInfo info(itr->origin, itr->type); | |
| 136 info.set_used_count(itr->used_count); | |
| 137 info.set_last_access_time(itr->last_access_time); | |
| 138 info.set_last_modified_time(itr->last_modified_time); | |
| 139 | |
| 140 origin_info.push_back(info); | |
| 141 } | |
| 142 | |
| 143 ReportPerOriginInfo(origin_info); | |
| 144 } | |
| 145 | |
| 146 void QuotaInternalsProxy::DidGetHostUsage(const std::string& host, | |
| 147 quota::StorageType type, | |
| 148 int64 usage) { | |
| 149 DCHECK(type == quota::kStorageTypeTemporary || | |
| 150 type == quota::kStorageTypePersistent); | |
| 151 | |
| 152 PerHostStorageInfo info(host, type); | |
| 153 info.set_usage(usage); | |
| 154 | |
| 155 report_pending_.push_back(info); | |
| 156 hosts_pending_.erase(make_pair(host, type)); | |
| 157 if (report_pending_.size() >= 10 || hosts_pending_.empty()) { | |
| 158 ReportPerHostInfo(report_pending_); | |
| 159 report_pending_.clear(); | |
| 160 } | |
| 161 | |
| 162 if (!hosts_pending_.empty()) | |
| 163 GetHostUsage(hosts_pending_.begin()->first, | |
| 164 hosts_pending_.begin()->second); | |
| 165 } | |
| 166 | |
| 167 void QuotaInternalsProxy::VisitHost(const std::string& host, | |
| 168 quota::StorageType type) { | |
| 169 if (hosts_visited_.insert(std::make_pair(host, type)).second) { | |
| 170 hosts_pending_.insert(std::make_pair(host, type)); | |
| 171 if (hosts_pending_.size() == 1) { | |
| 172 GetHostUsage(host, type); | |
| 173 } | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 void QuotaInternalsProxy::GetHostUsage(const std::string& host, | |
| 178 quota::StorageType type) { | |
| 179 DCHECK(quota_manager_); | |
| 180 quota_manager_->GetHostUsage( | |
| 181 host, type, | |
| 182 callback_factory_.NewCallback( | |
| 183 &QuotaInternalsProxy::DidGetHostUsage)); | |
| 184 } | |
| 185 | |
| 186 void QuotaInternalsProxy::RequestPerOriginInfo(quota::StorageType type) { | |
| 187 DCHECK(quota_manager_); | |
| 188 | |
| 189 std::set<GURL> origins; | |
| 190 quota_manager_->GetCachedOrigins(type, &origins); | |
| 191 | |
| 192 std::vector<PerOriginStorageInfo> origin_info; | |
| 193 origin_info.reserve(origins.size()); | |
| 194 | |
| 195 std::set<std::string> hosts; | |
| 196 std::vector<PerHostStorageInfo> host_info; | |
| 197 | |
| 198 for (std::set<GURL>::iterator itr(origins.begin()); | |
| 199 itr != origins.end(); ++itr) { | |
| 200 PerOriginStorageInfo info(*itr, type); | |
| 201 info.set_in_use(quota_manager_->IsOriginInUse(*itr)); | |
| 202 origin_info.push_back(info); | |
| 203 | |
| 204 std::string host(net::GetHostOrSpecFromURL(*itr)); | |
| 205 if (hosts.insert(host).second) { | |
| 206 PerHostStorageInfo info(host, type); | |
| 207 host_info.push_back(info); | |
| 208 VisitHost(host, type); | |
| 209 } | |
| 210 } | |
| 211 ReportPerOriginInfo(origin_info); | |
| 212 ReportPerHostInfo(host_info); | |
| 213 } | |
| 214 | |
| 215 } // namespace quota_internals | |
| OLD | NEW |