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

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

Issue 15442002: Move FileAPI sandboxed filesystem related code from webkit/fileapi to webkit/browser/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/sandbox_quota_observer.h"
6
7 #include "base/sequenced_task_runner.h"
8 #include "webkit/browser/fileapi/file_system_usage_cache.h"
9 #include "webkit/fileapi/file_system_url.h"
10 #include "webkit/fileapi/file_system_util.h"
11 #include "webkit/fileapi/sandbox_mount_point_provider.h"
12 #include "webkit/quota/quota_client.h"
13 #include "webkit/quota/quota_manager.h"
14
15 namespace fileapi {
16
17 SandboxQuotaObserver::SandboxQuotaObserver(
18 quota::QuotaManagerProxy* quota_manager_proxy,
19 base::SequencedTaskRunner* update_notify_runner,
20 ObfuscatedFileUtil* sandbox_file_util,
21 FileSystemUsageCache* file_system_usage_cache)
22 : quota_manager_proxy_(quota_manager_proxy),
23 update_notify_runner_(update_notify_runner),
24 sandbox_file_util_(sandbox_file_util),
25 file_system_usage_cache_(file_system_usage_cache),
26 running_delayed_cache_update_(false),
27 weak_factory_(this) {}
28
29 SandboxQuotaObserver::~SandboxQuotaObserver() {}
30
31 void SandboxQuotaObserver::OnStartUpdate(const FileSystemURL& url) {
32 DCHECK(SandboxMountPointProvider::IsSandboxType(url.type()));
33 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
34 base::FilePath usage_file_path = GetUsageCachePath(url);
35 if (usage_file_path.empty())
36 return;
37 file_system_usage_cache_->IncrementDirty(usage_file_path);
38 }
39
40 void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url,
41 int64 delta) {
42 DCHECK(SandboxMountPointProvider::IsSandboxType(url.type()));
43 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
44
45 if (quota_manager_proxy_) {
46 quota_manager_proxy_->NotifyStorageModified(
47 quota::QuotaClient::kFileSystem,
48 url.origin(),
49 FileSystemTypeToQuotaStorageType(url.type()),
50 delta);
51 }
52
53 base::FilePath usage_file_path = GetUsageCachePath(url);
54 if (usage_file_path.empty())
55 return;
56
57 pending_update_notification_[usage_file_path] += delta;
58 if (!running_delayed_cache_update_) {
59 update_notify_runner_->PostTask(FROM_HERE, base::Bind(
60 &SandboxQuotaObserver::ApplyPendingUsageUpdate,
61 weak_factory_.GetWeakPtr()));
62 running_delayed_cache_update_ = true;
63 }
64 }
65
66 void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) {
67 DCHECK(SandboxMountPointProvider::IsSandboxType(url.type()));
68 DCHECK(update_notify_runner_->RunsTasksOnCurrentThread());
69
70 base::FilePath usage_file_path = GetUsageCachePath(url);
71 if (usage_file_path.empty())
72 return;
73
74 PendingUpdateNotificationMap::iterator found =
75 pending_update_notification_.find(usage_file_path);
76 if (found != pending_update_notification_.end()) {
77 UpdateUsageCacheFile(found->first, found->second);
78 pending_update_notification_.erase(found);
79 }
80
81 file_system_usage_cache_->DecrementDirty(usage_file_path);
82 }
83
84 void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) {
85 DCHECK(SandboxMountPointProvider::IsSandboxType(url.type()));
86 if (quota_manager_proxy_) {
87 quota_manager_proxy_->NotifyStorageAccessed(
88 quota::QuotaClient::kFileSystem,
89 url.origin(),
90 FileSystemTypeToQuotaStorageType(url.type()));
91 }
92 }
93
94 void SandboxQuotaObserver::SetUsageCacheEnabled(
95 const GURL& origin,
96 FileSystemType type,
97 bool enabled) {
98 if (quota_manager_proxy_) {
99 quota_manager_proxy_->SetUsageCacheEnabled(
100 quota::QuotaClient::kFileSystem,
101 origin, FileSystemTypeToQuotaStorageType(type),
102 enabled);
103 }
104 }
105
106 base::FilePath SandboxQuotaObserver::GetUsageCachePath(
107 const FileSystemURL& url) {
108 DCHECK(sandbox_file_util_);
109 base::PlatformFileError error = base::PLATFORM_FILE_OK;
110 base::FilePath path =
111 SandboxMountPointProvider::GetUsageCachePathForOriginAndType(
112 sandbox_file_util_, url.origin(), url.type(), &error);
113 if (error != base::PLATFORM_FILE_OK) {
114 LOG(WARNING) << "Could not get usage cache path for: "
115 << url.DebugString();
116 return base::FilePath();
117 }
118 return path;
119 }
120
121 void SandboxQuotaObserver::ApplyPendingUsageUpdate() {
122 for (PendingUpdateNotificationMap::iterator itr =
123 pending_update_notification_.begin();
124 itr != pending_update_notification_.end();
125 ++itr) {
126 UpdateUsageCacheFile(itr->first, itr->second);
127 }
128 pending_update_notification_.clear();
129 running_delayed_cache_update_ = false;
130 }
131
132 void SandboxQuotaObserver::UpdateUsageCacheFile(
133 const base::FilePath& usage_file_path,
134 int64 delta) {
135 DCHECK(!usage_file_path.empty());
136 if (!usage_file_path.empty() && delta != 0)
137 file_system_usage_cache_->AtomicUpdateUsageByDelta(usage_file_path, delta);
138 }
139
140 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/sandbox_quota_observer.h ('k') | webkit/fileapi/syncable/canned_syncable_file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698