| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/sandbox_quota_observer.h" | 5 #include "webkit/fileapi/sandbox_quota_observer.h" |
| 6 | 6 |
| 7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
| 8 #include "webkit/fileapi/file_system_url.h" | 8 #include "webkit/fileapi/file_system_url.h" |
| 9 #include "webkit/fileapi/file_system_usage_cache.h" | 9 #include "webkit/fileapi/file_system_usage_cache.h" |
| 10 #include "webkit/fileapi/file_system_util.h" | 10 #include "webkit/fileapi/file_system_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 update_notify_runner_(update_notify_runner), | 22 update_notify_runner_(update_notify_runner), |
| 23 sandbox_file_util_(sandbox_file_util), | 23 sandbox_file_util_(sandbox_file_util), |
| 24 running_delayed_cache_update_(false), | 24 running_delayed_cache_update_(false), |
| 25 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} | 25 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
| 26 | 26 |
| 27 SandboxQuotaObserver::~SandboxQuotaObserver() {} | 27 SandboxQuotaObserver::~SandboxQuotaObserver() {} |
| 28 | 28 |
| 29 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { | 29 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { |
| 30 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); | 30 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); |
| 31 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); | 31 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); |
| 32 FilePath usage_file_path = GetUsageCachePath(url); | 32 base::FilePath usage_file_path = GetUsageCachePath(url); |
| 33 if (usage_file_path.empty()) | 33 if (usage_file_path.empty()) |
| 34 return; | 34 return; |
| 35 FileSystemUsageCache::IncrementDirty(usage_file_path); | 35 FileSystemUsageCache::IncrementDirty(usage_file_path); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, | 38 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, |
| 39 int64 delta) { | 39 int64 delta) { |
| 40 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); | 40 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); |
| 41 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); | 41 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); |
| 42 | 42 |
| 43 if (quota_manager_proxy_) { | 43 if (quota_manager_proxy_) { |
| 44 quota_manager_proxy_->NotifyStorageModified( | 44 quota_manager_proxy_->NotifyStorageModified( |
| 45 quota::QuotaClient::kFileSystem, | 45 quota::QuotaClient::kFileSystem, |
| 46 url.origin(), | 46 url.origin(), |
| 47 FileSystemTypeToQuotaStorageType(url.type()), | 47 FileSystemTypeToQuotaStorageType(url.type()), |
| 48 delta); | 48 delta); |
| 49 } | 49 } |
| 50 | 50 |
| 51 FilePath usage_file_path = GetUsageCachePath(url); | 51 base::FilePath usage_file_path = GetUsageCachePath(url); |
| 52 if (usage_file_path.empty()) | 52 if (usage_file_path.empty()) |
| 53 return; | 53 return; |
| 54 | 54 |
| 55 pending_update_notification_[usage_file_path] += delta; | 55 pending_update_notification_[usage_file_path] += delta; |
| 56 if (!running_delayed_cache_update_) { | 56 if (!running_delayed_cache_update_) { |
| 57 update_notify_runner_->PostTask(FROM_HERE, base::Bind( | 57 update_notify_runner_->PostTask(FROM_HERE, base::Bind( |
| 58 &SandboxQuotaObserver::ApplyPendingUsageUpdate, | 58 &SandboxQuotaObserver::ApplyPendingUsageUpdate, |
| 59 weak_factory_.GetWeakPtr())); | 59 weak_factory_.GetWeakPtr())); |
| 60 running_delayed_cache_update_ = true; | 60 running_delayed_cache_update_ = true; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { | 64 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { |
| 65 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); | 65 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); |
| 66 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); | 66 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); |
| 67 | 67 |
| 68 FilePath usage_file_path = GetUsageCachePath(url); | 68 base::FilePath usage_file_path = GetUsageCachePath(url); |
| 69 if (usage_file_path.empty()) | 69 if (usage_file_path.empty()) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 PendingUpdateNotificationMap::iterator found = | 72 PendingUpdateNotificationMap::iterator found = |
| 73 pending_update_notification_.find(usage_file_path); | 73 pending_update_notification_.find(usage_file_path); |
| 74 if (found != pending_update_notification_.end()) { | 74 if (found != pending_update_notification_.end()) { |
| 75 UpdateUsageCacheFile(found->first, found->second); | 75 UpdateUsageCacheFile(found->first, found->second); |
| 76 pending_update_notification_.erase(found); | 76 pending_update_notification_.erase(found); |
| 77 } | 77 } |
| 78 | 78 |
| 79 FileSystemUsageCache::DecrementDirty(usage_file_path); | 79 FileSystemUsageCache::DecrementDirty(usage_file_path); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { | 82 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { |
| 83 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); | 83 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); |
| 84 if (quota_manager_proxy_) { | 84 if (quota_manager_proxy_) { |
| 85 quota_manager_proxy_->NotifyStorageAccessed( | 85 quota_manager_proxy_->NotifyStorageAccessed( |
| 86 quota::QuotaClient::kFileSystem, | 86 quota::QuotaClient::kFileSystem, |
| 87 url.origin(), | 87 url.origin(), |
| 88 FileSystemTypeToQuotaStorageType(url.type())); | 88 FileSystemTypeToQuotaStorageType(url.type())); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) { | 92 base::FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url)
{ |
| 93 DCHECK(sandbox_file_util_); | 93 DCHECK(sandbox_file_util_); |
| 94 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 94 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 95 FilePath path = SandboxMountPointProvider::GetUsageCachePathForOriginAndType( | 95 base::FilePath path = SandboxMountPointProvider::GetUsageCachePathForOriginAnd
Type( |
| 96 sandbox_file_util_, url.origin(), url.type(), &error); | 96 sandbox_file_util_, url.origin(), url.type(), &error); |
| 97 if (error != base::PLATFORM_FILE_OK) { | 97 if (error != base::PLATFORM_FILE_OK) { |
| 98 LOG(WARNING) << "Could not get usage cache path for: " | 98 LOG(WARNING) << "Could not get usage cache path for: " |
| 99 << url.DebugString(); | 99 << url.DebugString(); |
| 100 return FilePath(); | 100 return base::FilePath(); |
| 101 } | 101 } |
| 102 return path; | 102 return path; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void SandboxQuotaObserver::ApplyPendingUsageUpdate() { | 105 void SandboxQuotaObserver::ApplyPendingUsageUpdate() { |
| 106 for (PendingUpdateNotificationMap::iterator itr = | 106 for (PendingUpdateNotificationMap::iterator itr = |
| 107 pending_update_notification_.begin(); | 107 pending_update_notification_.begin(); |
| 108 itr != pending_update_notification_.end(); | 108 itr != pending_update_notification_.end(); |
| 109 ++itr) { | 109 ++itr) { |
| 110 UpdateUsageCacheFile(itr->first, itr->second); | 110 UpdateUsageCacheFile(itr->first, itr->second); |
| 111 } | 111 } |
| 112 pending_update_notification_.clear(); | 112 pending_update_notification_.clear(); |
| 113 running_delayed_cache_update_ = false; | 113 running_delayed_cache_update_ = false; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void SandboxQuotaObserver::UpdateUsageCacheFile( | 116 void SandboxQuotaObserver::UpdateUsageCacheFile( |
| 117 const FilePath& usage_file_path, | 117 const base::FilePath& usage_file_path, |
| 118 int64 delta) { | 118 int64 delta) { |
| 119 DCHECK(!usage_file_path.empty()); | 119 DCHECK(!usage_file_path.empty()); |
| 120 if (!usage_file_path.empty() && delta != 0) | 120 if (!usage_file_path.empty() && delta != 0) |
| 121 FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta); | 121 FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta); |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace fileapi | 124 } // namespace fileapi |
| OLD | NEW |