Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 namespace chromeos { | 38 namespace chromeos { |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { | 41 bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { |
| 42 if (!url.is_valid()) | 42 if (!url.is_valid()) |
| 43 return false; | 43 return false; |
| 44 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 44 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 45 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | |
| 45 url.type() == fileapi::kFileSystemTypeDrive; | 46 url.type() == fileapi::kFileSystemTypeDrive; |
| 46 } | 47 } |
| 47 | 48 |
| 48 CrosMountPointProvider::CrosMountPointProvider( | 49 CrosMountPointProvider::CrosMountPointProvider( |
| 49 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) | 50 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) |
| 50 : special_storage_policy_(special_storage_policy), | 51 : special_storage_policy_(special_storage_policy), |
| 51 file_access_permissions_(new FileAccessPermissions()), | 52 file_access_permissions_(new FileAccessPermissions()), |
| 52 local_file_util_(new fileapi::IsolatedFileUtil()) { | 53 local_file_util_(new fileapi::IsolatedFileUtil()) { |
| 53 FilePath home_path; | 54 FilePath home_path; |
| 54 if (PathService::Get(base::DIR_HOME, &home_path)) | 55 if (PathService::Get(base::DIR_HOME, &home_path)) |
| 55 AddLocalMountPoint(home_path.AppendASCII("Downloads")); | 56 AddLocalMountPoint(home_path.AppendASCII("Downloads")); |
| 56 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); | 57 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); |
| 57 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); | 58 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); |
| 59 AddRestrictedLocalMountPoint(FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); | |
| 58 } | 60 } |
| 59 | 61 |
| 60 CrosMountPointProvider::~CrosMountPointProvider() { | 62 CrosMountPointProvider::~CrosMountPointProvider() { |
| 61 } | 63 } |
| 62 | 64 |
| 63 void CrosMountPointProvider::ValidateFileSystemRoot( | 65 void CrosMountPointProvider::ValidateFileSystemRoot( |
| 64 const GURL& origin_url, | 66 const GURL& origin_url, |
| 65 fileapi::FileSystemType type, | 67 fileapi::FileSystemType type, |
| 66 bool create, | 68 bool create, |
| 67 const ValidateFileSystemCallback& callback) { | 69 const ValidateFileSystemCallback& callback) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 142 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
| 141 isolated_context()->RevokeFileSystem(mount_name); | 143 isolated_context()->RevokeFileSystem(mount_name); |
| 142 isolated_context()->RegisterExternalFileSystem( | 144 isolated_context()->RegisterExternalFileSystem( |
| 143 mount_name, | 145 mount_name, |
| 144 fileapi::kFileSystemTypeNativeLocal, | 146 fileapi::kFileSystemTypeNativeLocal, |
| 145 mount_point); | 147 mount_point); |
| 146 base::AutoLock locker(mount_point_map_lock_); | 148 base::AutoLock locker(mount_point_map_lock_); |
| 147 local_to_virtual_map_[mount_point] = mount_point.BaseName(); | 149 local_to_virtual_map_[mount_point] = mount_point.BaseName(); |
| 148 } | 150 } |
| 149 | 151 |
| 152 void CrosMountPointProvider::AddRestrictedLocalMountPoint( | |
| 153 const FilePath& mount_point) { | |
| 154 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | |
| 155 isolated_context()->RevokeFileSystem(mount_name); | |
| 156 isolated_context()->RegisterExternalFileSystem( | |
| 157 mount_name, | |
| 158 fileapi::kFileSystemTypeRestrictedNativeLocal, | |
| 159 mount_point); | |
| 160 base::AutoLock locker(mount_point_map_lock_); | |
| 161 local_to_virtual_map_[mount_point] = mount_point.BaseName(); | |
| 162 } | |
| 163 | |
| 150 void CrosMountPointProvider::AddRemoteMountPoint( | 164 void CrosMountPointProvider::AddRemoteMountPoint( |
| 151 const FilePath& mount_point, | 165 const FilePath& mount_point, |
| 152 fileapi::RemoteFileSystemProxyInterface* remote_proxy) { | 166 fileapi::RemoteFileSystemProxyInterface* remote_proxy) { |
| 153 DCHECK(remote_proxy); | 167 DCHECK(remote_proxy); |
| 154 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 168 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
| 155 isolated_context()->RevokeFileSystem(mount_name); | 169 isolated_context()->RevokeFileSystem(mount_name); |
| 156 isolated_context()->RegisterExternalFileSystem(mount_name, | 170 isolated_context()->RegisterExternalFileSystem(mount_name, |
| 157 fileapi::kFileSystemTypeDrive, | 171 fileapi::kFileSystemTypeDrive, |
| 158 mount_point); | 172 mount_point); |
| 159 base::AutoLock locker(mount_point_map_lock_); | 173 base::AutoLock locker(mount_point_map_lock_); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 170 } | 184 } |
| 171 | 185 |
| 172 void CrosMountPointProvider::GrantFullAccessToExtension( | 186 void CrosMountPointProvider::GrantFullAccessToExtension( |
| 173 const std::string& extension_id) { | 187 const std::string& extension_id) { |
| 174 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 188 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
| 175 if (!special_storage_policy_->IsFileHandler(extension_id)) | 189 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 176 return; | 190 return; |
| 177 std::vector<fileapi::IsolatedContext::FileInfo> files = | 191 std::vector<fileapi::IsolatedContext::FileInfo> files = |
| 178 isolated_context()->GetExternalMountPoints(); | 192 isolated_context()->GetExternalMountPoints(); |
| 179 for (size_t i = 0; i < files.size(); ++i) { | 193 for (size_t i = 0; i < files.size(); ++i) { |
| 180 GrantFileAccessToExtension(extension_id, | 194 file_access_permissions_->GrantAccessPermission( |
|
kinuko
2012/10/03 02:38:04
Do we also need to avoid calling this for the moun
tbarzic
2012/10/03 02:47:32
no, if we don't call this here we won't be able to
| |
| 181 FilePath::FromUTF8Unsafe(files[i].name)); | 195 extension_id, |
| 196 FilePath::FromUTF8Unsafe(files[i].name)); | |
| 182 } | 197 } |
| 183 } | 198 } |
| 184 | 199 |
| 185 void CrosMountPointProvider::GrantFileAccessToExtension( | 200 void CrosMountPointProvider::GrantFileAccessToExtension( |
| 186 const std::string& extension_id, const FilePath& virtual_path) { | 201 const std::string& extension_id, const FilePath& virtual_path) { |
| 187 // All we care about here is access from extensions for now. | 202 // All we care about here is access from extensions for now. |
| 188 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 203 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
| 189 if (!special_storage_policy_->IsFileHandler(extension_id)) | 204 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 190 return; | 205 return; |
| 206 | |
| 207 std::string id; | |
| 208 fileapi::FileSystemType type; | |
| 209 FilePath path; | |
| 210 isolated_context()->CrackIsolatedPath(virtual_path, &id, &type, &path); | |
| 211 | |
| 212 if (type == fileapi::kFileSystemTypeRestrictedNativeLocal) { | |
| 213 LOG(ERROR) << "Can't grant access for restricted mount point"; | |
| 214 return; | |
| 215 } | |
| 216 | |
| 191 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); | 217 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); |
| 192 } | 218 } |
| 193 | 219 |
| 194 void CrosMountPointProvider::RevokeAccessForExtension( | 220 void CrosMountPointProvider::RevokeAccessForExtension( |
| 195 const std::string& extension_id) { | 221 const std::string& extension_id) { |
| 196 file_access_permissions_->RevokePermissions(extension_id); | 222 file_access_permissions_->RevokePermissions(extension_id); |
| 197 } | 223 } |
| 198 | 224 |
| 199 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { | 225 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { |
| 200 std::vector<fileapi::IsolatedContext::FileInfo> files = | 226 std::vector<fileapi::IsolatedContext::FileInfo> files = |
| 201 isolated_context()->GetExternalMountPoints(); | 227 isolated_context()->GetExternalMountPoints(); |
| 202 std::vector<FilePath> root_dirs; | 228 std::vector<FilePath> root_dirs; |
| 203 for (size_t i = 0; i < files.size(); ++i) | 229 for (size_t i = 0; i < files.size(); ++i) |
| 204 root_dirs.push_back(files[i].path); | 230 root_dirs.push_back(files[i].path); |
| 205 return root_dirs; | 231 return root_dirs; |
| 206 } | 232 } |
| 207 | 233 |
| 208 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( | 234 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( |
| 209 fileapi::FileSystemType type) { | 235 fileapi::FileSystemType type) { |
| 210 DCHECK(type == fileapi::kFileSystemTypeNativeLocal); | 236 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
| 237 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | |
| 211 return local_file_util_.get(); | 238 return local_file_util_.get(); |
| 212 } | 239 } |
| 213 | 240 |
| 214 FilePath CrosMountPointProvider::GetPathForPermissionsCheck( | 241 FilePath CrosMountPointProvider::GetPathForPermissionsCheck( |
| 215 const FilePath& virtual_path) const { | 242 const FilePath& virtual_path) const { |
| 216 return virtual_path; | 243 return virtual_path; |
| 217 } | 244 } |
| 218 | 245 |
| 219 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( | 246 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( |
| 220 const fileapi::FileSystemURL& url, | 247 const fileapi::FileSystemURL& url, |
| 221 fileapi::FileSystemContext* context, | 248 fileapi::FileSystemContext* context, |
| 222 base::PlatformFileError* error_code) const { | 249 base::PlatformFileError* error_code) const { |
| 223 if (url.type() == fileapi::kFileSystemTypeDrive) { | 250 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 224 base::AutoLock locker(mount_point_map_lock_); | 251 base::AutoLock locker(mount_point_map_lock_); |
| 225 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( | 252 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( |
| 226 url.filesystem_id()); | 253 url.filesystem_id()); |
| 227 if (found != remote_proxy_map_.end()) { | 254 if (found != remote_proxy_map_.end()) { |
| 228 return new chromeos::RemoteFileSystemOperation(found->second); | 255 return new chromeos::RemoteFileSystemOperation(found->second); |
| 229 } else { | 256 } else { |
| 230 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 257 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 231 return NULL; | 258 return NULL; |
| 232 } | 259 } |
| 233 } | 260 } |
| 234 | 261 |
| 235 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 262 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 263 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); | |
| 236 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 264 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| 237 new fileapi::FileSystemOperationContext(context)); | 265 new fileapi::FileSystemOperationContext(context)); |
| 238 return new fileapi::LocalFileSystemOperation(context, | 266 return new fileapi::LocalFileSystemOperation(context, |
| 239 operation_context.Pass()); | 267 operation_context.Pass()); |
| 240 } | 268 } |
| 241 | 269 |
| 242 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( | 270 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( |
| 243 const fileapi::FileSystemURL& url, | 271 const fileapi::FileSystemURL& url, |
| 244 int64 offset, | 272 int64 offset, |
| 245 fileapi::FileSystemContext* context) const { | 273 fileapi::FileSystemContext* context) const { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 257 return NULL; | 285 return NULL; |
| 258 if (url.type() == fileapi::kFileSystemTypeDrive) { | 286 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 259 base::AutoLock locker(mount_point_map_lock_); | 287 base::AutoLock locker(mount_point_map_lock_); |
| 260 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( | 288 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( |
| 261 url.filesystem_id()); | 289 url.filesystem_id()); |
| 262 if (found == remote_proxy_map_.end()) | 290 if (found == remote_proxy_map_.end()) |
| 263 return NULL; | 291 return NULL; |
| 264 return new fileapi::RemoteFileStreamWriter(found->second, url, offset); | 292 return new fileapi::RemoteFileStreamWriter(found->second, url, offset); |
| 265 } | 293 } |
| 266 | 294 |
| 295 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | |
| 296 return NULL; | |
| 297 | |
| 267 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 298 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 268 return new fileapi::LocalFileStreamWriter(url.path(), offset); | 299 return new fileapi::LocalFileStreamWriter(url.path(), offset); |
| 269 } | 300 } |
| 270 | 301 |
| 271 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, | 302 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, |
| 272 FilePath* virtual_path) { | 303 FilePath* virtual_path) { |
| 273 base::AutoLock locker(mount_point_map_lock_); | 304 base::AutoLock locker(mount_point_map_lock_); |
| 274 std::map<FilePath, FilePath>::reverse_iterator iter( | 305 std::map<FilePath, FilePath>::reverse_iterator iter( |
| 275 local_to_virtual_map_.upper_bound(filesystem_path)); | 306 local_to_virtual_map_.upper_bound(filesystem_path)); |
| 276 if (iter == local_to_virtual_map_.rend()) | 307 if (iter == local_to_virtual_map_.rend()) |
| 277 return false; | 308 return false; |
| 278 if (iter->first == filesystem_path) { | 309 if (iter->first == filesystem_path) { |
| 279 *virtual_path = iter->second; | 310 *virtual_path = iter->second; |
| 280 return true; | 311 return true; |
| 281 } | 312 } |
| 282 return iter->first.DirName().AppendRelativePath( | 313 return iter->first.DirName().AppendRelativePath( |
| 283 filesystem_path, virtual_path); | 314 filesystem_path, virtual_path); |
| 284 } | 315 } |
| 285 | 316 |
| 286 fileapi::IsolatedContext* CrosMountPointProvider::isolated_context() const { | 317 fileapi::IsolatedContext* CrosMountPointProvider::isolated_context() const { |
| 287 return fileapi::IsolatedContext::GetInstance(); | 318 return fileapi::IsolatedContext::GetInstance(); |
| 288 } | 319 } |
| 289 | 320 |
| 290 } // namespace chromeos | 321 } // namespace chromeos |
| OLD | NEW |