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" | |
12 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
13 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
14 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
19 #include "webkit/chromeos/fileapi/file_access_permissions.h" | 18 #include "webkit/chromeos/fileapi/file_access_permissions.h" |
20 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" | 19 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" |
21 #include "webkit/chromeos/fileapi/remote_file_system_operation.h" | 20 #include "webkit/chromeos/fileapi/remote_file_system_operation.h" |
| 21 #include "webkit/fileapi/external_mount_points.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" | 26 #include "webkit/fileapi/isolated_context.h" |
27 #include "webkit/fileapi/isolated_file_util.h" | 27 #include "webkit/fileapi/isolated_file_util.h" |
28 #include "webkit/fileapi/local_file_stream_writer.h" | 28 #include "webkit/fileapi/local_file_stream_writer.h" |
29 #include "webkit/fileapi/local_file_system_operation.h" | 29 #include "webkit/fileapi/local_file_system_operation.h" |
30 #include "webkit/glue/webkit_glue.h" | 30 #include "webkit/glue/webkit_glue.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kChromeUIScheme[] = "chrome"; | 34 const char kChromeUIScheme[] = "chrome"; |
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::kFileSystemTypeRestrictedNativeLocal || |
46 url.type() == fileapi::kFileSystemTypeDrive; | 46 url.type() == fileapi::kFileSystemTypeDrive; |
47 } | 47 } |
48 | 48 |
49 CrosMountPointProvider::CrosMountPointProvider( | 49 CrosMountPointProvider::CrosMountPointProvider( |
50 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) | 50 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 51 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
| 52 fileapi::ExternalMountPoints* system_mount_points) |
51 : special_storage_policy_(special_storage_policy), | 53 : special_storage_policy_(special_storage_policy), |
52 file_access_permissions_(new FileAccessPermissions()), | 54 file_access_permissions_(new FileAccessPermissions()), |
53 local_file_util_(new fileapi::IsolatedFileUtil()) { | 55 local_file_util_(new fileapi::IsolatedFileUtil()), |
54 FilePath home_path; | 56 mount_points_(mount_points), |
55 if (PathService::Get(base::DIR_HOME, &home_path)) | 57 system_mount_points_(system_mount_points) { |
56 AddLocalMountPoint(home_path.AppendASCII("Downloads")); | |
57 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive"))); | |
58 AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable"))); | |
59 AddRestrictedLocalMountPoint(FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); | |
60 } | 58 } |
61 | 59 |
62 CrosMountPointProvider::~CrosMountPointProvider() { | 60 CrosMountPointProvider::~CrosMountPointProvider() { |
63 } | 61 } |
64 | 62 |
65 void CrosMountPointProvider::ValidateFileSystemRoot( | 63 void CrosMountPointProvider::ValidateFileSystemRoot( |
66 const GURL& origin_url, | 64 const GURL& origin_url, |
67 fileapi::FileSystemType type, | 65 fileapi::FileSystemType type, |
68 bool create, | 66 bool create, |
69 const ValidateFileSystemCallback& callback) { | 67 const ValidateFileSystemCallback& callback) { |
70 DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); | 68 DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); |
71 // Nothing to validate for external filesystem. | 69 // Nothing to validate for external filesystem. |
72 callback.Run(base::PLATFORM_FILE_OK); | 70 callback.Run(base::PLATFORM_FILE_OK); |
73 } | 71 } |
74 | 72 |
75 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( | 73 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( |
76 const fileapi::FileSystemURL& url, | 74 const fileapi::FileSystemURL& url, |
77 bool create) { | 75 bool create) { |
78 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); | 76 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); |
79 if (!url.is_valid()) | 77 if (!url.is_valid()) |
80 return FilePath(); | 78 return FilePath(); |
81 | 79 |
82 FilePath root_path; | 80 FilePath root_path; |
83 if (!isolated_context()->GetRegisteredPath(url.filesystem_id(), &root_path)) | 81 std::string mount_name = url.filesystem_id(); |
| 82 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && |
| 83 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { |
84 return FilePath(); | 84 return FilePath(); |
| 85 } |
85 | 86 |
86 return root_path.DirName(); | 87 return root_path.DirName(); |
87 } | 88 } |
88 | 89 |
89 bool CrosMountPointProvider::IsAccessAllowed( | 90 bool CrosMountPointProvider::IsAccessAllowed( |
90 const fileapi::FileSystemURL& url) { | 91 const fileapi::FileSystemURL& url) { |
91 if (!CanHandleURL(url)) | 92 if (!CanHandleURL(url)) |
92 return false; | 93 return false; |
93 | 94 |
94 // No extra check is needed for isolated file systems. | 95 // No extra check is needed for isolated file systems. |
(...skipping 26 matching lines...) Expand all Loading... |
121 | 122 |
122 void CrosMountPointProvider::DeleteFileSystem( | 123 void CrosMountPointProvider::DeleteFileSystem( |
123 const GURL& origin_url, | 124 const GURL& origin_url, |
124 fileapi::FileSystemType type, | 125 fileapi::FileSystemType type, |
125 fileapi::FileSystemContext* context, | 126 fileapi::FileSystemContext* context, |
126 const DeleteFileSystemCallback& callback) { | 127 const DeleteFileSystemCallback& callback) { |
127 NOTREACHED(); | 128 NOTREACHED(); |
128 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 129 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
129 } | 130 } |
130 | 131 |
131 bool CrosMountPointProvider::HasMountPoint(const FilePath& mount_point) { | 132 bool CrosMountPointProvider::HasMountPoint(const FilePath& mount_point) const { |
132 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 133 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
133 FilePath path; | 134 FilePath path; |
134 const bool valid = isolated_context()->GetRegisteredPath(mount_name, &path); | 135 |
| 136 const bool valid = mount_points_->GetRegisteredPath(mount_name, &path); |
135 return valid && path == mount_point; | 137 return valid && path == mount_point; |
136 } | 138 } |
137 | 139 |
138 void CrosMountPointProvider::AddLocalMountPoint(const FilePath& mount_point) { | 140 bool CrosMountPointProvider::AddLocalMountPoint(const FilePath& mount_point) { |
139 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 141 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
140 isolated_context()->RevokeFileSystem(mount_name); | 142 return mount_points_->RegisterFileSystem( |
141 isolated_context()->RegisterExternalFileSystem( | 143 mount_name, |
142 mount_name, | 144 fileapi::kFileSystemTypeNativeLocal, |
143 fileapi::kFileSystemTypeNativeLocal, | 145 mount_point); |
144 mount_point); | |
145 base::AutoLock locker(mount_point_map_lock_); | |
146 local_to_virtual_map_[mount_point] = mount_point.BaseName(); | |
147 } | 146 } |
148 | 147 |
149 void CrosMountPointProvider::AddRestrictedLocalMountPoint( | 148 bool CrosMountPointProvider::AddRestrictedLocalMountPoint( |
150 const FilePath& mount_point) { | 149 const FilePath& mount_point) { |
151 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 150 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
152 isolated_context()->RevokeFileSystem(mount_name); | 151 return mount_points_->RegisterFileSystem( |
153 isolated_context()->RegisterExternalFileSystem( | 152 mount_name, |
154 mount_name, | 153 fileapi::kFileSystemTypeRestrictedNativeLocal, |
155 fileapi::kFileSystemTypeRestrictedNativeLocal, | 154 mount_point); |
156 mount_point); | |
157 base::AutoLock locker(mount_point_map_lock_); | |
158 local_to_virtual_map_[mount_point] = mount_point.BaseName(); | |
159 } | 155 } |
160 | 156 |
161 void CrosMountPointProvider::AddRemoteMountPoint( | 157 bool CrosMountPointProvider::AddRemoteMountPoint( |
162 const FilePath& mount_point, | 158 const FilePath& mount_point, |
163 fileapi::RemoteFileSystemProxyInterface* remote_proxy) { | 159 fileapi::RemoteFileSystemProxyInterface* remote_proxy) { |
164 DCHECK(remote_proxy); | 160 DCHECK(remote_proxy); |
165 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 161 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
166 isolated_context()->RevokeFileSystem(mount_name); | 162 return mount_points_->RegisterRemoteFileSystem(mount_name, |
167 isolated_context()->RegisterExternalFileSystem(mount_name, | |
168 fileapi::kFileSystemTypeDrive, | 163 fileapi::kFileSystemTypeDrive, |
| 164 remote_proxy, |
169 mount_point); | 165 mount_point); |
170 base::AutoLock locker(mount_point_map_lock_); | |
171 remote_proxy_map_[mount_name] = remote_proxy; | |
172 local_to_virtual_map_[mount_point] = mount_point.BaseName(); | |
173 } | 166 } |
174 | 167 |
175 void CrosMountPointProvider::RemoveMountPoint(const FilePath& mount_point) { | 168 void CrosMountPointProvider::RemoveMountPoint(const FilePath& mount_point) { |
| 169 if (!HasMountPoint(mount_point)) |
| 170 return; |
176 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); | 171 std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); |
177 isolated_context()->RevokeFileSystem(mount_name); | 172 mount_points_->RevokeFileSystem(mount_name); |
178 base::AutoLock locker(mount_point_map_lock_); | |
179 remote_proxy_map_.erase(mount_name); | |
180 local_to_virtual_map_.erase(mount_point); | |
181 } | 173 } |
182 | 174 |
183 void CrosMountPointProvider::GrantFullAccessToExtension( | 175 void CrosMountPointProvider::GrantFullAccessToExtension( |
184 const std::string& extension_id) { | 176 const std::string& extension_id) { |
185 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 177 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
186 if (!special_storage_policy_->IsFileHandler(extension_id)) | 178 if (!special_storage_policy_->IsFileHandler(extension_id)) |
187 return; | 179 return; |
188 std::vector<fileapi::IsolatedContext::FileInfo> files = | 180 |
189 isolated_context()->GetExternalMountPoints(); | 181 std::vector<fileapi::MountPoints::MountPointInfo> files; |
| 182 mount_points_->AddMountPointInfosTo(&files); |
| 183 system_mount_points_->AddMountPointInfosTo(&files); |
| 184 |
190 for (size_t i = 0; i < files.size(); ++i) { | 185 for (size_t i = 0; i < files.size(); ++i) { |
191 file_access_permissions_->GrantAccessPermission( | 186 file_access_permissions_->GrantAccessPermission( |
192 extension_id, | 187 extension_id, |
193 FilePath::FromUTF8Unsafe(files[i].name)); | 188 FilePath::FromUTF8Unsafe(files[i].name)); |
194 } | 189 } |
195 } | 190 } |
196 | 191 |
197 void CrosMountPointProvider::GrantFileAccessToExtension( | 192 void CrosMountPointProvider::GrantFileAccessToExtension( |
198 const std::string& extension_id, const FilePath& virtual_path) { | 193 const std::string& extension_id, const FilePath& virtual_path) { |
199 // All we care about here is access from extensions for now. | 194 // All we care about here is access from extensions for now. |
200 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); | 195 DCHECK(special_storage_policy_->IsFileHandler(extension_id)); |
201 if (!special_storage_policy_->IsFileHandler(extension_id)) | 196 if (!special_storage_policy_->IsFileHandler(extension_id)) |
202 return; | 197 return; |
203 | 198 |
204 std::string id; | 199 std::string id; |
205 fileapi::FileSystemType type; | 200 fileapi::FileSystemType type; |
206 FilePath path; | 201 FilePath path; |
207 isolated_context()->CrackIsolatedPath(virtual_path, &id, &type, &path); | 202 if (!mount_points_->CrackVirtualPath(virtual_path, &id, &type, &path) && |
| 203 !system_mount_points_->CrackVirtualPath(virtual_path, |
| 204 &id, &type, &path)) { |
| 205 return; |
| 206 } |
208 | 207 |
209 if (type == fileapi::kFileSystemTypeRestrictedNativeLocal) { | 208 if (type == fileapi::kFileSystemTypeRestrictedNativeLocal) { |
210 LOG(ERROR) << "Can't grant access for restricted mount point"; | 209 LOG(ERROR) << "Can't grant access for restricted mount point"; |
211 return; | 210 return; |
212 } | 211 } |
213 | 212 |
214 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); | 213 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); |
215 } | 214 } |
216 | 215 |
217 void CrosMountPointProvider::RevokeAccessForExtension( | 216 void CrosMountPointProvider::RevokeAccessForExtension( |
218 const std::string& extension_id) { | 217 const std::string& extension_id) { |
219 file_access_permissions_->RevokePermissions(extension_id); | 218 file_access_permissions_->RevokePermissions(extension_id); |
220 } | 219 } |
221 | 220 |
222 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { | 221 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { |
223 std::vector<fileapi::IsolatedContext::FileInfo> files = | 222 std::vector<fileapi::MountPoints::MountPointInfo> mount_points; |
224 isolated_context()->GetExternalMountPoints(); | 223 mount_points_->AddMountPointInfosTo(&mount_points); |
| 224 system_mount_points_->AddMountPointInfosTo(&mount_points); |
| 225 |
225 std::vector<FilePath> root_dirs; | 226 std::vector<FilePath> root_dirs; |
226 for (size_t i = 0; i < files.size(); ++i) | 227 for (size_t i = 0; i < mount_points.size(); ++i) |
227 root_dirs.push_back(files[i].path); | 228 root_dirs.push_back(mount_points[i].path); |
228 return root_dirs; | 229 return root_dirs; |
229 } | 230 } |
230 | 231 |
231 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( | 232 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( |
232 fileapi::FileSystemType type) { | 233 fileapi::FileSystemType type) { |
233 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 234 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
234 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 235 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
235 return local_file_util_.get(); | 236 return local_file_util_.get(); |
236 } | 237 } |
237 | 238 |
238 fileapi::FilePermissionPolicy CrosMountPointProvider::GetPermissionPolicy( | 239 fileapi::FilePermissionPolicy CrosMountPointProvider::GetPermissionPolicy( |
239 const fileapi::FileSystemURL& url, int permissions) const { | 240 const fileapi::FileSystemURL& url, int permissions) const { |
240 if (url.mount_type() == fileapi::kFileSystemTypeIsolated) { | 241 if (url.mount_type() == fileapi::kFileSystemTypeIsolated) { |
241 // Permissions in isolated filesystems should be examined with | 242 // Permissions in isolated filesystems should be examined with |
242 // FileSystem permission. | 243 // FileSystem permission. |
243 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; | 244 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; |
244 } | 245 } |
245 return fileapi::FILE_PERMISSION_USE_FILE_PERMISSION; | 246 return fileapi::FILE_PERMISSION_USE_FILE_PERMISSION; |
246 } | 247 } |
247 | 248 |
248 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( | 249 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( |
249 const fileapi::FileSystemURL& url, | 250 const fileapi::FileSystemURL& url, |
250 fileapi::FileSystemContext* context, | 251 fileapi::FileSystemContext* context, |
251 base::PlatformFileError* error_code) const { | 252 base::PlatformFileError* error_code) const { |
| 253 DCHECK(url.is_valid()); |
| 254 |
252 if (url.type() == fileapi::kFileSystemTypeDrive) { | 255 if (url.type() == fileapi::kFileSystemTypeDrive) { |
253 base::AutoLock locker(mount_point_map_lock_); | 256 fileapi::RemoteFileSystemProxyInterface* remote_proxy = |
254 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( | 257 GetRemoteProxy(url.filesystem_id()); |
255 url.filesystem_id()); | 258 if (!remote_proxy) { |
256 if (found != remote_proxy_map_.end()) { | |
257 return new chromeos::RemoteFileSystemOperation(found->second); | |
258 } else { | |
259 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 259 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
260 return NULL; | 260 return NULL; |
261 } | 261 } |
| 262 return new chromeos::RemoteFileSystemOperation(remote_proxy); |
262 } | 263 } |
263 | 264 |
264 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 265 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
265 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); | 266 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); |
266 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 267 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
267 new fileapi::FileSystemOperationContext(context)); | 268 new fileapi::FileSystemOperationContext(context)); |
268 return new fileapi::LocalFileSystemOperation(context, | 269 return new fileapi::LocalFileSystemOperation(context, |
269 operation_context.Pass()); | 270 operation_context.Pass()); |
270 } | 271 } |
271 | 272 |
272 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( | 273 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( |
273 const fileapi::FileSystemURL& url, | 274 const fileapi::FileSystemURL& url, |
274 int64 offset, | 275 int64 offset, |
275 const base::Time& expected_modification_time, | 276 const base::Time& expected_modification_time, |
276 fileapi::FileSystemContext* context) const { | 277 fileapi::FileSystemContext* context) const { |
277 // For now we return a generic Reader implementation which utilizes | 278 // For now we return a generic Reader implementation which utilizes |
278 // CreateSnapshotFile internally (i.e. will download everything first). | 279 // CreateSnapshotFile internally (i.e. will download everything first). |
279 // TODO(satorux,zel): implement more efficient reader for remote cases. | 280 // TODO(satorux,zel): implement more efficient reader for remote cases. |
280 return new fileapi::FileSystemFileStreamReader( | 281 return new fileapi::FileSystemFileStreamReader( |
281 context, url, offset, expected_modification_time); | 282 context, url, offset, expected_modification_time); |
282 } | 283 } |
283 | 284 |
284 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( | 285 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( |
285 const fileapi::FileSystemURL& url, | 286 const fileapi::FileSystemURL& url, |
286 int64 offset, | 287 int64 offset, |
287 fileapi::FileSystemContext* context) const { | 288 fileapi::FileSystemContext* context) const { |
288 if (!url.is_valid()) | 289 DCHECK(url.is_valid()); |
289 return NULL; | 290 |
290 if (url.type() == fileapi::kFileSystemTypeDrive) { | 291 if (url.type() == fileapi::kFileSystemTypeDrive) { |
291 base::AutoLock locker(mount_point_map_lock_); | 292 fileapi::RemoteFileSystemProxyInterface* remote_proxy = |
292 RemoteProxyMap::const_iterator found = remote_proxy_map_.find( | 293 GetRemoteProxy(url.filesystem_id()); |
293 url.filesystem_id()); | 294 if (!remote_proxy) |
294 if (found == remote_proxy_map_.end()) | |
295 return NULL; | 295 return NULL; |
296 return new fileapi::RemoteFileStreamWriter(found->second, url, offset); | 296 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); |
297 } | 297 } |
298 | 298 |
299 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 299 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
300 return NULL; | 300 return NULL; |
301 | 301 |
302 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 302 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
303 return new fileapi::LocalFileStreamWriter(url.path(), offset); | 303 return new fileapi::LocalFileStreamWriter(url.path(), offset); |
304 } | 304 } |
305 | 305 |
306 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, | 306 bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, |
307 FilePath* virtual_path) { | 307 FilePath* virtual_path) { |
308 base::AutoLock locker(mount_point_map_lock_); | 308 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
309 std::map<FilePath, FilePath>::reverse_iterator iter( | 309 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
310 local_to_virtual_map_.upper_bound(filesystem_path)); | |
311 if (iter == local_to_virtual_map_.rend()) | |
312 return false; | |
313 if (iter->first == filesystem_path) { | |
314 *virtual_path = iter->second; | |
315 return true; | |
316 } | |
317 return iter->first.DirName().AppendRelativePath( | |
318 filesystem_path, virtual_path); | |
319 } | 310 } |
320 | 311 |
321 fileapi::IsolatedContext* CrosMountPointProvider::isolated_context() const { | 312 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( |
322 return fileapi::IsolatedContext::GetInstance(); | 313 const std::string& mount_name) const { |
| 314 fileapi::RemoteFileSystemProxyInterface* proxy = |
| 315 mount_points_->GetRemoteFileSystemProxy(mount_name); |
| 316 if (proxy) |
| 317 return proxy; |
| 318 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); |
323 } | 319 } |
324 | 320 |
325 } // namespace chromeos | 321 } // namespace chromeos |
OLD | NEW |