| 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/file_system_context.h" | 5 #include "webkit/fileapi/file_system_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/stl_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 11 #include "webkit/fileapi/file_system_file_util.h" | 12 #include "webkit/fileapi/file_system_file_util.h" |
| 12 #include "webkit/fileapi/file_system_operation_interface.h" | 13 #include "webkit/fileapi/file_system_operation_interface.h" |
| 13 #include "webkit/fileapi/file_system_options.h" | 14 #include "webkit/fileapi/file_system_options.h" |
| 14 #include "webkit/fileapi/file_system_quota_client.h" | 15 #include "webkit/fileapi/file_system_quota_client.h" |
| 15 #include "webkit/fileapi/file_system_util.h" | 16 #include "webkit/fileapi/file_system_util.h" |
| 16 #include "webkit/fileapi/isolated_mount_point_provider.h" | 17 #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 17 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 18 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 18 #include "webkit/quota/quota_manager.h" | 19 #include "webkit/quota/quota_manager.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 type == fileapi::kFileSystemTypePersistent) { | 90 type == fileapi::kFileSystemTypePersistent) { |
| 90 DCHECK(sandbox_provider()); | 91 DCHECK(sandbox_provider()); |
| 91 return sandbox_provider()->DeleteOriginDataOnFileThread( | 92 return sandbox_provider()->DeleteOriginDataOnFileThread( |
| 92 quota_manager_proxy(), origin_url, type); | 93 quota_manager_proxy(), origin_url, type); |
| 93 } | 94 } |
| 94 return false; | 95 return false; |
| 95 } | 96 } |
| 96 | 97 |
| 97 FileSystemQuotaUtil* | 98 FileSystemQuotaUtil* |
| 98 FileSystemContext::GetQuotaUtil(FileSystemType type) const { | 99 FileSystemContext::GetQuotaUtil(FileSystemType type) const { |
| 99 if (type == fileapi::kFileSystemTypeTemporary || | 100 FileSystemMountPointProvider* mount_point_provider = |
| 100 type == fileapi::kFileSystemTypePersistent) { | 101 GetMountPointProvider(type); |
| 101 DCHECK(sandbox_provider()); | 102 if (!mount_point_provider) |
| 102 return sandbox_provider()->quota_util(); | 103 return NULL; |
| 103 } | 104 return mount_point_provider->GetQuotaUtil(); |
| 104 return NULL; | |
| 105 } | 105 } |
| 106 | 106 |
| 107 FileSystemFileUtil* FileSystemContext::GetFileUtil( | 107 FileSystemFileUtil* FileSystemContext::GetFileUtil( |
| 108 FileSystemType type) const { | 108 FileSystemType type) const { |
| 109 FileSystemMountPointProvider* mount_point_provider = | 109 FileSystemMountPointProvider* mount_point_provider = |
| 110 GetMountPointProvider(type); | 110 GetMountPointProvider(type); |
| 111 if (!mount_point_provider) | 111 if (!mount_point_provider) |
| 112 return NULL; | 112 return NULL; |
| 113 return mount_point_provider->GetFileUtil(); | 113 return mount_point_provider->GetFileUtil(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( | 116 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( |
| 117 FileSystemType type) const { | 117 FileSystemType type) const { |
| 118 switch (type) { | 118 switch (type) { |
| 119 case kFileSystemTypeTemporary: | 119 case kFileSystemTypeTemporary: |
| 120 case kFileSystemTypePersistent: | 120 case kFileSystemTypePersistent: |
| 121 return sandbox_provider_.get(); | 121 return sandbox_provider_.get(); |
| 122 case kFileSystemTypeExternal: | 122 case kFileSystemTypeExternal: |
| 123 return external_provider_.get(); | 123 return external_provider_.get(); |
| 124 case kFileSystemTypeIsolated: | 124 case kFileSystemTypeIsolated: |
| 125 return isolated_provider_.get(); | 125 return isolated_provider_.get(); |
| 126 default: |
| 127 if (provider_map_.find(type) != provider_map_.end()) |
| 128 return provider_map_.find(type)->second; |
| 129 // Fall through. |
| 126 case kFileSystemTypeUnknown: | 130 case kFileSystemTypeUnknown: |
| 127 default: | |
| 128 NOTREACHED(); | 131 NOTREACHED(); |
| 129 return NULL; | 132 return NULL; |
| 130 } | 133 } |
| 131 } | 134 } |
| 132 | 135 |
| 133 SandboxMountPointProvider* | 136 SandboxMountPointProvider* |
| 134 FileSystemContext::sandbox_provider() const { | 137 FileSystemContext::sandbox_provider() const { |
| 135 return sandbox_provider_.get(); | 138 return sandbox_provider_.get(); |
| 136 } | 139 } |
| 137 | 140 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 FilePath file_path; | 188 FilePath file_path; |
| 186 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path)) | 189 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path)) |
| 187 return NULL; | 190 return NULL; |
| 188 FileSystemMountPointProvider* mount_point_provider = | 191 FileSystemMountPointProvider* mount_point_provider = |
| 189 GetMountPointProvider(file_system_type); | 192 GetMountPointProvider(file_system_type); |
| 190 if (!mount_point_provider) | 193 if (!mount_point_provider) |
| 191 return NULL; | 194 return NULL; |
| 192 return mount_point_provider->CreateFileReader(url, offset, this); | 195 return mount_point_provider->CreateFileReader(url, offset, this); |
| 193 } | 196 } |
| 194 | 197 |
| 198 void FileSystemContext::RegisterMountPointProvider( |
| 199 FileSystemType type, |
| 200 FileSystemMountPointProvider* provider) { |
| 201 DCHECK(provider); |
| 202 DCHECK(provider_map_.find(type) == provider_map_.end()); |
| 203 provider_map_[type] = provider; |
| 204 } |
| 205 |
| 195 FileSystemContext::~FileSystemContext() {} | 206 FileSystemContext::~FileSystemContext() {} |
| 196 | 207 |
| 197 void FileSystemContext::DeleteOnCorrectThread() const { | 208 void FileSystemContext::DeleteOnCorrectThread() const { |
| 198 if (!io_task_runner_->RunsTasksOnCurrentThread() && | 209 if (!io_task_runner_->RunsTasksOnCurrentThread() && |
| 199 io_task_runner_->DeleteSoon(FROM_HERE, this)) { | 210 io_task_runner_->DeleteSoon(FROM_HERE, this)) { |
| 200 return; | 211 return; |
| 201 } | 212 } |
| 213 STLDeleteContainerPairSecondPointers(provider_map_.begin(), |
| 214 provider_map_.end()); |
| 202 delete this; | 215 delete this; |
| 203 } | 216 } |
| 204 | 217 |
| 205 } // namespace fileapi | 218 } // namespace fileapi |
| OLD | NEW |