OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "chrome/browser/chromeos/fileapi/cros_mount_point_provider.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/chromeos/fileapi/cros_mount_point_provider_delegate.h" |
14 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" | 15 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" |
15 #include "chrome/browser/chromeos/fileapi/remote_file_stream_writer.h" | |
16 #include "chrome/browser/chromeos/fileapi/remote_file_system_operation.h" | |
17 #include "chromeos/dbus/cros_disks_client.h" | 16 #include "chromeos/dbus/cros_disks_client.h" |
| 17 #include "webkit/browser/blob/file_stream_reader.h" |
18 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 18 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
19 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 19 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
20 #include "webkit/browser/fileapi/external_mount_points.h" | 20 #include "webkit/browser/fileapi/external_mount_points.h" |
21 #include "webkit/browser/fileapi/file_system_context.h" | 21 #include "webkit/browser/fileapi/file_system_context.h" |
22 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" | 22 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" |
23 #include "webkit/browser/fileapi/file_system_operation_context.h" | 23 #include "webkit/browser/fileapi/file_system_operation_context.h" |
24 #include "webkit/browser/fileapi/file_system_task_runners.h" | 24 #include "webkit/browser/fileapi/file_system_task_runners.h" |
25 #include "webkit/browser/fileapi/file_system_url.h" | 25 #include "webkit/browser/fileapi/file_system_url.h" |
26 #include "webkit/browser/fileapi/isolated_context.h" | 26 #include "webkit/browser/fileapi/isolated_context.h" |
27 #include "webkit/browser/fileapi/isolated_file_util.h" | 27 #include "webkit/browser/fileapi/isolated_file_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
39 // static | 39 // static |
40 bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { | 40 bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { |
41 if (!url.is_valid()) | 41 if (!url.is_valid()) |
42 return false; | 42 return false; |
43 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 43 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
44 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 44 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
45 url.type() == fileapi::kFileSystemTypeDrive; | 45 url.type() == fileapi::kFileSystemTypeDrive; |
46 } | 46 } |
47 | 47 |
48 CrosMountPointProvider::CrosMountPointProvider( | 48 CrosMountPointProvider::CrosMountPointProvider( |
| 49 CrosMountPointProviderDelegate* drive_delegate, |
49 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 50 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
50 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 51 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
51 fileapi::ExternalMountPoints* system_mount_points) | 52 fileapi::ExternalMountPoints* system_mount_points) |
52 : special_storage_policy_(special_storage_policy), | 53 : special_storage_policy_(special_storage_policy), |
53 file_access_permissions_(new FileAccessPermissions()), | 54 file_access_permissions_(new FileAccessPermissions()), |
54 local_file_util_(new fileapi::AsyncFileUtilAdapter( | 55 local_file_util_(new fileapi::AsyncFileUtilAdapter( |
55 new fileapi::IsolatedFileUtil())), | 56 new fileapi::IsolatedFileUtil())), |
| 57 drive_delegate_(drive_delegate), |
56 mount_points_(mount_points), | 58 mount_points_(mount_points), |
57 system_mount_points_(system_mount_points) { | 59 system_mount_points_(system_mount_points) { |
58 } | 60 } |
59 | 61 |
60 CrosMountPointProvider::~CrosMountPointProvider() { | 62 CrosMountPointProvider::~CrosMountPointProvider() { |
61 } | 63 } |
62 | 64 |
63 void CrosMountPointProvider::AddSystemMountPoints() { | 65 void CrosMountPointProvider::AddSystemMountPoints() { |
64 // RegisterFileSystem() is no-op if the mount point with the same name | 66 // RegisterFileSystem() is no-op if the mount point with the same name |
65 // already exists, hence it's safe to call without checking if a mount | 67 // already exists, hence it's safe to call without checking if a mount |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 215 |
214 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( | 216 fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( |
215 fileapi::FileSystemType type) { | 217 fileapi::FileSystemType type) { |
216 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 218 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
217 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 219 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
218 return local_file_util_->sync_file_util(); | 220 return local_file_util_->sync_file_util(); |
219 } | 221 } |
220 | 222 |
221 fileapi::AsyncFileUtil* CrosMountPointProvider::GetAsyncFileUtil( | 223 fileapi::AsyncFileUtil* CrosMountPointProvider::GetAsyncFileUtil( |
222 fileapi::FileSystemType type) { | 224 fileapi::FileSystemType type) { |
| 225 if (type == fileapi::kFileSystemTypeDrive) |
| 226 return drive_delegate_->GetAsyncFileUtil(type); |
| 227 |
223 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 228 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
224 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 229 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
225 return local_file_util_.get(); | 230 return local_file_util_.get(); |
226 } | 231 } |
227 | 232 |
228 fileapi::CopyOrMoveFileValidatorFactory* | 233 fileapi::CopyOrMoveFileValidatorFactory* |
229 CrosMountPointProvider::GetCopyOrMoveFileValidatorFactory( | 234 CrosMountPointProvider::GetCopyOrMoveFileValidatorFactory( |
230 fileapi::FileSystemType type, base::PlatformFileError* error_code) { | 235 fileapi::FileSystemType type, base::PlatformFileError* error_code) { |
231 DCHECK(error_code); | 236 DCHECK(error_code); |
232 *error_code = base::PLATFORM_FILE_OK; | 237 *error_code = base::PLATFORM_FILE_OK; |
233 return NULL; | 238 return NULL; |
234 } | 239 } |
235 | 240 |
236 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( | 241 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( |
237 const fileapi::FileSystemURL& url, | 242 const fileapi::FileSystemURL& url, |
238 fileapi::FileSystemContext* context, | 243 fileapi::FileSystemContext* context, |
239 base::PlatformFileError* error_code) const { | 244 base::PlatformFileError* error_code) const { |
240 DCHECK(url.is_valid()); | 245 DCHECK(url.is_valid()); |
241 | 246 |
242 if (!IsAccessAllowed(url)) { | 247 if (!IsAccessAllowed(url)) { |
243 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 248 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
244 return NULL; | 249 return NULL; |
245 } | 250 } |
246 | 251 |
247 if (url.type() == fileapi::kFileSystemTypeDrive) { | 252 if (url.type() == fileapi::kFileSystemTypeDrive) |
248 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 253 return drive_delegate_->CreateFileSystemOperation(url, context, error_code); |
249 GetRemoteProxy(url.filesystem_id()); | |
250 if (!remote_proxy) { | |
251 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
252 return NULL; | |
253 } | |
254 return new RemoteFileSystemOperation(remote_proxy); | |
255 } | |
256 | 254 |
257 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 255 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
258 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); | 256 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); |
259 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 257 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
260 new fileapi::FileSystemOperationContext(context)); | 258 new fileapi::FileSystemOperationContext(context)); |
261 operation_context->set_root_path(GetFileSystemRootPath(url)); | 259 operation_context->set_root_path(GetFileSystemRootPath(url)); |
262 return new fileapi::LocalFileSystemOperation(url, context, | 260 return new fileapi::LocalFileSystemOperation(url, context, |
263 operation_context.Pass()); | 261 operation_context.Pass()); |
264 } | 262 } |
265 | 263 |
266 scoped_ptr<webkit_blob::FileStreamReader> | 264 scoped_ptr<webkit_blob::FileStreamReader> |
267 CrosMountPointProvider::CreateFileStreamReader( | 265 CrosMountPointProvider::CreateFileStreamReader( |
268 const fileapi::FileSystemURL& url, | 266 const fileapi::FileSystemURL& url, |
269 int64 offset, | 267 int64 offset, |
270 const base::Time& expected_modification_time, | 268 const base::Time& expected_modification_time, |
271 fileapi::FileSystemContext* context) const { | 269 fileapi::FileSystemContext* context) const { |
272 DCHECK(url.is_valid()); | 270 DCHECK(url.is_valid()); |
273 | 271 |
274 if (!IsAccessAllowed(url)) | 272 if (!IsAccessAllowed(url)) |
275 return scoped_ptr<webkit_blob::FileStreamReader>(); | 273 return scoped_ptr<webkit_blob::FileStreamReader>(); |
276 | 274 |
277 if (url.type() == fileapi::kFileSystemTypeDrive) { | 275 if (url.type() == fileapi::kFileSystemTypeDrive) { |
278 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 276 return drive_delegate_->CreateFileStreamReader( |
279 GetRemoteProxy(url.filesystem_id()); | 277 url, offset, expected_modification_time, context); |
280 if (!remote_proxy) | |
281 return scoped_ptr<webkit_blob::FileStreamReader>(); | |
282 return remote_proxy->CreateFileStreamReader( | |
283 context->task_runners()->file_task_runner(), | |
284 url, offset, expected_modification_time); | |
285 } | 278 } |
286 | 279 |
287 return scoped_ptr<webkit_blob::FileStreamReader>( | 280 return scoped_ptr<webkit_blob::FileStreamReader>( |
288 new fileapi::FileSystemFileStreamReader( | 281 new fileapi::FileSystemFileStreamReader( |
289 context, url, offset, expected_modification_time)); | 282 context, url, offset, expected_modification_time)); |
290 } | 283 } |
291 | 284 |
292 scoped_ptr<fileapi::FileStreamWriter> | 285 scoped_ptr<fileapi::FileStreamWriter> |
293 CrosMountPointProvider::CreateFileStreamWriter( | 286 CrosMountPointProvider::CreateFileStreamWriter( |
294 const fileapi::FileSystemURL& url, | 287 const fileapi::FileSystemURL& url, |
295 int64 offset, | 288 int64 offset, |
296 fileapi::FileSystemContext* context) const { | 289 fileapi::FileSystemContext* context) const { |
297 DCHECK(url.is_valid()); | 290 DCHECK(url.is_valid()); |
298 | 291 |
299 if (!IsAccessAllowed(url)) | 292 if (!IsAccessAllowed(url)) |
300 return scoped_ptr<fileapi::FileStreamWriter>(); | 293 return scoped_ptr<fileapi::FileStreamWriter>(); |
301 | 294 |
302 if (url.type() == fileapi::kFileSystemTypeDrive) { | 295 if (url.type() == fileapi::kFileSystemTypeDrive) |
303 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 296 return drive_delegate_->CreateFileStreamWriter(url, offset, context); |
304 GetRemoteProxy(url.filesystem_id()); | |
305 if (!remote_proxy) | |
306 return scoped_ptr<fileapi::FileStreamWriter>(); | |
307 return scoped_ptr<fileapi::FileStreamWriter>( | |
308 new RemoteFileStreamWriter( | |
309 remote_proxy, url, offset, | |
310 context->task_runners()->file_task_runner())); | |
311 } | |
312 | 297 |
313 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 298 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
314 return scoped_ptr<fileapi::FileStreamWriter>(); | 299 return scoped_ptr<fileapi::FileStreamWriter>(); |
315 | 300 |
316 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 301 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
317 return scoped_ptr<fileapi::FileStreamWriter>( | 302 return scoped_ptr<fileapi::FileStreamWriter>( |
318 new fileapi::LocalFileStreamWriter( | 303 new fileapi::LocalFileStreamWriter( |
319 context->task_runners()->file_task_runner(), url.path(), offset)); | 304 context->task_runners()->file_task_runner(), url.path(), offset)); |
320 } | 305 } |
321 | 306 |
322 bool CrosMountPointProvider::GetVirtualPath( | 307 bool CrosMountPointProvider::GetVirtualPath( |
323 const base::FilePath& filesystem_path, | 308 const base::FilePath& filesystem_path, |
324 base::FilePath* virtual_path) { | 309 base::FilePath* virtual_path) { |
325 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 310 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
326 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 311 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
327 } | 312 } |
328 | 313 |
329 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( | |
330 const std::string& mount_name) const { | |
331 fileapi::RemoteFileSystemProxyInterface* proxy = | |
332 mount_points_->GetRemoteFileSystemProxy(mount_name); | |
333 if (proxy) | |
334 return proxy; | |
335 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); | |
336 } | |
337 | |
338 base::FilePath CrosMountPointProvider::GetFileSystemRootPath( | 314 base::FilePath CrosMountPointProvider::GetFileSystemRootPath( |
339 const fileapi::FileSystemURL& url) const { | 315 const fileapi::FileSystemURL& url) const { |
340 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); | 316 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); |
341 if (!url.is_valid()) | 317 if (!url.is_valid()) |
342 return base::FilePath(); | 318 return base::FilePath(); |
343 | 319 |
344 base::FilePath root_path; | 320 base::FilePath root_path; |
345 std::string mount_name = url.filesystem_id(); | 321 std::string mount_name = url.filesystem_id(); |
346 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && | 322 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && |
347 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { | 323 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { |
348 return base::FilePath(); | 324 return base::FilePath(); |
349 } | 325 } |
350 | 326 |
351 return root_path.DirName(); | 327 return root_path.DirName(); |
352 } | 328 } |
353 | 329 |
354 } // namespace chromeos | 330 } // namespace chromeos |
OLD | NEW |