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

Side by Side Diff: trunk/src/webkit/browser/fileapi/quota/quota_backend_impl.cc

Issue 64883003: Revert 233815 "Quota: Implement QuotaBackendImpl" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month 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 2013 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/browser/fileapi/quota/quota_backend_impl.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/logging.h"
12 #include "base/sequenced_task_runner.h"
13 #include "webkit/browser/fileapi/file_system_usage_cache.h"
14 #include "webkit/browser/quota/quota_client.h"
15 #include "webkit/browser/quota/quota_manager.h"
16 #include "webkit/common/fileapi/file_system_util.h"
17
18 namespace fileapi {
19
20 QuotaBackendImpl::QuotaBackendImpl(
21 base::SequencedTaskRunner* file_task_runner,
22 ObfuscatedFileUtil* obfuscated_file_util,
23 FileSystemUsageCache* file_system_usage_cache,
24 quota::QuotaManagerProxy* quota_manager_proxy)
25 : file_task_runner_(file_task_runner),
26 obfuscated_file_util_(obfuscated_file_util),
27 file_system_usage_cache_(file_system_usage_cache),
28 quota_manager_proxy_(quota_manager_proxy),
29 weak_ptr_factory_(this) {
30 }
31
32 QuotaBackendImpl::~QuotaBackendImpl() {
33 }
34
35 void QuotaBackendImpl::ReserveQuota(const GURL& origin,
36 FileSystemType type,
37 int64 delta,
38 const ReserveQuotaCallback& callback) {
39 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
40 if (!delta) {
41 callback.Run(base::PLATFORM_FILE_OK);
42 return;
43 }
44 DCHECK(quota_manager_proxy_);
45 quota_manager_proxy_->GetUsageAndQuota(
46 file_task_runner_, origin, FileSystemTypeToQuotaStorageType(type),
47 base::Bind(&QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota,
48 weak_ptr_factory_.GetWeakPtr(),
49 QuotaReservationInfo(origin, type, delta), callback));
50 }
51
52 void QuotaBackendImpl::ReleaseReservedQuota(const GURL& origin,
53 FileSystemType type,
54 int64 size) {
55 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
56 DCHECK_LE(0, size);
57 if (!size)
58 return;
59 ReserveQuotaInternal(QuotaReservationInfo(origin, type, -size));
60 }
61
62 void QuotaBackendImpl::CommitQuotaUsage(const GURL& origin,
63 FileSystemType type,
64 int64 delta) {
65 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
66 if (!delta)
67 return;
68 ReserveQuotaInternal(QuotaReservationInfo(origin, type, delta));
69 base::FilePath path;
70 if (GetUsageCachePath(origin, type, &path) != base::PLATFORM_FILE_OK)
71 return;
72 bool result = file_system_usage_cache_->AtomicUpdateUsageByDelta(path, delta);
73 DCHECK(result);
74 }
75
76 void QuotaBackendImpl::IncrementDirtyCount(const GURL& origin,
77 FileSystemType type) {
78 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
79 base::FilePath path;
80 if (GetUsageCachePath(origin, type, &path) != base::PLATFORM_FILE_OK)
81 return;
82 DCHECK(file_system_usage_cache_);
83 file_system_usage_cache_->IncrementDirty(path);
84 }
85
86 void QuotaBackendImpl::DecrementDirtyCount(const GURL& origin,
87 FileSystemType type) {
88 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
89 base::FilePath path;
90 if (GetUsageCachePath(origin, type, &path) != base::PLATFORM_FILE_OK)
91 return;
92 DCHECK(file_system_usage_cache_);
93 file_system_usage_cache_->DecrementDirty(path);
94 }
95
96 void QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota(
97 const QuotaReservationInfo& info,
98 const ReserveQuotaCallback& callback,
99 quota::QuotaStatusCode status, int64 usage, int64 quota) {
100 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
101 if (status != quota::kQuotaStatusOk) {
102 callback.Run(base::PLATFORM_FILE_ERROR_FAILED);
103 return;
104 }
105
106 if (quota < usage + info.delta) {
107 callback.Run(base::PLATFORM_FILE_ERROR_NO_SPACE);
108 return;
109 }
110
111 ReserveQuotaInternal(info);
112 if (callback.Run(base::PLATFORM_FILE_OK))
113 return;
114 // The requester could not accept the reserved quota. Revert it.
115 ReserveQuotaInternal(
116 QuotaReservationInfo(info.origin, info.type, -info.delta));
117 }
118
119 void QuotaBackendImpl::ReserveQuotaInternal(const QuotaReservationInfo& info) {
120 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
121 DCHECK(quota_manager_proxy_);
122 quota_manager_proxy_->NotifyStorageModified(
123 quota::QuotaClient::kFileSystem, info.origin,
124 FileSystemTypeToQuotaStorageType(info.type), info.delta);
125 }
126
127 base::PlatformFileError QuotaBackendImpl::GetUsageCachePath(
128 const GURL& origin,
129 FileSystemType type,
130 base::FilePath* usage_file_path) {
131 DCHECK(file_task_runner_->RunsTasksOnCurrentThread());
132 DCHECK(usage_file_path);
133 base::PlatformFileError error = base::PLATFORM_FILE_OK;
134 *usage_file_path =
135 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType(
136 obfuscated_file_util_, origin, type, &error);
137 return error;
138 }
139
140 QuotaBackendImpl::QuotaReservationInfo::QuotaReservationInfo(
141 const GURL& origin, FileSystemType type, int64 delta)
142 : origin(origin), type(type), delta(delta) {
143 }
144
145 QuotaBackendImpl::QuotaReservationInfo::~QuotaReservationInfo() {
146 }
147
148 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698