| 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/local_file_system_test_helper.h" | 5 #include "webkit/fileapi/local_file_system_test_helper.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 void LocalFileSystemTestOriginHelper::SetUp( | 44 void LocalFileSystemTestOriginHelper::SetUp( |
| 45 FileSystemContext* file_system_context) { | 45 FileSystemContext* file_system_context) { |
| 46 file_system_context_ = file_system_context; | 46 file_system_context_ = file_system_context; |
| 47 | 47 |
| 48 SetUpFileUtil(); | 48 SetUpFileUtil(); |
| 49 | 49 |
| 50 // Prepare the origin's root directory. | 50 // Prepare the origin's root directory. |
| 51 file_system_context_->GetMountPointProvider(type_)-> | 51 file_system_context_->GetMountPointProvider(type_)-> |
| 52 GetFileSystemRootPathOnFileThread( | 52 GetFileSystemRootPathOnFileThread(CreateURL(FilePath()), |
| 53 FileSystemURL(origin_, type_, FilePath()), true /* create */); | 53 true /* create */); |
| 54 | 54 |
| 55 // Initialize the usage cache file. | 55 // Initialize the usage cache file. |
| 56 FilePath usage_cache_path = GetUsageCachePath(); | 56 FilePath usage_cache_path = GetUsageCachePath(); |
| 57 if (!usage_cache_path.empty()) | 57 if (!usage_cache_path.empty()) |
| 58 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 58 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void LocalFileSystemTestOriginHelper::SetUp( | 61 void LocalFileSystemTestOriginHelper::SetUp( |
| 62 const FilePath& base_dir, | 62 const FilePath& base_dir, |
| 63 bool unlimited_quota, | 63 bool unlimited_quota, |
| 64 quota::QuotaManagerProxy* quota_manager_proxy) { | 64 quota::QuotaManagerProxy* quota_manager_proxy) { |
| 65 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 65 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
| 66 new quota::MockSpecialStoragePolicy; | 66 new quota::MockSpecialStoragePolicy; |
| 67 special_storage_policy->SetAllUnlimited(unlimited_quota); | 67 special_storage_policy->SetAllUnlimited(unlimited_quota); |
| 68 file_system_context_ = new FileSystemContext( | 68 file_system_context_ = new FileSystemContext( |
| 69 FileSystemTaskRunners::CreateMockTaskRunners(), | 69 FileSystemTaskRunners::CreateMockTaskRunners(), |
| 70 special_storage_policy, | 70 special_storage_policy, |
| 71 quota_manager_proxy, | 71 quota_manager_proxy, |
| 72 base_dir, | 72 base_dir, |
| 73 CreateAllowFileAccessOptions()); | 73 CreateAllowFileAccessOptions()); |
| 74 | 74 |
| 75 SetUpFileUtil(); | 75 SetUpFileUtil(); |
| 76 | 76 |
| 77 // Prepare the origin's root directory. | 77 // Prepare the origin's root directory. |
| 78 FileSystemMountPointProvider* mount_point_provider = | 78 FileSystemMountPointProvider* mount_point_provider = |
| 79 file_system_context_->GetMountPointProvider(type_); | 79 file_system_context_->GetMountPointProvider(type_); |
| 80 mount_point_provider->GetFileSystemRootPathOnFileThread( | 80 mount_point_provider->GetFileSystemRootPathOnFileThread(CreateURL(FilePath()), |
| 81 FileSystemURL(origin_, type_, FilePath()), true /* create */); | 81 true /* create */); |
| 82 | 82 |
| 83 // Initialize the usage cache file. | 83 // Initialize the usage cache file. |
| 84 FilePath usage_cache_path = GetUsageCachePath(); | 84 FilePath usage_cache_path = GetUsageCachePath(); |
| 85 if (!usage_cache_path.empty()) | 85 if (!usage_cache_path.empty()) |
| 86 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); | 86 FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void LocalFileSystemTestOriginHelper::TearDown() { | 89 void LocalFileSystemTestOriginHelper::TearDown() { |
| 90 file_system_context_ = NULL; | 90 file_system_context_ = NULL; |
| 91 MessageLoop::current()->RunUntilIdle(); | 91 MessageLoop::current()->RunUntilIdle(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 FilePath LocalFileSystemTestOriginHelper::GetOriginRootPath() const { | 94 FilePath LocalFileSystemTestOriginHelper::GetOriginRootPath() const { |
| 95 return file_system_context_->GetMountPointProvider(type_)-> | 95 return file_system_context_->GetMountPointProvider(type_)-> |
| 96 GetFileSystemRootPathOnFileThread( | 96 GetFileSystemRootPathOnFileThread(CreateURL(FilePath()), false); |
| 97 FileSystemURL(origin_, type_, FilePath()), false); | |
| 98 } | 97 } |
| 99 | 98 |
| 100 FilePath LocalFileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { | 99 FilePath LocalFileSystemTestOriginHelper::GetLocalPath(const FilePath& path) { |
| 101 DCHECK(file_util_); | 100 DCHECK(file_util_); |
| 102 FilePath local_path; | 101 FilePath local_path; |
| 103 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); | 102 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); |
| 104 file_util_->GetLocalFilePath(context.get(), CreateURL(path), &local_path); | 103 file_util_->GetLocalFilePath(context.get(), CreateURL(path), &local_path); |
| 105 return local_path; | 104 return local_path; |
| 106 } | 105 } |
| 107 | 106 |
| 108 FilePath LocalFileSystemTestOriginHelper::GetLocalPathFromASCII( | 107 FilePath LocalFileSystemTestOriginHelper::GetLocalPathFromASCII( |
| 109 const std::string& path) { | 108 const std::string& path) { |
| 110 return GetLocalPath(FilePath().AppendASCII(path)); | 109 return GetLocalPath(FilePath().AppendASCII(path)); |
| 111 } | 110 } |
| 112 | 111 |
| 113 FilePath LocalFileSystemTestOriginHelper::GetUsageCachePath() const { | 112 FilePath LocalFileSystemTestOriginHelper::GetUsageCachePath() const { |
| 114 if (type_ != kFileSystemTypeTemporary && | 113 if (type_ != kFileSystemTypeTemporary && |
| 115 type_ != kFileSystemTypePersistent) | 114 type_ != kFileSystemTypePersistent) |
| 116 return FilePath(); | 115 return FilePath(); |
| 117 return file_system_context_-> | 116 return file_system_context_-> |
| 118 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 117 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 119 } | 118 } |
| 120 | 119 |
| 121 FileSystemURL LocalFileSystemTestOriginHelper::CreateURL(const FilePath& path) | 120 FileSystemURL LocalFileSystemTestOriginHelper::CreateURL(const FilePath& path) |
| 122 const { | 121 const { |
| 123 return FileSystemURL(origin_, type_, path); | 122 return file_system_context_->CreateCrackedFileSystemURL(origin_, type_, path); |
| 124 } | 123 } |
| 125 | 124 |
| 126 base::PlatformFileError LocalFileSystemTestOriginHelper::SameFileUtilCopy( | 125 base::PlatformFileError LocalFileSystemTestOriginHelper::SameFileUtilCopy( |
| 127 FileSystemOperationContext* context, | 126 FileSystemOperationContext* context, |
| 128 const FileSystemURL& src, | 127 const FileSystemURL& src, |
| 129 const FileSystemURL& dest) const { | 128 const FileSystemURL& dest) const { |
| 130 return FileUtilHelper::Copy(context, file_util(), file_util(), src, dest); | 129 return FileUtilHelper::Copy(context, file_util(), file_util(), src, dest); |
| 131 } | 130 } |
| 132 | 131 |
| 133 base::PlatformFileError LocalFileSystemTestOriginHelper::SameFileUtilMove( | 132 base::PlatformFileError LocalFileSystemTestOriginHelper::SameFileUtilMove( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 file_system_context_->partition_path())); | 185 file_system_context_->partition_path())); |
| 187 } | 186 } |
| 188 FileSystemMountPointProvider* mount_point_provider = | 187 FileSystemMountPointProvider* mount_point_provider = |
| 189 file_system_context_->GetMountPointProvider(type_); | 188 file_system_context_->GetMountPointProvider(type_); |
| 190 DCHECK(mount_point_provider); | 189 DCHECK(mount_point_provider); |
| 191 file_util_ = mount_point_provider->GetFileUtil(type_); | 190 file_util_ = mount_point_provider->GetFileUtil(type_); |
| 192 DCHECK(file_util_); | 191 DCHECK(file_util_); |
| 193 } | 192 } |
| 194 | 193 |
| 195 } // namespace fileapi | 194 } // namespace fileapi |
| OLD | NEW |