Chromium Code Reviews| 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..fbbd3537d6ae5588ac1cba31e452c22ddd3acb18 100644 |
| --- a/webkit/fileapi/sandbox_quota_observer.cc |
| +++ b/webkit/fileapi/sandbox_quota_observer.cc |
| @@ -20,7 +20,8 @@ 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) {} |
| SandboxQuotaObserver::~SandboxQuotaObserver() {} |
| @@ -37,11 +38,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); |
| - 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, |
| + base::Unretained(this))); |
|
kinuko
2013/01/01 04:26:23
Is this PostTask with Unretained safe?
tzik
2013/01/07 06:06:12
No, it's not safe without DeleteSoon.
Changed to W
|
| + running_delayed_cache_update_ = true; |
| + } |
| + |
| if (quota_manager_proxy_) { |
| quota_manager_proxy_->NotifyStorageModified( |
| quota::QuotaClient::kFileSystem, |
| @@ -54,7 +60,15 @@ 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); |
| + 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); |
| + } |
| + |
| if (usage_file_path.empty()) |
| return; |
|
kinuko
2013/01/01 04:26:23
Should return if path is empty before line 65?
tzik
2013/01/07 06:06:12
Done.
|
| FileSystemUsageCache::DecrementDirty(usage_file_path); |
| @@ -83,4 +97,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) |
| + FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta); |
| +} |
| + |
| } // namespace fileapi |