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