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

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: testfix Created 8 years 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) {}
24 25
25 SandboxQuotaObserver::~SandboxQuotaObserver() {} 26 SandboxQuotaObserver::~SandboxQuotaObserver() {}
26 27
27 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { 28 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) {
28 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 29 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
29 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); 30 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
30 FilePath usage_file_path = GetUsageCachePath(url); 31 FilePath usage_file_path = GetUsageCachePath(url);
31 if (usage_file_path.empty()) 32 if (usage_file_path.empty())
32 return; 33 return;
33 FileSystemUsageCache::IncrementDirty(usage_file_path); 34 FileSystemUsageCache::IncrementDirty(usage_file_path);
34 } 35 }
35 36
36 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, 37 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url,
37 int64 delta) { 38 int64 delta) {
38 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 39 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
39 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); 40 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
41
40 FilePath usage_file_path = GetUsageCachePath(url); 42 FilePath usage_file_path = GetUsageCachePath(url);
41 if (usage_file_path.empty()) 43 pending_update_notification_[usage_file_path] += delta;
42 return; 44 if (!running_delayed_cache_update_) {
43 if (delta != 0) 45 update_notify_runner_->PostTask(FROM_HERE, base::Bind(
44 FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta); 46 &SandboxQuotaObserver::ApplyPendingUsageUpdate,
47 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
48 running_delayed_cache_update_ = true;
49 }
50
45 if (quota_manager_proxy_) { 51 if (quota_manager_proxy_) {
46 quota_manager_proxy_->NotifyStorageModified( 52 quota_manager_proxy_->NotifyStorageModified(
47 quota::QuotaClient::kFileSystem, 53 quota::QuotaClient::kFileSystem,
48 url.origin(), 54 url.origin(),
49 FileSystemTypeToQuotaStorageType(url.type()), 55 FileSystemTypeToQuotaStorageType(url.type()),
50 delta); 56 delta);
51 } 57 }
52 } 58 }
53 59
54 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { 60 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) {
55 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 61 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
56 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); 62 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
63
57 FilePath usage_file_path = GetUsageCachePath(url); 64 FilePath usage_file_path = GetUsageCachePath(url);
65 PendingUpdateNotificationMap::iterator found =
66 pending_update_notification_.find(usage_file_path);
67 if (found != pending_update_notification_.end()) {
68 UpdateUsageCacheFile(found->first, found->second);
69 pending_update_notification_.erase(found);
70 }
71
58 if (usage_file_path.empty()) 72 if (usage_file_path.empty())
59 return; 73 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.
60 FileSystemUsageCache::DecrementDirty(usage_file_path); 74 FileSystemUsageCache::DecrementDirty(usage_file_path);
61 } 75 }
62 76
63 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { 77 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) {
64 DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); 78 DCHECK(SandboxMountPointProvider::CanHandleType(url.type()));
65 if (quota_manager_proxy_) { 79 if (quota_manager_proxy_) {
66 quota_manager_proxy_->NotifyStorageAccessed( 80 quota_manager_proxy_->NotifyStorageAccessed(
67 quota::QuotaClient::kFileSystem, 81 quota::QuotaClient::kFileSystem,
68 url.origin(), 82 url.origin(),
69 FileSystemTypeToQuotaStorageType(url.type())); 83 FileSystemTypeToQuotaStorageType(url.type()));
70 } 84 }
71 } 85 }
72 86
73 FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) { 87 FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) {
74 DCHECK(sandbox_file_util_); 88 DCHECK(sandbox_file_util_);
75 base::PlatformFileError error = base::PLATFORM_FILE_OK; 89 base::PlatformFileError error = base::PLATFORM_FILE_OK;
76 FilePath path = SandboxMountPointProvider::GetUsageCachePathForOriginAndType( 90 FilePath path = SandboxMountPointProvider::GetUsageCachePathForOriginAndType(
77 sandbox_file_util_, url.origin(), url.type(), &error); 91 sandbox_file_util_, url.origin(), url.type(), &error);
78 if (error != base::PLATFORM_FILE_OK) { 92 if (error != base::PLATFORM_FILE_OK) {
79 LOG(WARNING) << "Could not get usage cache path for: " 93 LOG(WARNING) << "Could not get usage cache path for: "
80 << url.DebugString(); 94 << url.DebugString();
81 return FilePath(); 95 return FilePath();
82 } 96 }
83 return path; 97 return path;
84 } 98 }
85 99
100 void SandboxQuotaObserver::ApplyPendingUsageUpdate() {
101 for (PendingUpdateNotificationMap::iterator itr =
102 pending_update_notification_.begin();
103 itr != pending_update_notification_.end();
104 ++itr) {
105 UpdateUsageCacheFile(itr->first, itr->second);
106 }
107 pending_update_notification_.clear();
108 running_delayed_cache_update_ = false;
109 }
110
111 void SandboxQuotaObserver::UpdateUsageCacheFile(
112 const FilePath& usage_file_path,
113 int64 delta) {
114 if (!usage_file_path.empty() && delta != 0)
115 FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta);
116 }
117
86 } // namespace fileapi 118 } // 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