| 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/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 6 | 6 |
| 7 #include "base/chromeos/chromeos_version.h" | 7 #include "base/chromeos/chromeos_version.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 void CrosMountPointProvider::ValidateFileSystemRoot( | 65 void CrosMountPointProvider::ValidateFileSystemRoot( |
| 66 const GURL& origin_url, | 66 const GURL& origin_url, |
| 67 fileapi::FileSystemType type, | 67 fileapi::FileSystemType type, |
| 68 bool create, | 68 bool create, |
| 69 const ValidateFileSystemCallback& callback) { | 69 const ValidateFileSystemCallback& callback) { |
| 70 DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); | 70 DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); |
| 71 // Nothing to validate for external filesystem. | 71 // Nothing to validate for external filesystem. |
| 72 callback.Run(base::PLATFORM_FILE_OK); | 72 callback.Run(base::PLATFORM_FILE_OK); |
| 73 } | 73 } |
| 74 | 74 |
| 75 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( | 75 base::FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 76 const fileapi::FileSystemURL& url, | 76 const fileapi::FileSystemURL& url, |
| 77 bool create) { | 77 bool create) { |
| 78 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); | 78 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); |
| 79 if (!url.is_valid()) | 79 if (!url.is_valid()) |
| 80 return FilePath(); | 80 return base::FilePath(); |
| 81 | 81 |
| 82 FilePath root_path; | 82 base::FilePath root_path; |
| 83 std::string mount_name = url.filesystem_id(); | 83 std::string mount_name = url.filesystem_id(); |
| 84 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && | 84 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && |
| 85 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { | 85 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { |
| 86 return FilePath(); | 86 return base::FilePath(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 return root_path.DirName(); | 89 return root_path.DirName(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool CrosMountPointProvider::IsAccessAllowed( | 92 bool CrosMountPointProvider::IsAccessAllowed( |
| 93 const fileapi::FileSystemURL& url) { | 93 const fileapi::FileSystemURL& url) { |
| 94 if (!url.is_valid()) | 94 if (!url.is_valid()) |
| 95 return false; | 95 return false; |
| 96 | 96 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 std::string extension_id = origin_url.host(); | 109 std::string extension_id = origin_url.host(); |
| 110 // Check first to make sure this extension has fileBrowserHander permissions. | 110 // Check first to make sure this extension has fileBrowserHander permissions. |
| 111 if (!special_storage_policy_->IsFileHandler(extension_id)) | 111 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 return file_access_permissions_->HasAccessPermission(extension_id, | 114 return file_access_permissions_->HasAccessPermission(extension_id, |
| 115 url.virtual_path()); | 115 url.virtual_path()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. | 118 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. |
| 119 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { | 119 bool CrosMountPointProvider::IsRestrictedFileName( |
| 120 const base::FilePath& path) const { |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 | 123 |
| 123 fileapi::FileSystemQuotaUtil* CrosMountPointProvider::GetQuotaUtil() { | 124 fileapi::FileSystemQuotaUtil* CrosMountPointProvider::GetQuotaUtil() { |
| 124 // No quota support. | 125 // No quota support. |
| 125 return NULL; | 126 return NULL; |
| 126 } | 127 } |
| 127 | 128 |
| 128 void CrosMountPointProvider::DeleteFileSystem( | 129 void CrosMountPointProvider::DeleteFileSystem( |
| 129 const GURL& origin_url, | 130 const GURL& origin_url, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 if (!special_storage_policy_->IsFileHandler(extension_id)) | 141 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 141 return; | 142 return; |
| 142 | 143 |
| 143 std::vector<fileapi::MountPoints::MountPointInfo> files; | 144 std::vector<fileapi::MountPoints::MountPointInfo> files; |
| 144 mount_points_->AddMountPointInfosTo(&files); | 145 mount_points_->AddMountPointInfosTo(&files); |
| 145 system_mount_points_->AddMountPointInfosTo(&files); | 146 system_mount_points_->AddMountPointInfosTo(&files); |
| 146 | 147 |
| 147 for (size_t i = 0; i < files.size(); ++i) { | 148 for (size_t i = 0; i < files.size(); ++i) { |
| 148 file_access_permissions_->GrantAccessPermission( | 149 file_access_permissions_->GrantAccessPermission( |
| 149 extension_id, | 150 extension_id, |
| 150 FilePath::FromUTF8Unsafe(files[i].name)); | 151 base::FilePath::FromUTF8Unsafe(files[i].name)); |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 | 154 |
| 154 void CrosMountPointProvider::GrantFileAccessToExtension( | 155 void CrosMountPointProvider::GrantFileAccessToExtension( |
| 155 const std::string& extension_id, const FilePath& virtual_path) { | 156 const std::string& extension_id, const base::FilePath& virtual_path) { |
| 156 // All we care about here is access from extensions for now. | 157 // All we care about here is access from extensions for now. |
| 157 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 158 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
| 158 if (!special_storage_policy_->IsFileHandler(extension_id)) | 159 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 159 return; | 160 return; |
| 160 | 161 |
| 161 std::string id; | 162 std::string id; |
| 162 fileapi::FileSystemType type; | 163 fileapi::FileSystemType type; |
| 163 FilePath path; | 164 base::FilePath path; |
| 164 if (!mount_points_->CrackVirtualPath(virtual_path, &id, &type, &path) && | 165 if (!mount_points_->CrackVirtualPath(virtual_path, &id, &type, &path) && |
| 165 !system_mount_points_->CrackVirtualPath(virtual_path, | 166 !system_mount_points_->CrackVirtualPath(virtual_path, |
| 166 &id, &type, &path)) { | 167 &id, &type, &path)) { |
| 167 return; | 168 return; |
| 168 } | 169 } |
| 169 | 170 |
| 170 if (type == fileapi::kFileSystemTypeRestrictedNativeLocal) { | 171 if (type == fileapi::kFileSystemTypeRestrictedNativeLocal) { |
| 171 LOG(ERROR) << "Can't grant access for restricted mount point"; | 172 LOG(ERROR) << "Can't grant access for restricted mount point"; |
| 172 return; | 173 return; |
| 173 } | 174 } |
| 174 | 175 |
| 175 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); | 176 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); |
| 176 } | 177 } |
| 177 | 178 |
| 178 void CrosMountPointProvider::RevokeAccessForExtension( | 179 void CrosMountPointProvider::RevokeAccessForExtension( |
| 179 const std::string& extension_id) { | 180 const std::string& extension_id) { |
| 180 file_access_permissions_->RevokePermissions(extension_id); | 181 file_access_permissions_->RevokePermissions(extension_id); |
| 181 } | 182 } |
| 182 | 183 |
| 183 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { | 184 std::vector<base::FilePath> CrosMountPointProvider::GetRootDirectories() const { |
| 184 std::vector<fileapi::MountPoints::MountPointInfo> mount_points; | 185 std::vector<fileapi::MountPoints::MountPointInfo> mount_points; |
| 185 mount_points_->AddMountPointInfosTo(&mount_points); | 186 mount_points_->AddMountPointInfosTo(&mount_points); |
| 186 system_mount_points_->AddMountPointInfosTo(&mount_points); | 187 system_mount_points_->AddMountPointInfosTo(&mount_points); |
| 187 | 188 |
| 188 std::vector<FilePath> root_dirs; | 189 std::vector<base::FilePath> root_dirs; |
| 189 for (size_t i = 0; i < mount_points.size(); ++i) | 190 for (size_t i = 0; i < mount_points.size(); ++i) |
| 190 root_dirs.push_back(mount_points[i].path); | 191 root_dirs.push_back(mount_points[i].path); |
| 191 return root_dirs; | 192 return root_dirs; |
| 192 } | 193 } |
| 193 | 194 |
| 194 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( | 195 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( |
| 195 fileapi::FileSystemType type) { | 196 fileapi::FileSystemType type) { |
| 196 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 197 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
| 197 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 198 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
| 198 return local_file_util_->sync_file_util(); | 199 return local_file_util_->sync_file_util(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); | 266 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); |
| 266 } | 267 } |
| 267 | 268 |
| 268 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 269 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
| 269 return NULL; | 270 return NULL; |
| 270 | 271 |
| 271 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 272 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 272 return new fileapi::LocalFileStreamWriter(url.path(), offset); | 273 return new fileapi::LocalFileStreamWriter(url.path(), offset); |
| 273 } | 274 } |
| 274 | 275 |
| 275 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, | 276 bool CrosMountPointProvider::GetVirtualPath(const base::FilePath& filesystem_pat
h, |
| 276 FilePath* virtual_path) { | 277 base::FilePath* virtual_path) { |
| 277 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 278 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 278 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 279 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
| 279 } | 280 } |
| 280 | 281 |
| 281 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( | 282 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( |
| 282 const std::string& mount_name) const { | 283 const std::string& mount_name) const { |
| 283 fileapi::RemoteFileSystemProxyInterface* proxy = | 284 fileapi::RemoteFileSystemProxyInterface* proxy = |
| 284 mount_points_->GetRemoteFileSystemProxy(mount_name); | 285 mount_points_->GetRemoteFileSystemProxy(mount_name); |
| 285 if (proxy) | 286 if (proxy) |
| 286 return proxy; | 287 return proxy; |
| 287 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); | 288 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); |
| 288 } | 289 } |
| 289 | 290 |
| 290 } // namespace chromeos | 291 } // namespace chromeos |
| OLD | NEW |