| OLD | NEW |
| 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/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_callback_factory.h" | 10 #include "base/memory/scoped_callback_factory.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = | 272 const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = |
| 273 FILE_PATH_LITERAL("FileSystem"); | 273 FILE_PATH_LITERAL("FileSystem"); |
| 274 | 274 |
| 275 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = | 275 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = |
| 276 FILE_PATH_LITERAL("File System"); | 276 FILE_PATH_LITERAL("File System"); |
| 277 | 277 |
| 278 const FilePath::CharType | 278 const FilePath::CharType |
| 279 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = | 279 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
| 280 FILE_PATH_LITERAL("FS.old"); | 280 FILE_PATH_LITERAL("FS.old"); |
| 281 | 281 |
| 282 SandboxMountPointProvider::SandboxMountPointProvider( | |
| 283 FileSystemPathManager* path_manager, | |
| 284 scoped_refptr<base::MessageLoopProxy> file_message_loop, | |
| 285 const FilePath& profile_path) | |
| 286 : FileSystemQuotaUtil(file_message_loop), | |
| 287 path_manager_(path_manager), | |
| 288 file_message_loop_(file_message_loop), | |
| 289 profile_path_(profile_path), | |
| 290 sandbox_file_util_( | |
| 291 new ObfuscatedFileUtil( | |
| 292 profile_path.Append(kNewFileSystemDirectory), | |
| 293 QuotaFileUtil::CreateDefault())) { | |
| 294 } | |
| 295 | |
| 296 SandboxMountPointProvider::~SandboxMountPointProvider() { | |
| 297 if (!file_message_loop_->BelongsToCurrentThread()) | |
| 298 file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); | |
| 299 } | |
| 300 | |
| 301 bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, | |
| 302 FileSystemType type, | |
| 303 const FilePath& unused) { | |
| 304 if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) | |
| 305 return false; | |
| 306 // We essentially depend on quota to do our access controls. | |
| 307 return path_manager_->IsAllowedScheme(origin_url); | |
| 308 } | |
| 309 | |
| 310 class SandboxMountPointProvider::GetFileSystemRootPathTask | 282 class SandboxMountPointProvider::GetFileSystemRootPathTask |
| 311 : public base::RefCountedThreadSafe< | 283 : public base::RefCountedThreadSafe< |
| 312 SandboxMountPointProvider::GetFileSystemRootPathTask> { | 284 SandboxMountPointProvider::GetFileSystemRootPathTask> { |
| 313 public: | 285 public: |
| 314 GetFileSystemRootPathTask( | 286 GetFileSystemRootPathTask( |
| 315 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 287 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 316 const GURL& origin_url, | 288 const GURL& origin_url, |
| 317 FileSystemType type, | 289 FileSystemType type, |
| 318 ObfuscatedFileUtil* file_util, | 290 ObfuscatedFileUtil* file_util, |
| 319 const FilePath& old_base_path, | 291 const FilePath& old_base_path, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 352 |
| 381 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 353 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
| 382 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 354 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
| 383 GURL origin_url_; | 355 GURL origin_url_; |
| 384 FileSystemType type_; | 356 FileSystemType type_; |
| 385 scoped_refptr<ObfuscatedFileUtil> file_util_; | 357 scoped_refptr<ObfuscatedFileUtil> file_util_; |
| 386 FilePath old_base_path_; | 358 FilePath old_base_path_; |
| 387 FileSystemPathManager::GetRootPathCallback callback_; | 359 FileSystemPathManager::GetRootPathCallback callback_; |
| 388 }; | 360 }; |
| 389 | 361 |
| 390 FilePath SandboxMountPointProvider::old_base_path() const { | 362 SandboxMountPointProvider::SandboxMountPointProvider( |
| 391 return profile_path_.Append(kOldFileSystemDirectory); | 363 FileSystemPathManager* path_manager, |
| 364 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 365 const FilePath& profile_path) |
| 366 : FileSystemQuotaUtil(file_message_loop), |
| 367 path_manager_(path_manager), |
| 368 file_message_loop_(file_message_loop), |
| 369 profile_path_(profile_path), |
| 370 sandbox_file_util_( |
| 371 new ObfuscatedFileUtil( |
| 372 profile_path.Append(kNewFileSystemDirectory), |
| 373 QuotaFileUtil::CreateDefault())) { |
| 392 } | 374 } |
| 393 | 375 |
| 394 FilePath SandboxMountPointProvider::new_base_path() const { | 376 SandboxMountPointProvider::~SandboxMountPointProvider() { |
| 395 return profile_path_.Append(kNewFileSystemDirectory); | 377 if (!file_message_loop_->BelongsToCurrentThread()) |
| 378 file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); |
| 396 } | 379 } |
| 397 | 380 |
| 398 FilePath SandboxMountPointProvider::renamed_old_base_path() const { | 381 bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
| 399 return profile_path_.Append(kRenamedOldFileSystemDirectory); | 382 FileSystemType type, |
| 400 } | 383 const FilePath& unused) { |
| 401 | 384 if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) |
| 402 bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) | |
| 403 const { | |
| 404 if (filename.value().empty()) | |
| 405 return false; | 385 return false; |
| 406 | 386 // We essentially depend on quota to do our access controls. |
| 407 std::string filename_lower = StringToLowerASCII( | 387 return path_manager_->IsAllowedScheme(origin_url); |
| 408 FilePathStringToASCII(filename.value())); | |
| 409 | |
| 410 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { | |
| 411 // Exact match. | |
| 412 if (filename_lower == kRestrictedNames[i]) | |
| 413 return true; | |
| 414 } | |
| 415 | |
| 416 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { | |
| 417 if (filename.value().find(kRestrictedChars[i]) != | |
| 418 FilePath::StringType::npos) | |
| 419 return true; | |
| 420 } | |
| 421 | |
| 422 return false; | |
| 423 } | |
| 424 | |
| 425 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { | |
| 426 NOTREACHED(); | |
| 427 // TODO(ericu): Implement this method and check for access permissions as | |
| 428 // fileBrowserPrivate extension API does. We currently have another mechanism, | |
| 429 // but we should switch over. This may also need to call MigrateIfNeeded(). | |
| 430 return std::vector<FilePath>(); | |
| 431 } | |
| 432 | |
| 433 SandboxMountPointProvider::OriginEnumerator* | |
| 434 SandboxMountPointProvider::CreateOriginEnumerator() const { | |
| 435 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | |
| 436 return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); | |
| 437 } | 388 } |
| 438 | 389 |
| 439 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( | 390 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
| 440 const GURL& origin_url, fileapi::FileSystemType type, bool create, | 391 const GURL& origin_url, fileapi::FileSystemType type, bool create, |
| 441 const FileSystemPathManager::GetRootPathCallback& callback) { | 392 const FileSystemPathManager::GetRootPathCallback& callback) { |
| 442 FilePath origin_base_path; | 393 FilePath origin_base_path; |
| 443 | 394 |
| 444 if (path_manager_->is_incognito()) { | 395 if (path_manager_->is_incognito()) { |
| 445 // TODO(kinuko): return an isolated temporary directory. | 396 // TODO(kinuko): return an isolated temporary directory. |
| 446 callback.Run(false, FilePath(), std::string()); | 397 callback.Run(false, FilePath(), std::string()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 475 | 426 |
| 476 if (!path_manager_->IsAllowedScheme(origin_url)) | 427 if (!path_manager_->IsAllowedScheme(origin_url)) |
| 477 return FilePath(); | 428 return FilePath(); |
| 478 | 429 |
| 479 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | 430 MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
| 480 | 431 |
| 481 return sandbox_file_util_->GetDirectoryForOriginAndType( | 432 return sandbox_file_util_->GetDirectoryForOriginAndType( |
| 482 origin_url, type, create); | 433 origin_url, type, create); |
| 483 } | 434 } |
| 484 | 435 |
| 436 bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) |
| 437 const { |
| 438 if (filename.value().empty()) |
| 439 return false; |
| 440 |
| 441 std::string filename_lower = StringToLowerASCII( |
| 442 FilePathStringToASCII(filename.value())); |
| 443 |
| 444 for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { |
| 445 // Exact match. |
| 446 if (filename_lower == kRestrictedNames[i]) |
| 447 return true; |
| 448 } |
| 449 |
| 450 for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { |
| 451 if (filename.value().find(kRestrictedChars[i]) != |
| 452 FilePath::StringType::npos) |
| 453 return true; |
| 454 } |
| 455 |
| 456 return false; |
| 457 } |
| 458 |
| 459 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { |
| 460 NOTREACHED(); |
| 461 // TODO(ericu): Implement this method and check for access permissions as |
| 462 // fileBrowserPrivate extension API does. We currently have another mechanism, |
| 463 // but we should switch over. This may also need to call MigrateIfNeeded(). |
| 464 return std::vector<FilePath>(); |
| 465 } |
| 466 |
| 467 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() { |
| 468 return sandbox_file_util_.get(); |
| 469 } |
| 470 |
| 471 FilePath SandboxMountPointProvider::old_base_path() const { |
| 472 return profile_path_.Append(kOldFileSystemDirectory); |
| 473 } |
| 474 |
| 475 FilePath SandboxMountPointProvider::new_base_path() const { |
| 476 return profile_path_.Append(kNewFileSystemDirectory); |
| 477 } |
| 478 |
| 479 FilePath SandboxMountPointProvider::renamed_old_base_path() const { |
| 480 return profile_path_.Append(kRenamedOldFileSystemDirectory); |
| 481 } |
| 482 |
| 483 SandboxMountPointProvider::OriginEnumerator* |
| 484 SandboxMountPointProvider::CreateOriginEnumerator() const { |
| 485 MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
| 486 return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); |
| 487 } |
| 488 |
| 485 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( | 489 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( |
| 486 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { | 490 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { |
| 487 | 491 |
| 488 MigrateIfNeeded(sandbox_file_util_, old_base_path()); | 492 MigrateIfNeeded(sandbox_file_util_, old_base_path()); |
| 489 | 493 |
| 490 return sandbox_file_util_->GetDirectoryForOriginAndType( | 494 return sandbox_file_util_->GetDirectoryForOriginAndType( |
| 491 origin_url, type, create); | 495 origin_url, type, create); |
| 492 } | 496 } |
| 493 | 497 |
| 494 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( | 498 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 637 |
| 634 void SandboxMountPointProvider::InvalidateUsageCache( | 638 void SandboxMountPointProvider::InvalidateUsageCache( |
| 635 const GURL& origin_url, fileapi::FileSystemType type) { | 639 const GURL& origin_url, fileapi::FileSystemType type) { |
| 636 DCHECK(type == fileapi::kFileSystemTypeTemporary || | 640 DCHECK(type == fileapi::kFileSystemTypeTemporary || |
| 637 type == fileapi::kFileSystemTypePersistent); | 641 type == fileapi::kFileSystemTypePersistent); |
| 638 FilePath usage_file_path = GetUsageCachePathForOriginAndType( | 642 FilePath usage_file_path = GetUsageCachePathForOriginAndType( |
| 639 origin_url, type); | 643 origin_url, type); |
| 640 FileSystemUsageCache::IncrementDirty(usage_file_path); | 644 FileSystemUsageCache::IncrementDirty(usage_file_path); |
| 641 } | 645 } |
| 642 | 646 |
| 643 FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() { | |
| 644 return sandbox_file_util_.get(); | |
| 645 } | |
| 646 | |
| 647 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( | 647 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( |
| 648 const GURL& origin_url, fileapi::FileSystemType type) const { | 648 const GURL& origin_url, fileapi::FileSystemType type) const { |
| 649 FilePath base_path = | 649 FilePath base_path = |
| 650 GetBaseDirectoryForOriginAndType(origin_url, type, false); | 650 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
| 651 if (base_path.empty()) | 651 if (base_path.empty()) |
| 652 return FilePath(); | 652 return FilePath(); |
| 653 return base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); | 653 return base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); |
| 654 } | 654 } |
| 655 | 655 |
| 656 FilePath SandboxMountPointProvider::OldCreateFileSystemRootPath( | 656 FilePath SandboxMountPointProvider::OldCreateFileSystemRootPath( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 672 | 672 |
| 673 // Creates the root directory. | 673 // Creates the root directory. |
| 674 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); | 674 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); |
| 675 if (!file_util::CreateDirectory(root)) | 675 if (!file_util::CreateDirectory(root)) |
| 676 return FilePath(); | 676 return FilePath(); |
| 677 | 677 |
| 678 return root; | 678 return root; |
| 679 } | 679 } |
| 680 | 680 |
| 681 } // namespace fileapi | 681 } // namespace fileapi |
| OLD | NEW |