| OLD | NEW |
| 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 Loading... |
| 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 11 matching lines...) Expand all Loading... |
| 302 kCreateDirectoryError, | 296 kCreateDirectoryError, |
| 303 kFileSystemErrorMax); | 297 kFileSystemErrorMax); |
| 304 } else { | 298 } else { |
| 305 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax); | 299 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax); |
| 306 } | 300 } |
| 307 // The reference of file_util will be derefed on the FILE thread | 301 // The reference of file_util will be derefed on the FILE thread |
| 308 // when the storage of this callback gets deleted regardless of whether | 302 // when the storage of this callback gets deleted regardless of whether |
| 309 // this method is called or not. | 303 // this method is called or not. |
| 310 } | 304 } |
| 311 | 305 |
| 306 base::PlatformFileError DeleteFileSystemOnFileThread( |
| 307 const GURL& origin_url, |
| 308 FileSystemType type, |
| 309 FileSystemContext* context) { |
| 310 return context->DeleteDataForOriginAndTypeOnFileThread(origin_url, type); |
| 311 } |
| 312 |
| 312 } // anonymous namespace | 313 } // anonymous namespace |
| 313 | 314 |
| 314 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = | 315 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = |
| 315 FILE_PATH_LITERAL("FileSystem"); | 316 FILE_PATH_LITERAL("FileSystem"); |
| 316 | 317 |
| 317 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = | 318 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = |
| 318 FILE_PATH_LITERAL("File System"); | 319 FILE_PATH_LITERAL("File System"); |
| 319 | 320 |
| 320 const FilePath::CharType | 321 const FilePath::CharType |
| 321 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = | 322 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 const FileSystemURL& url, | 453 const FileSystemURL& url, |
| 453 int64 offset, | 454 int64 offset, |
| 454 FileSystemContext* context) const { | 455 FileSystemContext* context) const { |
| 455 return new SandboxFileStreamWriter(context, url, offset); | 456 return new SandboxFileStreamWriter(context, url, offset); |
| 456 } | 457 } |
| 457 | 458 |
| 458 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() { | 459 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() { |
| 459 return this; | 460 return this; |
| 460 } | 461 } |
| 461 | 462 |
| 463 void SandboxMountPointProvider::DeleteFileSystem( |
| 464 const GURL& origin_url, |
| 465 FileSystemType type, |
| 466 FileSystemContext* context, |
| 467 const DeleteFileSystemCallback& callback) const { |
| 468 base::PostTaskAndReplyWithResult( |
| 469 context->file_task_runner(), |
| 470 FROM_HERE, |
| 471 base::Bind(&DeleteFileSystemOnFileThread, |
| 472 origin_url, |
| 473 type, |
| 474 make_scoped_refptr(context)), |
| 475 callback); |
| 476 } |
| 477 |
| 462 FilePath SandboxMountPointProvider::old_base_path() const { | 478 FilePath SandboxMountPointProvider::old_base_path() const { |
| 463 return profile_path_.Append(kOldFileSystemDirectory); | 479 return profile_path_.Append(kOldFileSystemDirectory); |
| 464 } | 480 } |
| 465 | 481 |
| 466 FilePath SandboxMountPointProvider::new_base_path() const { | 482 FilePath SandboxMountPointProvider::new_base_path() const { |
| 467 return profile_path_.Append(kNewFileSystemDirectory); | 483 return profile_path_.Append(kNewFileSystemDirectory); |
| 468 } | 484 } |
| 469 | 485 |
| 470 FilePath SandboxMountPointProvider::renamed_old_base_path() const { | 486 FilePath SandboxMountPointProvider::renamed_old_base_path() const { |
| 471 return profile_path_.Append(kRenamedOldFileSystemDirectory); | 487 return profile_path_.Append(kRenamedOldFileSystemDirectory); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 break; | 749 break; |
| 734 case base::PLATFORM_FILE_ERROR_FAILED: | 750 case base::PLATFORM_FILE_ERROR_FAILED: |
| 735 default: | 751 default: |
| 736 REPORT(kUnknownError); | 752 REPORT(kUnknownError); |
| 737 break; | 753 break; |
| 738 } | 754 } |
| 739 #undef REPORT | 755 #undef REPORT |
| 740 } | 756 } |
| 741 | 757 |
| 742 } // namespace fileapi | 758 } // namespace fileapi |
| OLD | NEW |