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

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

Issue 10828043: Wire up the deleteFileSystem operation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactoring. Created 8 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) 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/fileapi/sandbox_mount_point_provider.h" 5 #include "webkit/fileapi/sandbox_mount_point_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/task_runner_util.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 #include "webkit/fileapi/file_system_file_stream_reader.h" 19 #include "webkit/fileapi/file_system_file_stream_reader.h"
19 #include "webkit/fileapi/file_system_operation_context.h" 20 #include "webkit/fileapi/file_system_operation_context.h"
20 #include "webkit/fileapi/file_system_options.h" 21 #include "webkit/fileapi/file_system_options.h"
21 #include "webkit/fileapi/file_system_types.h" 22 #include "webkit/fileapi/file_system_types.h"
22 #include "webkit/fileapi/file_system_usage_cache.h" 23 #include "webkit/fileapi/file_system_usage_cache.h"
23 #include "webkit/fileapi/file_system_util.h" 24 #include "webkit/fileapi/file_system_util.h"
24 #include "webkit/fileapi/local_file_system_operation.h" 25 #include "webkit/fileapi/local_file_system_operation.h"
25 #include "webkit/fileapi/native_file_util.h" 26 #include "webkit/fileapi/native_file_util.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // done before anyone looks up a filesystem. Most entry points start by trying 262 // done before anyone looks up a filesystem. Most entry points start by trying
262 // to look up the filesystem's root, so we can take care of most of them by 263 // to look up the filesystem's root, so we can take care of most of them by
263 // putting a check there. 264 // putting a check there.
264 void MigrateIfNeeded( 265 void MigrateIfNeeded(
265 ObfuscatedFileUtil* file_util, 266 ObfuscatedFileUtil* file_util,
266 const FilePath& old_base_path) { 267 const FilePath& old_base_path) {
267 if (file_util::DirectoryExists(old_base_path)) 268 if (file_util::DirectoryExists(old_base_path))
268 MigrateAllOldFileSystems(file_util, old_base_path); 269 MigrateAllOldFileSystems(file_util, old_base_path);
269 } 270 }
270 271
271 void PassPointerErrorByValue(
272 const base::Callback<void(PlatformFileError)>& callback,
273 PlatformFileError* error_ptr) {
274 DCHECK(error_ptr);
275 callback.Run(*error_ptr);
276 }
277
278 void DidValidateFileSystemRoot( 272 void DidValidateFileSystemRoot(
279 base::WeakPtr<SandboxMountPointProvider> mount_point_provider, 273 base::WeakPtr<SandboxMountPointProvider> mount_point_provider,
280 const base::Callback<void(PlatformFileError)>& callback, 274 const FileSystemMountPointProvider::ValidateFileSystemCallback& callback,
281 base::PlatformFileError* error) { 275 base::PlatformFileError* error) {
282 if (mount_point_provider.get()) 276 if (mount_point_provider.get())
283 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); 277 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error);
284 callback.Run(*error); 278 callback.Run(*error);
285 } 279 }
286 280
287 void ValidateRootOnFileThread( 281 void ValidateRootOnFileThread(
288 ObfuscatedFileUtil* file_util, 282 ObfuscatedFileUtil* file_util,
289 const GURL& origin_url, 283 const GURL& origin_url,
290 FileSystemType type, 284 FileSystemType type,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 const FileSystemURL& url, 446 const FileSystemURL& url,
453 int64 offset, 447 int64 offset,
454 FileSystemContext* context) const { 448 FileSystemContext* context) const {
455 return new SandboxFileStreamWriter(context, url, offset); 449 return new SandboxFileStreamWriter(context, url, offset);
456 } 450 }
457 451
458 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() { 452 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() {
459 return this; 453 return this;
460 } 454 }
461 455
456 void SandboxMountPointProvider::DeleteFileSystem(
457 const GURL& origin_url,
458 FileSystemType type,
459 FileSystemContext* context,
460 const DeleteFileSystemCallback& callback) {
461 base::PostTaskAndReplyWithResult(
462 context->file_task_runner(),
463 FROM_HERE,
464 base::Bind(&SandboxMountPointProvider::DeleteOriginDataOnFileThread,
kinuko 2012/08/02 00:38:35 nit: could you add a brief comment that it's safe
nhiroki (google) 2012/08/02 17:38:38 Done.
465 base::Unretained(this),
466 make_scoped_refptr(context),
467 base::Unretained(context->quota_manager_proxy()),
kinuko 2012/08/02 00:38:35 nit: I guess you don't need this Unretained decora
nhiroki (google) 2012/08/02 17:38:38 In this case, we need to decorate it since QuotaMa
468 origin_url,
469 type),
470 callback);
471 }
472
462 FilePath SandboxMountPointProvider::old_base_path() const { 473 FilePath SandboxMountPointProvider::old_base_path() const {
463 return profile_path_.Append(kOldFileSystemDirectory); 474 return profile_path_.Append(kOldFileSystemDirectory);
464 } 475 }
465 476
466 FilePath SandboxMountPointProvider::new_base_path() const { 477 FilePath SandboxMountPointProvider::new_base_path() const {
467 return profile_path_.Append(kNewFileSystemDirectory); 478 return profile_path_.Append(kNewFileSystemDirectory);
468 } 479 }
469 480
470 FilePath SandboxMountPointProvider::renamed_old_base_path() const { 481 FilePath SandboxMountPointProvider::renamed_old_base_path() const {
471 return profile_path_.Append(kRenamedOldFileSystemDirectory); 482 return profile_path_.Append(kRenamedOldFileSystemDirectory);
(...skipping 11 matching lines...) Expand all
483 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); 494 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path());
484 495
485 base::PlatformFileError error = base::PLATFORM_FILE_OK; 496 base::PlatformFileError error = base::PLATFORM_FILE_OK;
486 FilePath path = sandbox_file_util_->GetDirectoryForOriginAndType( 497 FilePath path = sandbox_file_util_->GetDirectoryForOriginAndType(
487 origin_url, type, create, &error); 498 origin_url, type, create, &error);
488 if (error != base::PLATFORM_FILE_OK) 499 if (error != base::PLATFORM_FILE_OK)
489 return FilePath(); 500 return FilePath();
490 return path; 501 return path;
491 } 502 }
492 503
493 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( 504 base::PlatformFileError
505 SandboxMountPointProvider::DeleteOriginDataOnFileThread(
494 FileSystemContext* file_system_context, 506 FileSystemContext* file_system_context,
495 QuotaManagerProxy* proxy, 507 QuotaManagerProxy* proxy,
496 const GURL& origin_url, 508 const GURL& origin_url,
497 fileapi::FileSystemType type) { 509 fileapi::FileSystemType type) {
498 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); 510 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path());
499 511
500 int64 usage = GetOriginUsageOnFileThread(file_system_context, 512 int64 usage = GetOriginUsageOnFileThread(file_system_context,
501 origin_url, type); 513 origin_url, type);
502 514
503 bool result = 515 bool result =
504 sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type); 516 sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type);
505 if (result && proxy) { 517 if (result && proxy) {
506 proxy->NotifyStorageModified( 518 proxy->NotifyStorageModified(
507 quota::QuotaClient::kFileSystem, 519 quota::QuotaClient::kFileSystem,
508 origin_url, 520 origin_url,
509 FileSystemTypeToQuotaStorageType(type), 521 FileSystemTypeToQuotaStorageType(type),
510 -usage); 522 -usage);
511 } 523 }
512 return result; 524
525 if (result)
526 return base::PLATFORM_FILE_OK;
527 return base::PLATFORM_FILE_ERROR_FAILED;
513 } 528 }
514 529
515 void SandboxMountPointProvider::GetOriginsForTypeOnFileThread( 530 void SandboxMountPointProvider::GetOriginsForTypeOnFileThread(
516 fileapi::FileSystemType type, std::set<GURL>* origins) { 531 fileapi::FileSystemType type, std::set<GURL>* origins) {
517 DCHECK(type == kFileSystemTypeTemporary || 532 DCHECK(type == kFileSystemTypeTemporary ||
518 type == kFileSystemTypePersistent); 533 type == kFileSystemTypePersistent);
519 DCHECK(origins); 534 DCHECK(origins);
520 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); 535 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator());
521 GURL origin; 536 GURL origin;
522 while (!(origin = enumerator->Next()).is_empty()) { 537 while (!(origin = enumerator->Next()).is_empty()) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 break; 748 break;
734 case base::PLATFORM_FILE_ERROR_FAILED: 749 case base::PLATFORM_FILE_ERROR_FAILED:
735 default: 750 default:
736 REPORT(kUnknownError); 751 REPORT(kUnknownError);
737 break; 752 break;
738 } 753 }
739 #undef REPORT 754 #undef REPORT
740 } 755 }
741 756
742 } // namespace fileapi 757 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/sandbox_mount_point_provider.h ('k') | webkit/fileapi/test_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698