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

Unified Diff: webkit/quota/usage_tracker.cc

Issue 7618025: Send notifications on the IO thread when changes are made to the special storage policy. Listen f... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/quota/usage_tracker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/quota/usage_tracker.cc
===================================================================
--- webkit/quota/usage_tracker.cc (revision 96595)
+++ webkit/quota/usage_tracker.cc (working copy)
@@ -12,7 +12,6 @@
#include "base/message_loop_proxy.h"
#include "base/stl_util.h"
#include "net/base/net_util.h"
-#include "webkit/quota/special_storage_policy.h"
namespace quota {
@@ -334,18 +333,23 @@
global_usage_(0),
global_unlimited_usage_(0),
global_usage_retrieved_(false),
+ global_unlimited_usage_is_valid_(true),
global_usage_task_(NULL),
special_storage_policy_(special_storage_policy) {
DCHECK(tracker_);
DCHECK(client_);
+ if (special_storage_policy_)
+ special_storage_policy_->AddObserver(this);
}
ClientUsageTracker::~ClientUsageTracker() {
+ if (special_storage_policy_)
+ special_storage_policy_->RemoveObserver(this);
}
void ClientUsageTracker::GetGlobalUsage(GlobalUsageCallback* callback) {
if (global_usage_retrieved_) {
- callback->Run(type_, global_usage_, global_unlimited_usage_);
+ callback->Run(type_, global_usage_, GetCachedGlobalUnlimitedUsage());
delete callback;
return;
}
@@ -377,7 +381,7 @@
if (cached_hosts_.find(host) != cached_hosts_.end()) {
cached_usage_[host][origin] += delta;
global_usage_ += delta;
- if (IsStorageUnlimited(origin))
+ if (global_unlimited_usage_is_valid_ && IsStorageUnlimited(origin))
global_unlimited_usage_ += delta;
DCHECK_GE(cached_usage_[host][origin], 0);
DCHECK_GE(global_usage_, 0);
@@ -411,7 +415,7 @@
int64 delta = usage - old_usage;
if (delta) {
global_usage_ += delta;
- if (IsStorageUnlimited(origin))
+ if (global_unlimited_usage_is_valid_ && IsStorageUnlimited(origin))
global_unlimited_usage_ += delta;
}
DCHECK_GE(iter->second, 0);
@@ -429,7 +433,8 @@
global_usage_retrieved_ = true;
DCHECK(global_usage_callback_.HasCallbacks());
- global_usage_callback_.Run(type_, global_usage_, global_unlimited_usage_);
+ global_usage_callback_.Run(type_, global_usage_,
+ GetCachedGlobalUnlimitedUsage());
for (HostUsageCallbackMap::iterator iter = host_usage_callbacks_.Begin();
iter != host_usage_callbacks_.End(); ++iter) {
@@ -458,6 +463,27 @@
return usage;
}
+int64 ClientUsageTracker::GetCachedGlobalUnlimitedUsage() {
+ if (!global_unlimited_usage_is_valid_) {
+ global_unlimited_usage_ = 0;
+ for (HostUsageMap::const_iterator host_iter = cached_usage_.begin();
+ host_iter != cached_usage_.end(); host_iter++) {
+ const UsageMap& origin_map = host_iter->second;
+ for (UsageMap::const_iterator origin_iter = origin_map.begin();
+ origin_iter != origin_map.end(); origin_iter++) {
+ if (IsStorageUnlimited(origin_iter->first))
+ global_unlimited_usage_ += origin_iter->second;
+ }
+ }
+ global_unlimited_usage_is_valid_ = true;
+ }
+ return global_unlimited_usage_;
+}
+
+void ClientUsageTracker::OnSpecialStoragePolicyChanged() {
+ global_unlimited_usage_is_valid_ = false;
kinuko 2011/08/15 11:26:45 just to make it clear that this is called on the s
michaeln 2011/08/15 19:21:52 Done.
+}
+
void ClientUsageTracker::NoopHostUsageCallback(
const std::string& host, StorageType type, int64 usage) {
}
« no previous file with comments | « webkit/quota/usage_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698