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

Unified Diff: webkit/fileapi/sandbox_quota_observer.cc

Issue 11639037: Accumulate FileSystemUsageCache updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: drop Unretained Created 7 years, 11 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/fileapi/sandbox_quota_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/sandbox_quota_observer.cc
diff --git a/webkit/fileapi/sandbox_quota_observer.cc b/webkit/fileapi/sandbox_quota_observer.cc
index 29e11022a79b6433011eb32bd1afc275695445a1..27f56ca6f2d39203853a1d721ba1ba5117ab94f0 100644
--- a/webkit/fileapi/sandbox_quota_observer.cc
+++ b/webkit/fileapi/sandbox_quota_observer.cc
@@ -20,7 +20,9 @@ SandboxQuotaObserver::SandboxQuotaObserver(
ObfuscatedFileUtil* sandbox_file_util)
: quota_manager_proxy_(quota_manager_proxy),
update_notify_runner_(update_notify_runner),
- sandbox_file_util_(sandbox_file_util) {}
+ sandbox_file_util_(sandbox_file_util),
+ running_delayed_cache_update_(false),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
SandboxQuotaObserver::~SandboxQuotaObserver() {}
@@ -37,11 +39,16 @@ void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url,
int64 delta) {
DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
+
FilePath usage_file_path = GetUsageCachePath(url);
kinuko 2013/01/07 06:38:25 should we return if usage_file_path.empty() here t
tzik 2013/01/07 16:00:37 Done.
- if (usage_file_path.empty())
- return;
- if (delta != 0)
- FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta);
+ pending_update_notification_[usage_file_path] += delta;
+ if (!running_delayed_cache_update_) {
+ update_notify_runner_->PostTask(FROM_HERE, base::Bind(
+ &SandboxQuotaObserver::ApplyPendingUsageUpdate,
+ weak_factory_.GetWeakPtr()));
+ running_delayed_cache_update_ = true;
+ }
+
if (quota_manager_proxy_) {
quota_manager_proxy_->NotifyStorageModified(
quota::QuotaClient::kFileSystem,
@@ -54,9 +61,18 @@ void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url,
void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) {
DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
+
FilePath usage_file_path = GetUsageCachePath(url);
if (usage_file_path.empty())
return;
+
+ PendingUpdateNotificationMap::iterator found =
+ pending_update_notification_.find(usage_file_path);
+ if (found != pending_update_notification_.end()) {
+ UpdateUsageCacheFile(found->first, found->second);
+ pending_update_notification_.erase(found);
+ }
+
FileSystemUsageCache::DecrementDirty(usage_file_path);
}
@@ -83,4 +99,22 @@ FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) {
return path;
}
+void SandboxQuotaObserver::ApplyPendingUsageUpdate() {
+ for (PendingUpdateNotificationMap::iterator itr =
+ pending_update_notification_.begin();
+ itr != pending_update_notification_.end();
+ ++itr) {
+ UpdateUsageCacheFile(itr->first, itr->second);
+ }
+ pending_update_notification_.clear();
+ running_delayed_cache_update_ = false;
+}
+
+void SandboxQuotaObserver::UpdateUsageCacheFile(
+ const FilePath& usage_file_path,
+ int64 delta) {
+ if (!usage_file_path.empty() && delta != 0)
kinuko 2013/01/07 06:38:25 DCHECK(!usage_file_path.empty()) ?
tzik 2013/01/07 16:00:37 Done.
+ FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta);
+}
+
} // namespace fileapi
« no previous file with comments | « webkit/fileapi/sandbox_quota_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698