| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 19 #include "webkit/chromeos/fileapi/file_access_permissions.h" | 19 #include "webkit/chromeos/fileapi/file_access_permissions.h" |
| 20 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" | 20 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" |
| 21 #include "webkit/chromeos/fileapi/remote_file_system_operation.h" | 21 #include "webkit/chromeos/fileapi/remote_file_system_operation.h" |
| 22 #include "webkit/fileapi/file_system_file_stream_reader.h" | 22 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 23 #include "webkit/fileapi/file_system_operation_context.h" | 23 #include "webkit/fileapi/file_system_operation_context.h" |
| 24 #include "webkit/fileapi/file_system_url.h" | 24 #include "webkit/fileapi/file_system_url.h" |
| 25 #include "webkit/fileapi/file_system_util.h" | 25 #include "webkit/fileapi/file_system_util.h" |
| 26 #include "webkit/fileapi/isolated_context.h" |
| 27 #include "webkit/fileapi/isolated_file_util.h" |
| 26 #include "webkit/fileapi/local_file_stream_writer.h" | 28 #include "webkit/fileapi/local_file_stream_writer.h" |
| 27 #include "webkit/fileapi/local_file_system_operation.h" | 29 #include "webkit/fileapi/local_file_system_operation.h" |
| 28 #include "webkit/glue/webkit_glue.h" | 30 #include "webkit/glue/webkit_glue.h" |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 const char kChromeUIScheme[] = "chrome"; | 34 const char kChromeUIScheme[] = "chrome"; |
| 33 | 35 |
| 34 } // namespace | 36 } // namespace |
| 35 | 37 |
| 36 namespace chromeos { | 38 namespace chromeos { |
| 37 | 39 |
| 38 CrosMountPointProvider::MountPoint::MountPoint( | 40 // static |
| 39 const FilePath& in_web_root_path, | 41 bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { |
| 40 const FilePath& in_local_root_path, | 42 if (!url.is_valid()) { |
| 41 FileSystemLocation in_location, | 43 NOTREACHED(); |
| 42 fileapi::RemoteFileSystemProxyInterface* in_proxy) | 44 return false; |
| 43 : web_root_path(in_web_root_path), local_root_path(in_local_root_path), | 45 } |
| 44 location(in_location), remote_proxy(in_proxy) { | 46 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 45 } | 47 url.type() == fileapi::kFileSystemTypeDrive; |
| 46 | |
| 47 CrosMountPointProvider::MountPoint::~MountPoint() { | |
| 48 } | 48 } |
| 49 | 49 |
| 50 CrosMountPointProvider::CrosMountPointProvider( | 50 CrosMountPointProvider::CrosMountPointProvider( |
| 51 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) | 51 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) |
| 52 : special_storage_policy_(special_storage_policy), | 52 : special_storage_policy_(special_storage_policy), |
| 53 file_access_permissions_(new FileAccessPermissions()), | 53 file_access_permissions_(new FileAccessPermissions()), |
| 54 local_file_util_(new fileapi::LocalFileUtil()) { | 54 local_file_util_(new fileapi::IsolatedFileUtil()) { |
| 55 FilePath home_path; | 55 FilePath home_path; |
| 56 if (PathService::Get(base::DIR_HOME, &home_path)) | 56 if (PathService::Get(base::DIR_HOME, &home_path)) |
| 57 AddLocalMountPoint(home_path.AppendASCII("Downloads")); | 57 AddLocalMountPoint(home_path.AppendASCII("Downloads")); |
| 58 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); | 58 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); |
| 59 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); | 59 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); |
| 60 } | 60 } |
| 61 | 61 |
| 62 CrosMountPointProvider::~CrosMountPointProvider() { | 62 CrosMountPointProvider::~CrosMountPointProvider() { |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool CrosMountPointProvider::GetRootForVirtualPath( | |
| 66 const FilePath& virtual_path, FilePath* root_path) { | |
| 67 const MountPoint* mount_point = GetMountPoint(virtual_path); | |
| 68 if (!mount_point) | |
| 69 return false; | |
| 70 | |
| 71 DCHECK(root_path); | |
| 72 *root_path = mount_point->local_root_path; | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 void CrosMountPointProvider::ValidateFileSystemRoot( | 65 void CrosMountPointProvider::ValidateFileSystemRoot( |
| 77 const GURL& origin_url, | 66 const GURL& origin_url, |
| 78 fileapi::FileSystemType type, | 67 fileapi::FileSystemType type, |
| 79 bool create, | 68 bool create, |
| 80 const ValidateFileSystemCallback& callback) { | 69 const ValidateFileSystemCallback& callback) { |
| 81 // Nothing to validate for external filesystem. | 70 // Nothing to validate for external filesystem. |
| 82 DCHECK(type == fileapi::kFileSystemTypeExternal); | 71 DCHECK(type == fileapi::kFileSystemTypeExternal); |
| 83 callback.Run(base::PLATFORM_FILE_OK); | 72 callback.Run(base::PLATFORM_FILE_OK); |
| 84 } | 73 } |
| 85 | 74 |
| 86 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( | 75 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 87 const GURL& origin_url, | 76 const GURL& origin_url, |
| 88 fileapi::FileSystemType type, | 77 fileapi::FileSystemType type, |
| 89 const FilePath& virtual_path, | 78 const FilePath& virtual_path, |
| 90 bool create) { | 79 bool create) { |
| 91 DCHECK(type == fileapi::kFileSystemTypeExternal); | 80 DCHECK(type == fileapi::kFileSystemTypeExternal); |
| 92 FilePath root_path; | 81 fileapi::FileSystemURL url(origin_url, type, virtual_path); |
| 93 if (!GetRootForVirtualPath(virtual_path, &root_path)) | 82 if (!url.is_valid()) |
| 94 return FilePath(); | 83 return FilePath(); |
| 95 | 84 |
| 96 return root_path; | 85 FilePath root_path; |
| 86 if (!isolated_context()->GetRegisteredPath(url.filesystem_id(), &root_path)) |
| 87 return FilePath(); |
| 88 |
| 89 return root_path.DirName(); |
| 97 } | 90 } |
| 98 | 91 |
| 99 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, | 92 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
| 100 fileapi::FileSystemType type, | 93 fileapi::FileSystemType type, |
| 101 const FilePath& virtual_path) { | 94 const FilePath& virtual_path) { |
| 102 if (type != fileapi::kFileSystemTypeExternal) | 95 // TODO(kinuko): this should call CanHandleURL() once |
| 96 // http://crbug.com/142267 is fixed. |
| 97 if (type != fileapi::kFileSystemTypeNativeLocal && |
| 98 type != fileapi::kFileSystemTypeDrive) |
| 103 return false; | 99 return false; |
| 104 | 100 |
| 105 // Permit access to mount points from internal WebUI. | 101 // Permit access to mount points from internal WebUI. |
| 106 if (origin_url.SchemeIs(kChromeUIScheme)) | 102 if (origin_url.SchemeIs(kChromeUIScheme)) |
| 107 return true; | 103 return true; |
| 108 | 104 |
| 109 std::string extension_id = origin_url.host(); | 105 std::string extension_id = origin_url.host(); |
| 110 // Check first to make sure this extension has fileBrowserHander permissions. | 106 // Check first to make sure this extension has fileBrowserHander permissions. |
| 111 if (!special_storage_policy_->IsFileHandler(extension_id)) | 107 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 112 return false; | 108 return false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 void CrosMountPointProvider::DeleteFileSystem( | 124 void CrosMountPointProvider::DeleteFileSystem( |
| 129 const GURL& origin_url, | 125 const GURL& origin_url, |
| 130 fileapi::FileSystemType type, | 126 fileapi::FileSystemType type, |
| 131 fileapi::FileSystemContext* context, | 127 fileapi::FileSystemContext* context, |
| 132 const DeleteFileSystemCallback& callback) { | 128 const DeleteFileSystemCallback& callback) { |
| 133 NOTREACHED(); | 129 NOTREACHED(); |
| 134 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 130 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 135 } | 131 } |
| 136 | 132 |
| 137 bool CrosMountPointProvider::HasMountPoint(const FilePath& mount_point) { | 133 bool CrosMountPointProvider::HasMountPoint(const FilePath& mount_point) { |
| 138 base::AutoLock locker(mount_point_map_lock_); | 134 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
| 139 MountPointMap::const_iterator iter = mount_point_map_.find( | 135 FilePath path; |
| 140 mount_point.BaseName().value()); | 136 const bool valid = isolated_context()->GetRegisteredPath(mount_name, &path); |
| 141 DCHECK(iter == mount_point_map_.end() || | 137 return valid && path == mount_point; |
| 142 iter->second.local_root_path == mount_point.DirName()); | |
| 143 return iter != mount_point_map_.end(); | |
| 144 } | 138 } |
| 145 | 139 |
| 146 void CrosMountPointProvider::AddLocalMountPoint(const FilePath& mount_point) { | 140 void CrosMountPointProvider::AddLocalMountPoint(const FilePath& mount_point) { |
| 141 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
| 142 isolated_context()->RevokeFileSystem(mount_name); |
| 143 isolated_context()->RegisterExternalFileSystem( |
| 144 mount_name, |
| 145 fileapi::kFileSystemTypeNativeLocal, |
| 146 mount_point); |
| 147 base::AutoLock locker(mount_point_map_lock_); | 147 base::AutoLock locker(mount_point_map_lock_); |
| 148 mount_point_map_.erase(mount_point.BaseName().value()); | 148 local_to_virtual_map_[mount_point] = mount_point.BaseName(); |
| 149 mount_point_map_.insert(std::make_pair( | |
| 150 mount_point.BaseName().value(), | |
| 151 MountPoint(mount_point.BaseName(), | |
| 152 mount_point.DirName(), | |
| 153 LOCAL, | |
| 154 NULL))); | |
| 155 } | 149 } |
| 156 | 150 |
| 157 void CrosMountPointProvider::AddRemoteMountPoint( | 151 void CrosMountPointProvider::AddRemoteMountPoint( |
| 158 const FilePath& mount_point, | 152 const FilePath& mount_point, |
| 159 fileapi::RemoteFileSystemProxyInterface* remote_proxy) { | 153 fileapi::RemoteFileSystemProxyInterface* remote_proxy) { |
| 160 DCHECK(remote_proxy); | 154 DCHECK(remote_proxy); |
| 155 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
| 156 isolated_context()->RevokeFileSystem(mount_name); |
| 157 isolated_context()->RegisterExternalFileSystem(mount_name, |
| 158 fileapi::kFileSystemTypeDrive, |
| 159 mount_point); |
| 161 base::AutoLock locker(mount_point_map_lock_); | 160 base::AutoLock locker(mount_point_map_lock_); |
| 162 mount_point_map_.erase(mount_point.BaseName().value()); | 161 remote_proxy_map_[mount_name] = remote_proxy; |
| 163 mount_point_map_.insert(std::make_pair( | 162 local_to_virtual_map_[mount_point] = mount_point.BaseName(); |
| 164 mount_point.BaseName().value(), | |
| 165 MountPoint(mount_point.BaseName(), | |
| 166 mount_point.DirName(), | |
| 167 REMOTE, | |
| 168 remote_proxy))); | |
| 169 } | 163 } |
| 170 | 164 |
| 171 void CrosMountPointProvider::RemoveMountPoint(const FilePath& mount_point) { | 165 void CrosMountPointProvider::RemoveMountPoint(const FilePath& mount_point) { |
| 166 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
| 167 isolated_context()->RevokeFileSystem(mount_name); |
| 172 base::AutoLock locker(mount_point_map_lock_); | 168 base::AutoLock locker(mount_point_map_lock_); |
| 173 mount_point_map_.erase(mount_point.BaseName().value()); | 169 remote_proxy_map_.erase(mount_name); |
| 170 local_to_virtual_map_.erase(mount_point); |
| 174 } | 171 } |
| 175 | 172 |
| 176 void CrosMountPointProvider::GrantFullAccessToExtension( | 173 void CrosMountPointProvider::GrantFullAccessToExtension( |
| 177 const std::string& extension_id) { | 174 const std::string& extension_id) { |
| 178 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 175 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
| 179 if (!special_storage_policy_->IsFileHandler(extension_id)) | 176 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 180 return; | 177 return; |
| 181 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); | 178 std::vector<fileapi::IsolatedContext::FileInfo> files = |
| 182 iter != mount_point_map_.end(); | 179 isolated_context()->GetExternalMountPoints(); |
| 183 ++iter) { | 180 for (size_t i = 0; i < files.size(); ++i) { |
| 184 GrantFileAccessToExtension(extension_id, FilePath(iter->first)); | 181 GrantFileAccessToExtension(extension_id, |
| 182 FilePath::FromUTF8Unsafe(files[i].name)); |
| 185 } | 183 } |
| 186 } | 184 } |
| 187 | 185 |
| 188 void CrosMountPointProvider::GrantFileAccessToExtension( | 186 void CrosMountPointProvider::GrantFileAccessToExtension( |
| 189 const std::string& extension_id, const FilePath& virtual_path) { | 187 const std::string& extension_id, const FilePath& virtual_path) { |
| 190 // All we care about here is access from extensions for now. | 188 // All we care about here is access from extensions for now. |
| 191 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 189 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
| 192 if (!special_storage_policy_->IsFileHandler(extension_id)) | 190 if (!special_storage_policy_->IsFileHandler(extension_id)) |
| 193 return; | 191 return; |
| 194 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); | 192 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); |
| 195 } | 193 } |
| 196 | 194 |
| 197 void CrosMountPointProvider::RevokeAccessForExtension( | 195 void CrosMountPointProvider::RevokeAccessForExtension( |
| 198 const std::string& extension_id) { | 196 const std::string& extension_id) { |
| 199 file_access_permissions_->RevokePermissions(extension_id); | 197 file_access_permissions_->RevokePermissions(extension_id); |
| 200 } | 198 } |
| 201 | 199 |
| 202 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { | 200 std::vector<fileapi::ExternalFileSystemMountPointProvider::MountInfo> |
| 203 std::vector<FilePath> root_dirs; | 201 CrosMountPointProvider::GetMountPoints() const { |
| 204 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); | 202 std::vector<fileapi::IsolatedContext::FileInfo> files = |
| 205 iter != mount_point_map_.end(); | 203 isolated_context()->GetExternalMountPoints(); |
| 206 ++iter) { | 204 std::vector<MountInfo> mount_points; |
| 207 root_dirs.push_back(iter->second.local_root_path.Append(iter->first)); | 205 for (size_t i = 0; i < files.size(); ++i) { |
| 206 MountInfo mount_point; |
| 207 mount_point.mount_name = files[i].name; |
| 208 mount_point.root_path = files[i].path; |
| 209 mount_points.push_back(mount_point); |
| 208 } | 210 } |
| 209 return root_dirs; | 211 return mount_points; |
| 210 } | 212 } |
| 211 | 213 |
| 212 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( | 214 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( |
| 213 fileapi::FileSystemType type) { | 215 fileapi::FileSystemType type) { |
| 216 DCHECK(type == fileapi::kFileSystemTypeNativeLocal); |
| 214 return local_file_util_.get(); | 217 return local_file_util_.get(); |
| 215 } | 218 } |
| 216 | 219 |
| 217 FilePath CrosMountPointProvider::GetPathForPermissionsCheck( | 220 FilePath CrosMountPointProvider::GetPathForPermissionsCheck( |
| 218 const FilePath& virtual_path) const { | 221 const FilePath& virtual_path) const { |
| 219 const MountPoint* mount_point = GetMountPoint(virtual_path); | 222 return virtual_path; |
| 220 if (!mount_point) | |
| 221 return FilePath(); | |
| 222 | |
| 223 FilePath root_path = mount_point->local_root_path; | |
| 224 | |
| 225 return root_path.Append(virtual_path); | |
| 226 } | |
| 227 | |
| 228 const CrosMountPointProvider::MountPoint* | |
| 229 CrosMountPointProvider::GetMountPoint(const FilePath& virtual_path) const { | |
| 230 std::vector<FilePath::StringType> components; | |
| 231 virtual_path.GetComponents(&components); | |
| 232 if (components.empty()) | |
| 233 return NULL; | |
| 234 | |
| 235 base::AutoLock locker( | |
| 236 const_cast<CrosMountPointProvider*>(this)->mount_point_map_lock_); | |
| 237 // Check if this root mount point is exposed by this provider. | |
| 238 MountPointMap::const_iterator iter = mount_point_map_.find(components[0]); | |
| 239 if (iter == mount_point_map_.end()) | |
| 240 return NULL; | |
| 241 | |
| 242 return &(iter->second); | |
| 243 } | 223 } |
| 244 | 224 |
| 245 fileapi::FileSystemOperationInterface* | 225 fileapi::FileSystemOperationInterface* |
| 246 CrosMountPointProvider::CreateFileSystemOperation( | 226 CrosMountPointProvider::CreateFileSystemOperation( |
| 247 const fileapi::FileSystemURL& url, | 227 const fileapi::FileSystemURL& url, |
| 248 fileapi::FileSystemContext* context) const { | 228 fileapi::FileSystemContext* context) const { |
| 249 const MountPoint* mount_point = GetMountPoint(url.path()); | 229 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 250 if (mount_point && mount_point->location == REMOTE) | 230 base::AutoLock locker(mount_point_map_lock_); |
| 251 return new chromeos::RemoteFileSystemOperation(mount_point->remote_proxy); | 231 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( |
| 232 url.filesystem_id()); |
| 233 // TODO(kinuko): we should handle not-found case gracefully. |
| 234 // http://crbug.com/141617 |
| 235 if (found != remote_proxy_map_.end()) { |
| 236 return new chromeos::RemoteFileSystemOperation(found->second); |
| 237 } |
| 238 } |
| 252 | 239 |
| 240 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 253 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 241 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| 254 new fileapi::FileSystemOperationContext(context)); | 242 new fileapi::FileSystemOperationContext(context)); |
| 255 return new fileapi::LocalFileSystemOperation(context, | 243 return new fileapi::LocalFileSystemOperation(context, |
| 256 operation_context.Pass()); | 244 operation_context.Pass()); |
| 257 } | 245 } |
| 258 | 246 |
| 259 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( | 247 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( |
| 260 const fileapi::FileSystemURL& url, | 248 const fileapi::FileSystemURL& url, |
| 261 int64 offset, | 249 int64 offset, |
| 262 fileapi::FileSystemContext* context) const { | 250 fileapi::FileSystemContext* context) const { |
| 263 // For now we return a generic Reader implementation which utilizes | 251 // For now we return a generic Reader implementation which utilizes |
| 264 // CreateSnapshotFile internally (i.e. will download everything first). | 252 // CreateSnapshotFile internally (i.e. will download everything first). |
| 265 // TODO(satorux,zel): implement more efficient reader for remote cases. | 253 // TODO(satorux,zel): implement more efficient reader for remote cases. |
| 266 return new fileapi::FileSystemFileStreamReader(context, url, offset); | 254 return new fileapi::FileSystemFileStreamReader(context, url, offset); |
| 267 } | 255 } |
| 268 | 256 |
| 269 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( | 257 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( |
| 270 const fileapi::FileSystemURL& url, | 258 const fileapi::FileSystemURL& url, |
| 271 int64 offset, | 259 int64 offset, |
| 272 fileapi::FileSystemContext* context) const { | 260 fileapi::FileSystemContext* context) const { |
| 273 if (!url.is_valid()) | 261 if (!url.is_valid()) |
| 274 return NULL; | 262 return NULL; |
| 275 const MountPoint* mount_point = GetMountPoint(url.path()); | 263 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 276 if (!mount_point) | 264 base::AutoLock locker(mount_point_map_lock_); |
| 277 return NULL; | 265 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( |
| 278 if (mount_point->location == REMOTE) { | 266 url.filesystem_id()); |
| 279 return new fileapi::RemoteFileStreamWriter(mount_point->remote_proxy, | 267 if (found == remote_proxy_map_.end()) |
| 280 url, | 268 return NULL; |
| 281 offset); | 269 return new fileapi::RemoteFileStreamWriter(found->second, url, offset); |
| 282 } | 270 } |
| 283 FilePath root_path = mount_point->local_root_path; | 271 |
| 284 return new fileapi::LocalFileStreamWriter( | 272 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 285 root_path.Append(url.path()), offset); | 273 return new fileapi::LocalFileStreamWriter(url.path(), offset); |
| 286 } | 274 } |
| 287 | 275 |
| 288 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, | 276 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, |
| 289 FilePath* virtual_path) { | 277 FilePath* virtual_path) { |
| 290 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); | 278 base::AutoLock locker(mount_point_map_lock_); |
| 291 iter != mount_point_map_.end(); | 279 std::map<FilePath, FilePath>::reverse_iterator iter( |
| 292 ++iter) { | 280 local_to_virtual_map_.upper_bound(filesystem_path)); |
| 293 FilePath mount_prefix = iter->second.local_root_path.Append(iter->first); | 281 if (iter == local_to_virtual_map_.rend()) |
| 294 *virtual_path = FilePath(iter->first); | 282 return false; |
| 295 if (mount_prefix == filesystem_path) { | 283 if (iter->first == filesystem_path) { |
| 296 return true; | 284 *virtual_path = iter->second; |
| 297 } else if (mount_prefix.AppendRelativePath(filesystem_path, virtual_path)) { | 285 return true; |
| 298 return true; | |
| 299 } | |
| 300 } | 286 } |
| 301 return false; | 287 return iter->first.DirName().AppendRelativePath( |
| 288 filesystem_path, virtual_path); |
| 289 } |
| 290 |
| 291 fileapi::IsolatedContext* CrosMountPointProvider::isolated_context() const { |
| 292 return fileapi::IsolatedContext::GetInstance(); |
| 302 } | 293 } |
| 303 | 294 |
| 304 } // namespace chromeos | 295 } // namespace chromeos |
| OLD | NEW |