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

Side by Side Diff: webkit/browser/fileapi/file_system_context.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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) 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/file_system_context.h" 5 #include "webkit/browser/fileapi/file_system_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 29 matching lines...) Expand all
40 FileSystemContext* context, 40 FileSystemContext* context,
41 bool is_incognito) { 41 bool is_incognito) {
42 return new FileSystemQuotaClient(context, is_incognito); 42 return new FileSystemQuotaClient(context, is_incognito);
43 } 43 }
44 44
45 45
46 void DidGetMetadataForResolveURL( 46 void DidGetMetadataForResolveURL(
47 const base::FilePath& path, 47 const base::FilePath& path,
48 const FileSystemContext::ResolveURLCallback& callback, 48 const FileSystemContext::ResolveURLCallback& callback,
49 const FileSystemInfo& info, 49 const FileSystemInfo& info,
50 base::PlatformFileError error, 50 base::File::Error error,
51 const base::PlatformFileInfo& file_info) { 51 const base::File::Info& file_info) {
52 if (error != base::PLATFORM_FILE_OK) { 52 if (error != base::File::FILE_OK) {
53 callback.Run(error, FileSystemInfo(), base::FilePath(), false); 53 callback.Run(error, FileSystemInfo(), base::FilePath(), false);
54 return; 54 return;
55 } 55 }
56 callback.Run(error, info, path, file_info.is_directory); 56 callback.Run(error, info, path, file_info.is_directory);
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 // static 61 // static
62 int FileSystemContext::GetPermissionPolicy(FileSystemType type) { 62 int FileSystemContext::GetPermissionPolicy(FileSystemType type) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 bool success = true; 178 bool success = true;
179 for (FileSystemBackendMap::iterator iter = backend_map_.begin(); 179 for (FileSystemBackendMap::iterator iter = backend_map_.begin();
180 iter != backend_map_.end(); 180 iter != backend_map_.end();
181 ++iter) { 181 ++iter) {
182 FileSystemBackend* backend = iter->second; 182 FileSystemBackend* backend = iter->second;
183 if (!backend->GetQuotaUtil()) 183 if (!backend->GetQuotaUtil())
184 continue; 184 continue;
185 if (backend->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner( 185 if (backend->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner(
186 this, quota_manager_proxy(), origin_url, iter->first) 186 this, quota_manager_proxy(), origin_url, iter->first)
187 != base::PLATFORM_FILE_OK) { 187 != base::File::FILE_OK) {
188 // Continue the loop, but record the failure. 188 // Continue the loop, but record the failure.
189 success = false; 189 success = false;
190 } 190 }
191 } 191 }
192 192
193 return success; 193 return success;
194 } 194 }
195 195
196 scoped_refptr<QuotaReservation> 196 scoped_refptr<QuotaReservation>
197 FileSystemContext::CreateQuotaReservationOnFileTaskRunner( 197 FileSystemContext::CreateQuotaReservationOnFileTaskRunner(
(...skipping 28 matching lines...) Expand all
226 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil( 226 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil(
227 FileSystemType type) const { 227 FileSystemType type) const {
228 FileSystemBackend* backend = GetFileSystemBackend(type); 228 FileSystemBackend* backend = GetFileSystemBackend(type);
229 if (!backend) 229 if (!backend)
230 return NULL; 230 return NULL;
231 return backend->GetAsyncFileUtil(type); 231 return backend->GetAsyncFileUtil(type);
232 } 232 }
233 233
234 CopyOrMoveFileValidatorFactory* 234 CopyOrMoveFileValidatorFactory*
235 FileSystemContext::GetCopyOrMoveFileValidatorFactory( 235 FileSystemContext::GetCopyOrMoveFileValidatorFactory(
236 FileSystemType type, base::PlatformFileError* error_code) const { 236 FileSystemType type, base::File::Error* error_code) const {
237 DCHECK(error_code); 237 DCHECK(error_code);
238 *error_code = base::PLATFORM_FILE_OK; 238 *error_code = base::File::FILE_OK;
239 FileSystemBackend* backend = GetFileSystemBackend(type); 239 FileSystemBackend* backend = GetFileSystemBackend(type);
240 if (!backend) 240 if (!backend)
241 return NULL; 241 return NULL;
242 return backend->GetCopyOrMoveFileValidatorFactory( 242 return backend->GetCopyOrMoveFileValidatorFactory(
243 type, error_code); 243 type, error_code);
244 } 244 }
245 245
246 FileSystemBackend* FileSystemContext::GetFileSystemBackend( 246 FileSystemBackend* FileSystemContext::GetFileSystemBackend(
247 FileSystemType type) const { 247 FileSystemType type) const {
248 FileSystemBackendMap::const_iterator found = backend_map_.find(type); 248 FileSystemBackendMap::const_iterator found = backend_map_.find(type);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 void FileSystemContext::OpenFileSystem( 290 void FileSystemContext::OpenFileSystem(
291 const GURL& origin_url, 291 const GURL& origin_url,
292 FileSystemType type, 292 FileSystemType type,
293 OpenFileSystemMode mode, 293 OpenFileSystemMode mode,
294 const OpenFileSystemCallback& callback) { 294 const OpenFileSystemCallback& callback) {
295 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 295 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
296 DCHECK(!callback.is_null()); 296 DCHECK(!callback.is_null());
297 297
298 if (!FileSystemContext::IsSandboxFileSystem(type)) { 298 if (!FileSystemContext::IsSandboxFileSystem(type)) {
299 // Disallow opening a non-sandboxed filesystem. 299 // Disallow opening a non-sandboxed filesystem.
300 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY); 300 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY);
301 return; 301 return;
302 } 302 }
303 303
304 FileSystemBackend* backend = GetFileSystemBackend(type); 304 FileSystemBackend* backend = GetFileSystemBackend(type);
305 if (!backend) { 305 if (!backend) {
306 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY); 306 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY);
307 return; 307 return;
308 } 308 }
309 309
310 backend->OpenFileSystem(origin_url, type, mode, callback); 310 backend->OpenFileSystem(origin_url, type, mode, callback);
311 } 311 }
312 312
313 void FileSystemContext::ResolveURL( 313 void FileSystemContext::ResolveURL(
314 const FileSystemURL& url, 314 const FileSystemURL& url,
315 const ResolveURLCallback& callback) { 315 const ResolveURLCallback& callback) {
316 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 316 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
317 DCHECK(!callback.is_null()); 317 DCHECK(!callback.is_null());
318 318
319 if (!FileSystemContext::IsSandboxFileSystem(url.type())) { 319 if (!FileSystemContext::IsSandboxFileSystem(url.type())) {
320 #ifdef OS_CHROMEOS 320 #ifdef OS_CHROMEOS
321 // Do not have to open a non-sandboxed filesystem. 321 // Do not have to open a non-sandboxed filesystem.
322 // TODO(nhiroki): For now we assume this path is called only on ChromeOS, 322 // TODO(nhiroki): For now we assume this path is called only on ChromeOS,
323 // but this assumption may be broken in the future and we should handle 323 // but this assumption may be broken in the future and we should handle
324 // more generally. http://crbug.com/304062. 324 // more generally. http://crbug.com/304062.
325 FileSystemInfo info = GetFileSystemInfoForChromeOS(url.origin()); 325 FileSystemInfo info = GetFileSystemInfoForChromeOS(url.origin());
326 DidOpenFileSystemForResolveURL( 326 DidOpenFileSystemForResolveURL(
327 url, callback, info.root_url, info.name, base::PLATFORM_FILE_OK); 327 url, callback, info.root_url, info.name, base::File::FILE_OK);
328 return; 328 return;
329 #endif 329 #endif
330 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 330 callback.Run(base::File::FILE_ERROR_SECURITY,
331 FileSystemInfo(), base::FilePath(), false); 331 FileSystemInfo(), base::FilePath(), false);
332 return; 332 return;
333 } 333 }
334 334
335 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 335 FileSystemBackend* backend = GetFileSystemBackend(url.type());
336 if (!backend) { 336 if (!backend) {
337 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 337 callback.Run(base::File::FILE_ERROR_SECURITY,
338 FileSystemInfo(), base::FilePath(), false); 338 FileSystemInfo(), base::FilePath(), false);
339 return; 339 return;
340 } 340 }
341 341
342 backend->OpenFileSystem( 342 backend->OpenFileSystem(
343 url.origin(), url.type(), 343 url.origin(), url.type(),
344 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 344 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
345 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL, 345 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL,
346 this, url, callback)); 346 this, url, callback));
347 } 347 }
348 348
349 void FileSystemContext::DeleteFileSystem( 349 void FileSystemContext::DeleteFileSystem(
350 const GURL& origin_url, 350 const GURL& origin_url,
351 FileSystemType type, 351 FileSystemType type,
352 const StatusCallback& callback) { 352 const StatusCallback& callback) {
353 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 353 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
354 DCHECK(origin_url == origin_url.GetOrigin()); 354 DCHECK(origin_url == origin_url.GetOrigin());
355 DCHECK(!callback.is_null()); 355 DCHECK(!callback.is_null());
356 356
357 FileSystemBackend* backend = GetFileSystemBackend(type); 357 FileSystemBackend* backend = GetFileSystemBackend(type);
358 if (!backend) { 358 if (!backend) {
359 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 359 callback.Run(base::File::FILE_ERROR_SECURITY);
360 return; 360 return;
361 } 361 }
362 if (!backend->GetQuotaUtil()) { 362 if (!backend->GetQuotaUtil()) {
363 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); 363 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
364 return; 364 return;
365 } 365 }
366 366
367 base::PostTaskAndReplyWithResult( 367 base::PostTaskAndReplyWithResult(
368 default_file_task_runner(), 368 default_file_task_runner(),
369 FROM_HERE, 369 FROM_HERE,
370 // It is safe to pass Unretained(quota_util) since context owns it. 370 // It is safe to pass Unretained(quota_util) since context owns it.
371 base::Bind(&FileSystemQuotaUtil::DeleteOriginDataOnFileTaskRunner, 371 base::Bind(&FileSystemQuotaUtil::DeleteOriginDataOnFileTaskRunner,
372 base::Unretained(backend->GetQuotaUtil()), 372 base::Unretained(backend->GetQuotaUtil()),
373 make_scoped_refptr(this), 373 make_scoped_refptr(this),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 454
455 void FileSystemContext::DeleteOnCorrectThread() const { 455 void FileSystemContext::DeleteOnCorrectThread() const {
456 if (!io_task_runner_->RunsTasksOnCurrentThread() && 456 if (!io_task_runner_->RunsTasksOnCurrentThread() &&
457 io_task_runner_->DeleteSoon(FROM_HERE, this)) { 457 io_task_runner_->DeleteSoon(FROM_HERE, this)) {
458 return; 458 return;
459 } 459 }
460 delete this; 460 delete this;
461 } 461 }
462 462
463 FileSystemOperation* FileSystemContext::CreateFileSystemOperation( 463 FileSystemOperation* FileSystemContext::CreateFileSystemOperation(
464 const FileSystemURL& url, base::PlatformFileError* error_code) { 464 const FileSystemURL& url, base::File::Error* error_code) {
465 if (!url.is_valid()) { 465 if (!url.is_valid()) {
466 if (error_code) 466 if (error_code)
467 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; 467 *error_code = base::File::FILE_ERROR_INVALID_URL;
468 return NULL; 468 return NULL;
469 } 469 }
470 470
471 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 471 FileSystemBackend* backend = GetFileSystemBackend(url.type());
472 if (!backend) { 472 if (!backend) {
473 if (error_code) 473 if (error_code)
474 *error_code = base::PLATFORM_FILE_ERROR_FAILED; 474 *error_code = base::File::FILE_ERROR_FAILED;
475 return NULL; 475 return NULL;
476 } 476 }
477 477
478 base::PlatformFileError fs_error = base::PLATFORM_FILE_OK; 478 base::File::Error fs_error = base::File::FILE_OK;
479 FileSystemOperation* operation = 479 FileSystemOperation* operation =
480 backend->CreateFileSystemOperation(url, this, &fs_error); 480 backend->CreateFileSystemOperation(url, this, &fs_error);
481 481
482 if (error_code) 482 if (error_code)
483 *error_code = fs_error; 483 *error_code = fs_error;
484 return operation; 484 return operation;
485 } 485 }
486 486
487 FileSystemURL FileSystemContext::CrackFileSystemURL( 487 FileSystemURL FileSystemContext::CrackFileSystemURL(
488 const FileSystemURL& url) const { 488 const FileSystemURL& url) const {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 DCHECK(inserted); 536 DCHECK(inserted);
537 } 537 }
538 } 538 }
539 } 539 }
540 540
541 void FileSystemContext::DidOpenFileSystemForResolveURL( 541 void FileSystemContext::DidOpenFileSystemForResolveURL(
542 const FileSystemURL& url, 542 const FileSystemURL& url,
543 const FileSystemContext::ResolveURLCallback& callback, 543 const FileSystemContext::ResolveURLCallback& callback,
544 const GURL& filesystem_root, 544 const GURL& filesystem_root,
545 const std::string& filesystem_name, 545 const std::string& filesystem_name,
546 base::PlatformFileError error) { 546 base::File::Error error) {
547 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 547 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
548 548
549 if (error != base::PLATFORM_FILE_OK) { 549 if (error != base::File::FILE_OK) {
550 callback.Run(error, FileSystemInfo(), base::FilePath(), false); 550 callback.Run(error, FileSystemInfo(), base::FilePath(), false);
551 return; 551 return;
552 } 552 }
553 553
554 fileapi::FileSystemInfo info( 554 fileapi::FileSystemInfo info(
555 filesystem_name, filesystem_root, url.mount_type()); 555 filesystem_name, filesystem_root, url.mount_type());
556 556
557 // Extract the virtual path not containing a filesystem type part from |url|. 557 // Extract the virtual path not containing a filesystem type part from |url|.
558 base::FilePath parent = CrackURL(filesystem_root).virtual_path(); 558 base::FilePath parent = CrackURL(filesystem_root).virtual_path();
559 base::FilePath child = url.virtual_path(); 559 base::FilePath child = url.virtual_path();
560 base::FilePath path; 560 base::FilePath path;
561 561
562 if (parent.empty()) { 562 if (parent.empty()) {
563 path = child; 563 path = child;
564 } else if (parent != child) { 564 } else if (parent != child) {
565 bool result = parent.AppendRelativePath(child, &path); 565 bool result = parent.AppendRelativePath(child, &path);
566 DCHECK(result); 566 DCHECK(result);
567 } 567 }
568 568
569 operation_runner()->GetMetadata( 569 operation_runner()->GetMetadata(
570 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info)); 570 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info));
571 } 571 }
572 572
573 } // namespace fileapi 573 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/file_system_context.h ('k') | webkit/browser/fileapi/file_system_dir_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698