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/browser/fileapi/sandbox_quota_observer.h" | 5 #include "webkit/browser/fileapi/sandbox_quota_observer.h" |
6 | 6 |
7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
8 #include "webkit/browser/fileapi/file_system_url.h" | 8 #include "webkit/browser/fileapi/file_system_url.h" |
9 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 9 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
10 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 10 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
11 #include "webkit/browser/fileapi/timed_task_helper.h" | 11 #include "webkit/browser/fileapi/timed_task_helper.h" |
12 #include "webkit/browser/quota/quota_client.h" | 12 #include "webkit/browser/quota/quota_client.h" |
13 #include "webkit/browser/quota/quota_manager_proxy.h" | 13 #include "webkit/browser/quota/quota_manager_proxy.h" |
14 #include "webkit/common/fileapi/file_system_util.h" | 14 #include "webkit/common/fileapi/file_system_util.h" |
15 | 15 |
16 namespace fileapi { | 16 namespace storage { |
17 | 17 |
18 SandboxQuotaObserver::SandboxQuotaObserver( | 18 SandboxQuotaObserver::SandboxQuotaObserver( |
19 quota::QuotaManagerProxy* quota_manager_proxy, | 19 storage::QuotaManagerProxy* quota_manager_proxy, |
20 base::SequencedTaskRunner* update_notify_runner, | 20 base::SequencedTaskRunner* update_notify_runner, |
21 ObfuscatedFileUtil* sandbox_file_util, | 21 ObfuscatedFileUtil* sandbox_file_util, |
22 FileSystemUsageCache* file_system_usage_cache) | 22 FileSystemUsageCache* file_system_usage_cache) |
23 : quota_manager_proxy_(quota_manager_proxy), | 23 : quota_manager_proxy_(quota_manager_proxy), |
24 update_notify_runner_(update_notify_runner), | 24 update_notify_runner_(update_notify_runner), |
25 sandbox_file_util_(sandbox_file_util), | 25 sandbox_file_util_(sandbox_file_util), |
26 file_system_usage_cache_(file_system_usage_cache) {} | 26 file_system_usage_cache_(file_system_usage_cache) { |
| 27 } |
27 | 28 |
28 SandboxQuotaObserver::~SandboxQuotaObserver() {} | 29 SandboxQuotaObserver::~SandboxQuotaObserver() {} |
29 | 30 |
30 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { | 31 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) { |
31 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); | 32 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); |
32 base::FilePath usage_file_path = GetUsageCachePath(url); | 33 base::FilePath usage_file_path = GetUsageCachePath(url); |
33 if (usage_file_path.empty()) | 34 if (usage_file_path.empty()) |
34 return; | 35 return; |
35 file_system_usage_cache_->IncrementDirty(usage_file_path); | 36 file_system_usage_cache_->IncrementDirty(usage_file_path); |
36 } | 37 } |
37 | 38 |
38 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, | 39 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, |
39 int64 delta) { | 40 int64 delta) { |
40 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); | 41 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); |
41 | 42 |
42 if (quota_manager_proxy_.get()) { | 43 if (quota_manager_proxy_.get()) { |
43 quota_manager_proxy_->NotifyStorageModified( | 44 quota_manager_proxy_->NotifyStorageModified( |
44 quota::QuotaClient::kFileSystem, | 45 storage::QuotaClient::kFileSystem, |
45 url.origin(), | 46 url.origin(), |
46 FileSystemTypeToQuotaStorageType(url.type()), | 47 FileSystemTypeToQuotaStorageType(url.type()), |
47 delta); | 48 delta); |
48 } | 49 } |
49 | 50 |
50 base::FilePath usage_file_path = GetUsageCachePath(url); | 51 base::FilePath usage_file_path = GetUsageCachePath(url); |
51 if (usage_file_path.empty()) | 52 if (usage_file_path.empty()) |
52 return; | 53 return; |
53 | 54 |
54 pending_update_notification_[usage_file_path] += delta; | 55 pending_update_notification_[usage_file_path] += delta; |
(...skipping 21 matching lines...) Expand all Loading... |
76 UpdateUsageCacheFile(found->first, found->second); | 77 UpdateUsageCacheFile(found->first, found->second); |
77 pending_update_notification_.erase(found); | 78 pending_update_notification_.erase(found); |
78 } | 79 } |
79 | 80 |
80 file_system_usage_cache_->DecrementDirty(usage_file_path); | 81 file_system_usage_cache_->DecrementDirty(usage_file_path); |
81 } | 82 } |
82 | 83 |
83 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { | 84 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { |
84 if (quota_manager_proxy_.get()) { | 85 if (quota_manager_proxy_.get()) { |
85 quota_manager_proxy_->NotifyStorageAccessed( | 86 quota_manager_proxy_->NotifyStorageAccessed( |
86 quota::QuotaClient::kFileSystem, | 87 storage::QuotaClient::kFileSystem, |
87 url.origin(), | 88 url.origin(), |
88 FileSystemTypeToQuotaStorageType(url.type())); | 89 FileSystemTypeToQuotaStorageType(url.type())); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 void SandboxQuotaObserver::SetUsageCacheEnabled( | 93 void SandboxQuotaObserver::SetUsageCacheEnabled( |
93 const GURL& origin, | 94 const GURL& origin, |
94 FileSystemType type, | 95 FileSystemType type, |
95 bool enabled) { | 96 bool enabled) { |
96 if (quota_manager_proxy_.get()) { | 97 if (quota_manager_proxy_.get()) { |
97 quota_manager_proxy_->SetUsageCacheEnabled( | 98 quota_manager_proxy_->SetUsageCacheEnabled( |
98 quota::QuotaClient::kFileSystem, | 99 storage::QuotaClient::kFileSystem, |
99 origin, | 100 origin, |
100 FileSystemTypeToQuotaStorageType(type), | 101 FileSystemTypeToQuotaStorageType(type), |
101 enabled); | 102 enabled); |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 base::FilePath SandboxQuotaObserver::GetUsageCachePath( | 106 base::FilePath SandboxQuotaObserver::GetUsageCachePath( |
106 const FileSystemURL& url) { | 107 const FileSystemURL& url) { |
107 DCHECK(sandbox_file_util_); | 108 DCHECK(sandbox_file_util_); |
108 base::File::Error error = base::File::FILE_OK; | 109 base::File::Error error = base::File::FILE_OK; |
(...skipping 20 matching lines...) Expand all Loading... |
129 } | 130 } |
130 | 131 |
131 void SandboxQuotaObserver::UpdateUsageCacheFile( | 132 void SandboxQuotaObserver::UpdateUsageCacheFile( |
132 const base::FilePath& usage_file_path, | 133 const base::FilePath& usage_file_path, |
133 int64 delta) { | 134 int64 delta) { |
134 DCHECK(!usage_file_path.empty()); | 135 DCHECK(!usage_file_path.empty()); |
135 if (!usage_file_path.empty() && delta != 0) | 136 if (!usage_file_path.empty() && delta != 0) |
136 file_system_usage_cache_->AtomicUpdateUsageByDelta(usage_file_path, delta); | 137 file_system_usage_cache_->AtomicUpdateUsageByDelta(usage_file_path, delta); |
137 } | 138 } |
138 | 139 |
139 } // namespace fileapi | 140 } // namespace storage |
OLD | NEW |