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

Side by Side Diff: webkit/fileapi/sandbox_quota_observer.cc

Issue 11639037: Accumulate FileSystemUsageCache updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: skip update task for invalid usage cache 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/sandbox_quota_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "webkit/fileapi/sandbox_mount_point_provider.h" 11 #include "webkit/fileapi/sandbox_mount_point_provider.h"
12 #include "webkit/quota/quota_client.h" 12 #include "webkit/quota/quota_client.h"
13 #include "webkit/quota/quota_manager.h" 13 #include "webkit/quota/quota_manager.h"
14 14
15 namespace fileapi { 15 namespace fileapi {
16 16
17 SandboxQuotaObserver::SandboxQuotaObserver( 17 SandboxQuotaObserver::SandboxQuotaObserver(
18 quota::QuotaManagerProxy* quota_manager_proxy, 18 quota::QuotaManagerProxy* quota_manager_proxy,
19 base::SequencedTaskRunner* update_notify_runner, 19 base::SequencedTaskRunner* update_notify_runner,
20 ObfuscatedFileUtil* sandbox_file_util) 20 ObfuscatedFileUtil* sandbox_file_util)
21 : quota_manager_proxy_(quota_manager_proxy), 21 : quota_manager_proxy_(quota_manager_proxy),
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),
25 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
24 26
25 SandboxQuotaObserver::~SandboxQuotaObserver() {} 27 SandboxQuotaObserver::~SandboxQuotaObserver() {}
26 28
27 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { 29 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) {
28 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 30 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
29 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); 31 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
30 FilePath usage_file_path = GetUsageCachePath(url); 32 FilePath usage_file_path = GetUsageCachePath(url);
31 if (usage_file_path.empty()) 33 if (usage_file_path.empty())
32 return; 34 return;
33 FileSystemUsageCache::IncrementDirty(usage_file_path); 35 FileSystemUsageCache::IncrementDirty(usage_file_path);
34 } 36 }
35 37
36 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, 38 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url,
37 int64 delta) { 39 int64 delta) {
38 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 40 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
39 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); 41 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
40 FilePath usage_file_path = GetUsageCachePath(url); 42
41 if (usage_file_path.empty())
42 return;
43 if (delta != 0)
44 FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta);
45 if (quota_manager_proxy_) { 43 if (quota_manager_proxy_) {
46 quota_manager_proxy_->NotifyStorageModified( 44 quota_manager_proxy_->NotifyStorageModified(
47 quota::QuotaClient::kFileSystem, 45 quota::QuotaClient::kFileSystem,
48 url.origin(), 46 url.origin(),
49 FileSystemTypeToQuotaStorageType(url.type()), 47 FileSystemTypeToQuotaStorageType(url.type()),
50 delta); 48 delta);
51 } 49 }
50
51 FilePath usage_file_path = GetUsageCachePath(url);
52 if (usage_file_path.empty())
53 return;
54
55 pending_update_notification_[usage_file_path] += delta;
56 if (!running_delayed_cache_update_) {
57 update_notify_runner_->PostTask(FROM_HERE, base::Bind(
58 &SandboxQuotaObserver::ApplyPendingUsageUpdate,
59 weak_factory_.GetWeakPtr()));
60 running_delayed_cache_update_ = true;
61 }
52 } 62 }
53 63
54 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { 64 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) {
55 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 65 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
56 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); 66 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
67
57 FilePath usage_file_path = GetUsageCachePath(url); 68 FilePath usage_file_path = GetUsageCachePath(url);
58 if (usage_file_path.empty()) 69 if (usage_file_path.empty())
59 return; 70 return;
71
72 PendingUpdateNotificationMap::iterator found =
73 pending_update_notification_.find(usage_file_path);
74 if (found != pending_update_notification_.end()) {
75 UpdateUsageCacheFile(found->first, found->second);
76 pending_update_notification_.erase(found);
77 }
78
60 FileSystemUsageCache::DecrementDirty(usage_file_path); 79 FileSystemUsageCache::DecrementDirty(usage_file_path);
61 } 80 }
62 81
63 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { 82 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) {
64 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 83 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
65 if (quota_manager_proxy_) { 84 if (quota_manager_proxy_) {
66 quota_manager_proxy_->NotifyStorageAccessed( 85 quota_manager_proxy_->NotifyStorageAccessed(
67 quota::QuotaClient::kFileSystem, 86 quota::QuotaClient::kFileSystem,
68 url.origin(), 87 url.origin(),
69 FileSystemTypeToQuotaStorageType(url.type())); 88 FileSystemTypeToQuotaStorageType(url.type()));
70 } 89 }
71 } 90 }
72 91
73 FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) { 92 FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) {
74 DCHECK(sandbox_file_util_); 93 DCHECK(sandbox_file_util_);
75 base::PlatformFileError error = base::PLATFORM_FILE_OK; 94 base::PlatformFileError error = base::PLATFORM_FILE_OK;
76 FilePath path = SandboxMountPointProvider::GetUsageCachePathForOriginAndType( 95 FilePath path = SandboxMountPointProvider::GetUsageCachePathForOriginAndType(
77 sandbox_file_util_, url.origin(), url.type(), &error); 96 sandbox_file_util_, url.origin(), url.type(), &error);
78 if (error != base::PLATFORM_FILE_OK) { 97 if (error != base::PLATFORM_FILE_OK) {
79 LOG(WARNING) << "Could not get usage cache path for: " 98 LOG(WARNING) << "Could not get usage cache path for: "
80 << url.DebugString(); 99 << url.DebugString();
81 return FilePath(); 100 return FilePath();
82 } 101 }
83 return path; 102 return path;
84 } 103 }
85 104
105 void SandboxQuotaObserver::ApplyPendingUsageUpdate() {
106 for (PendingUpdateNotificationMap::iterator itr =
107 pending_update_notification_.begin();
108 itr != pending_update_notification_.end();
109 ++itr) {
110 UpdateUsageCacheFile(itr->first, itr->second);
111 }
112 pending_update_notification_.clear();
113 running_delayed_cache_update_ = false;
114 }
115
116 void SandboxQuotaObserver::UpdateUsageCacheFile(
117 const FilePath& usage_file_path,
118 int64 delta) {
119 DCHECK(!usage_file_path.empty());
120 if (!usage_file_path.empty() && delta != 0)
121 FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta);
122 }
123
86 } // namespace fileapi 124 } // namespace fileapi
OLDNEW
« 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