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

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

Issue 7470037: [Refactor] to rename and re-layer the file_util stack layers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed for ChromeOS again. Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/quota_file_util.h" 5 #include "webkit/fileapi/quota_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "webkit/fileapi/file_system_context.h" 9 #include "webkit/fileapi/file_system_context.h"
10 #include "webkit/fileapi/file_system_operation_context.h" 10 #include "webkit/fileapi/file_system_operation_context.h"
11 #include "webkit/fileapi/file_system_path_manager.h" 11 #include "webkit/fileapi/file_system_path_manager.h"
12 #include "webkit/fileapi/file_system_quota_util.h" 12 #include "webkit/fileapi/file_system_quota_util.h"
13 #include "webkit/fileapi/native_file_util.h"
13 #include "webkit/quota/quota_manager.h" 14 #include "webkit/quota/quota_manager.h"
14 15
15 using quota::QuotaManagerProxy; 16 using quota::QuotaManagerProxy;
16 17
17 namespace fileapi { 18 namespace fileapi {
18 19
19 const int64 QuotaFileUtil::kNoLimit = kint64max; 20 const int64 QuotaFileUtil::kNoLimit = kint64max;
20 21
21 // See the comment in the header file as for these constants. 22 // See the comment in the header file as for these constants.
22 const int64 QuotaFileUtil::kFilePathCostPerChar = 2; 23 const int64 QuotaFileUtil::kFilePathCostPerChar = 2;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 FileSystemOperationContext* operation_context_; 64 FileSystemOperationContext* operation_context_;
64 FileSystemQuotaUtil* quota_util_; 65 FileSystemQuotaUtil* quota_util_;
65 QuotaManagerProxy* quota_manager_proxy_; 66 QuotaManagerProxy* quota_manager_proxy_;
66 const GURL& origin_url_; 67 const GURL& origin_url_;
67 FileSystemType type_; 68 FileSystemType type_;
68 DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper); 69 DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper);
69 }; 70 };
70 71
71 } // namespace (anonymous) 72 } // namespace (anonymous)
72 73
73 QuotaFileUtil::QuotaFileUtil(FileSystemFileUtil* underlying_file_util) 74 QuotaFileUtil::QuotaFileUtil(FileApiFileUtil* underlying_file_util)
74 : underlying_file_util_(underlying_file_util) { 75 : FileApiFileUtil(underlying_file_util) {
75 } 76 }
76 77
77 QuotaFileUtil::~QuotaFileUtil() { 78 QuotaFileUtil::~QuotaFileUtil() {
78 } 79 }
79 80
80 // static 81 // static
81 QuotaFileUtil* QuotaFileUtil::CreateDefault() { 82 QuotaFileUtil* QuotaFileUtil::CreateDefault() {
82 return new QuotaFileUtil(new FileSystemFileUtil()); 83 return new QuotaFileUtil(new NativeFileUtil());
83 } 84 }
84 85
85 int64 QuotaFileUtil::ComputeFilePathCost(const FilePath& file_path) const { 86 int64 QuotaFileUtil::ComputeFilePathCost(const FilePath& file_path) const {
86 return kFilePathCostPerFile + 87 return kFilePathCostPerFile +
87 file_path.BaseName().value().length() * kFilePathCostPerChar; 88 file_path.BaseName().value().length() * kFilePathCostPerChar;
88 } 89 }
89 90
90 PlatformFileError QuotaFileUtil::CreateOrOpen( 91 PlatformFileError QuotaFileUtil::CreateOrOpen(
91 FileSystemOperationContext* fs_context, 92 FileSystemOperationContext* fs_context,
92 const FilePath& file_path, int file_flags, 93 const FilePath& file_path, int file_flags,
(...skipping 10 matching lines...) Expand all
103 if (growth > 0) { 104 if (growth > 0) {
104 helper.reset(new ScopedOriginUpdateHelper( 105 helper.reset(new ScopedOriginUpdateHelper(
105 fs_context, 106 fs_context,
106 fs_context->src_origin_url(), 107 fs_context->src_origin_url(),
107 fs_context->src_type())); 108 fs_context->src_type()));
108 109
109 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth) 110 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
110 return base::PLATFORM_FILE_ERROR_NO_SPACE; 111 return base::PLATFORM_FILE_ERROR_NO_SPACE;
111 } 112 }
112 113
113 base::PlatformFileError error = underlying_file_util_->CreateOrOpen( 114 base::PlatformFileError error = underlying_file_util()->CreateOrOpen(
114 fs_context, file_path, file_flags, file_handle, created); 115 fs_context, file_path, file_flags, file_handle, created);
115 116
116 if (growth > 0) { 117 if (growth > 0) {
117 if (error == base::PLATFORM_FILE_OK) 118 if (error == base::PLATFORM_FILE_OK)
118 helper->NotifyUpdate(growth); 119 helper->NotifyUpdate(growth);
119 } 120 }
120 121
121 return error; 122 return error;
122 } 123 }
123 124
(...skipping 13 matching lines...) Expand all
137 if (growth > 0) { 138 if (growth > 0) {
138 helper.reset(new ScopedOriginUpdateHelper( 139 helper.reset(new ScopedOriginUpdateHelper(
139 fs_context, 140 fs_context,
140 fs_context->src_origin_url(), 141 fs_context->src_origin_url(),
141 fs_context->src_type())); 142 fs_context->src_type()));
142 143
143 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth) 144 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
144 return base::PLATFORM_FILE_ERROR_NO_SPACE; 145 return base::PLATFORM_FILE_ERROR_NO_SPACE;
145 } 146 }
146 147
147 base::PlatformFileError error = underlying_file_util_->EnsureFileExists( 148 base::PlatformFileError error = underlying_file_util()->EnsureFileExists(
148 fs_context, file_path, created); 149 fs_context, file_path, created);
149 150
150 if (growth > 0 &&error == base::PLATFORM_FILE_OK) 151 if (growth > 0 &&error == base::PLATFORM_FILE_OK)
151 helper->NotifyUpdate(growth); 152 helper->NotifyUpdate(growth);
152 153
153 return error; 154 return error;
154 } 155 }
155 156
156 PlatformFileError QuotaFileUtil::CreateDirectory( 157 PlatformFileError QuotaFileUtil::CreateDirectory(
157 FileSystemOperationContext* fs_context, 158 FileSystemOperationContext* fs_context,
158 const FilePath& file_path, 159 const FilePath& file_path,
159 bool exclusive, 160 bool exclusive,
160 bool recursive) { 161 bool recursive) {
161 DCHECK(fs_context); 162 DCHECK(fs_context);
162 scoped_ptr<ScopedOriginUpdateHelper> helper; 163 scoped_ptr<ScopedOriginUpdateHelper> helper;
163 164
164 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth(); 165 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
165 int64 growth = 0; 166 int64 growth = 0;
166 167
167 if (!exclusive || !file_util::PathExists(file_path)) { 168 if (!exclusive || !file_util::PathExists(file_path)) {
168 if (recursive) { 169 if (recursive) {
169 FilePath last_path; 170 FilePath last_path;
170 for (FilePath path = fs_context->src_virtual_path(); 171 for (FilePath path = fs_context->src_virtual_path();
171 path.value() != last_path.value() && 172 path.value() != last_path.value() &&
172 !fs_context->src_file_system_file_util()->PathExists( 173 !fs_context->src_file_util()->PathExists(
173 fs_context, fs_context->src_virtual_path()); 174 fs_context, fs_context->src_virtual_path());
174 path = path.DirName()) { 175 path = path.DirName()) {
175 growth += ComputeFilePathCost(fs_context->src_virtual_path()); 176 growth += ComputeFilePathCost(fs_context->src_virtual_path());
176 last_path = path; 177 last_path = path;
177 } 178 }
178 } else { 179 } else {
179 growth += ComputeFilePathCost(fs_context->src_virtual_path()); 180 growth += ComputeFilePathCost(fs_context->src_virtual_path());
180 } 181 }
181 } 182 }
182 183
183 if (growth > 0) { 184 if (growth > 0) {
184 helper.reset(new ScopedOriginUpdateHelper( 185 helper.reset(new ScopedOriginUpdateHelper(
185 fs_context, 186 fs_context,
186 fs_context->src_origin_url(), 187 fs_context->src_origin_url(),
187 fs_context->src_type())); 188 fs_context->src_type()));
188 189
189 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth) 190 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
190 return base::PLATFORM_FILE_ERROR_NO_SPACE; 191 return base::PLATFORM_FILE_ERROR_NO_SPACE;
191 } 192 }
192 193
193 base::PlatformFileError error = base::PLATFORM_FILE_OK; 194 base::PlatformFileError error = base::PLATFORM_FILE_OK;
194 error = underlying_file_util_->CreateDirectory( 195 error = underlying_file_util()->CreateDirectory(
195 fs_context, file_path, exclusive, recursive); 196 fs_context, file_path, exclusive, recursive);
196 197
197 if (growth > 0 && error == base::PLATFORM_FILE_OK) 198 if (growth > 0 && error == base::PLATFORM_FILE_OK)
198 helper->NotifyUpdate(growth); 199 helper->NotifyUpdate(growth);
199 200
200 return error; 201 return error;
201 } 202 }
202 203
203 base::PlatformFileError QuotaFileUtil::CopyOrMoveFile( 204 base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
204 FileSystemOperationContext* fs_context, 205 FileSystemOperationContext* fs_context,
(...skipping 26 matching lines...) Expand all
231 ComputeFilePathCost(fs_context->src_virtual_path()); 232 ComputeFilePathCost(fs_context->src_virtual_path());
232 int64 dest_file_path_cost = 233 int64 dest_file_path_cost =
233 ComputeFilePathCost(fs_context->dest_virtual_path()); 234 ComputeFilePathCost(fs_context->dest_virtual_path());
234 if (!file_util::GetFileInfo(dest_file_path, &dest_file_info)) 235 if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
235 dest_file_info.size = 0; 236 dest_file_info.size = 0;
236 growth = -dest_file_info.size - src_file_path_cost + dest_file_path_cost; 237 growth = -dest_file_info.size - src_file_path_cost + dest_file_path_cost;
237 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth) 238 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
238 return base::PLATFORM_FILE_ERROR_NO_SPACE; 239 return base::PLATFORM_FILE_ERROR_NO_SPACE;
239 } 240 }
240 241
241 base::PlatformFileError error = underlying_file_util_->CopyOrMoveFile( 242 base::PlatformFileError error = underlying_file_util()->CopyOrMoveFile(
242 fs_context, src_file_path, dest_file_path, copy); 243 fs_context, src_file_path, dest_file_path, copy);
243 244
244 if (error == base::PLATFORM_FILE_OK) { 245 if (error == base::PLATFORM_FILE_OK) {
245 // TODO(kinuko): For cross-filesystem move case, call this with -growth 246 // TODO(kinuko): For cross-filesystem move case, call this with -growth
246 // for source and growth for dest. 247 // for source and growth for dest.
247 helper.NotifyUpdate(growth); 248 helper.NotifyUpdate(growth);
248 } 249 }
249 250
250 return error; 251 return error;
251 } 252 }
252 253
253 base::PlatformFileError QuotaFileUtil::DeleteFile( 254 base::PlatformFileError QuotaFileUtil::DeleteFile(
254 FileSystemOperationContext* fs_context, 255 FileSystemOperationContext* fs_context,
255 const FilePath& file_path) { 256 const FilePath& file_path) {
256 DCHECK(fs_context); 257 DCHECK(fs_context);
257 ScopedOriginUpdateHelper helper( 258 ScopedOriginUpdateHelper helper(
258 fs_context, 259 fs_context,
259 fs_context->src_origin_url(), 260 fs_context->src_origin_url(),
260 fs_context->src_type()); 261 fs_context->src_type());
261 262
262 int64 growth = 0; 263 int64 growth = 0;
263 base::PlatformFileInfo file_info; 264 base::PlatformFileInfo file_info;
264 if (file_util::GetFileInfo(file_path, &file_info)) { 265 if (file_util::GetFileInfo(file_path, &file_info)) {
265 growth -= file_info.size + 266 growth -= file_info.size +
266 ComputeFilePathCost(fs_context->src_virtual_path()); 267 ComputeFilePathCost(fs_context->src_virtual_path());
267 } 268 }
268 269
269 base::PlatformFileError error = underlying_file_util_->DeleteFile( 270 base::PlatformFileError error = underlying_file_util()->DeleteFile(
270 fs_context, file_path); 271 fs_context, file_path);
271 272
272 if (error == base::PLATFORM_FILE_OK) 273 if (error == base::PLATFORM_FILE_OK)
273 helper.NotifyUpdate(growth); 274 helper.NotifyUpdate(growth);
274 275
275 return error; 276 return error;
276 } 277 }
277 278
278 base::PlatformFileError QuotaFileUtil::DeleteSingleDirectory( 279 base::PlatformFileError QuotaFileUtil::DeleteSingleDirectory(
279 FileSystemOperationContext* fs_context, 280 FileSystemOperationContext* fs_context,
280 const FilePath& file_path) { 281 const FilePath& file_path) {
281 DCHECK(fs_context); 282 DCHECK(fs_context);
282 ScopedOriginUpdateHelper helper( 283 ScopedOriginUpdateHelper helper(
283 fs_context, 284 fs_context,
284 fs_context->src_origin_url(), 285 fs_context->src_origin_url(),
285 fs_context->src_type()); 286 fs_context->src_type());
286 287
287 int64 growth = 0; 288 int64 growth = 0;
288 if (file_util::DirectoryExists(file_path)) 289 if (file_util::DirectoryExists(file_path))
289 growth -= ComputeFilePathCost(fs_context->src_virtual_path()); 290 growth -= ComputeFilePathCost(fs_context->src_virtual_path());
290 291
291 base::PlatformFileError error = underlying_file_util_->DeleteSingleDirectory( 292 base::PlatformFileError error = underlying_file_util()->DeleteSingleDirectory(
292 fs_context, file_path); 293 fs_context, file_path);
293 294
294 if (error == base::PLATFORM_FILE_OK) 295 if (error == base::PLATFORM_FILE_OK)
295 helper.NotifyUpdate(growth); 296 helper.NotifyUpdate(growth);
296 297
297 return error; 298 return error;
298 } 299 }
299 300
300 base::PlatformFileError QuotaFileUtil::Truncate( 301 base::PlatformFileError QuotaFileUtil::Truncate(
301 FileSystemOperationContext* fs_context, 302 FileSystemOperationContext* fs_context,
302 const FilePath& path, 303 const FilePath& path,
303 int64 length) { 304 int64 length) {
304 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth(); 305 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
305 ScopedOriginUpdateHelper helper( 306 ScopedOriginUpdateHelper helper(
306 fs_context, 307 fs_context,
307 fs_context->src_origin_url(), 308 fs_context->src_origin_url(),
308 fs_context->src_type()); 309 fs_context->src_type());
309 310
310 int64 growth = 0; 311 int64 growth = 0;
311 base::PlatformFileInfo file_info; 312 base::PlatformFileInfo file_info;
312 if (!file_util::GetFileInfo(path, &file_info)) 313 if (!file_util::GetFileInfo(path, &file_info))
313 return base::PLATFORM_FILE_ERROR_FAILED; 314 return base::PLATFORM_FILE_ERROR_FAILED;
314 315
315 growth = length - file_info.size; 316 growth = length - file_info.size;
316 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth) 317 if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
317 return base::PLATFORM_FILE_ERROR_NO_SPACE; 318 return base::PLATFORM_FILE_ERROR_NO_SPACE;
318 319
319 base::PlatformFileError error = underlying_file_util_->Truncate( 320 base::PlatformFileError error = underlying_file_util()->Truncate(
320 fs_context, path, length); 321 fs_context, path, length);
321 322
322 if (error == base::PLATFORM_FILE_OK) 323 if (error == base::PLATFORM_FILE_OK)
323 helper.NotifyUpdate(growth); 324 helper.NotifyUpdate(growth);
324 325
325 return error; 326 return error;
326 } 327 }
327 328
328 // Checks if copying in the same filesystem can be performed. 329 // Checks if copying in the same filesystem can be performed.
329 // This method is not called for moving within a single filesystem. 330 // This method is not called for moving within a single filesystem.
(...skipping 17 matching lines...) Expand all
347 } 348 }
348 *growth = src_file_info.size - dest_file_info.size + dest_file_path_cost; 349 *growth = src_file_info.size - dest_file_info.size + dest_file_path_cost;
349 if (allowed_bytes_growth != QuotaFileUtil::kNoLimit && 350 if (allowed_bytes_growth != QuotaFileUtil::kNoLimit &&
350 *growth > allowed_bytes_growth) 351 *growth > allowed_bytes_growth)
351 return false; 352 return false;
352 353
353 return true; 354 return true;
354 } 355 }
355 356
356 } // namespace fileapi 357 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698