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/file_system_backend.h" | 5 #include "chrome/browser/chromeos/fileapi/file_system_backend.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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 namespace chromeos { | 32 namespace chromeos { |
33 | 33 |
34 // static | 34 // static |
35 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { | 35 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { |
36 if (!url.is_valid()) | 36 if (!url.is_valid()) |
37 return false; | 37 return false; |
38 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 38 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
39 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 39 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
40 url.type() == fileapi::kFileSystemTypeDrive; | 40 url.type() == fileapi::kFileSystemTypeDrive || |
| 41 url.type() == fileapi::kFileSystemTypeProvided; |
41 } | 42 } |
42 | 43 |
43 FileSystemBackend::FileSystemBackend( | 44 FileSystemBackend::FileSystemBackend( |
44 FileSystemBackendDelegate* drive_delegate, | 45 FileSystemBackendDelegate* drive_delegate, |
| 46 FileSystemBackendDelegate* file_system_provider_delegate, |
45 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 47 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
46 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 48 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
47 fileapi::ExternalMountPoints* system_mount_points) | 49 fileapi::ExternalMountPoints* system_mount_points) |
48 : special_storage_policy_(special_storage_policy), | 50 : special_storage_policy_(special_storage_policy), |
49 file_access_permissions_(new FileAccessPermissions()), | 51 file_access_permissions_(new FileAccessPermissions()), |
50 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), | 52 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), |
51 drive_delegate_(drive_delegate), | 53 drive_delegate_(drive_delegate), |
52 mount_points_(mount_points), | 54 mount_points_(mount_points), |
53 system_mount_points_(system_mount_points) { | 55 system_mount_points_(system_mount_points) {} |
54 } | |
55 | 56 |
56 FileSystemBackend::~FileSystemBackend() { | 57 FileSystemBackend::~FileSystemBackend() { |
57 } | 58 } |
58 | 59 |
59 void FileSystemBackend::AddSystemMountPoints() { | 60 void FileSystemBackend::AddSystemMountPoints() { |
60 // RegisterFileSystem() is no-op if the mount point with the same name | 61 // RegisterFileSystem() is no-op if the mount point with the same name |
61 // already exists, hence it's safe to call without checking if a mount | 62 // already exists, hence it's safe to call without checking if a mount |
62 // point already exists or not. | 63 // point already exists or not. |
63 system_mount_points_->RegisterFileSystem( | 64 system_mount_points_->RegisterFileSystem( |
64 "archive", | 65 "archive", |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 std::vector<base::FilePath> root_dirs; | 226 std::vector<base::FilePath> root_dirs; |
226 for (size_t i = 0; i < mount_points.size(); ++i) | 227 for (size_t i = 0; i < mount_points.size(); ++i) |
227 root_dirs.push_back(mount_points[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::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( | 232 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( |
232 fileapi::FileSystemType type) { | 233 fileapi::FileSystemType type) { |
233 if (type == fileapi::kFileSystemTypeDrive) | 234 if (type == fileapi::kFileSystemTypeDrive) |
234 return drive_delegate_->GetAsyncFileUtil(type); | 235 return drive_delegate_->GetAsyncFileUtil(type); |
| 236 if (type == fileapi::kFileSystemTypeProvided) |
| 237 return file_system_provider_delegate_->GetAsyncFileUtil(type); |
235 | 238 |
236 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 239 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
237 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 240 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
238 return local_file_util_.get(); | 241 return local_file_util_.get(); |
239 } | 242 } |
240 | 243 |
241 fileapi::CopyOrMoveFileValidatorFactory* | 244 fileapi::CopyOrMoveFileValidatorFactory* |
242 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 245 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
243 fileapi::FileSystemType type, base::File::Error* error_code) { | 246 fileapi::FileSystemType type, base::File::Error* error_code) { |
244 DCHECK(error_code); | 247 DCHECK(error_code); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 DCHECK(url.is_valid()); | 282 DCHECK(url.is_valid()); |
280 | 283 |
281 if (!IsAccessAllowed(url)) | 284 if (!IsAccessAllowed(url)) |
282 return scoped_ptr<webkit_blob::FileStreamReader>(); | 285 return scoped_ptr<webkit_blob::FileStreamReader>(); |
283 | 286 |
284 if (url.type() == fileapi::kFileSystemTypeDrive) { | 287 if (url.type() == fileapi::kFileSystemTypeDrive) { |
285 return drive_delegate_->CreateFileStreamReader( | 288 return drive_delegate_->CreateFileStreamReader( |
286 url, offset, expected_modification_time, context); | 289 url, offset, expected_modification_time, context); |
287 } | 290 } |
288 | 291 |
| 292 if (url.type() == fileapi::kFileSystemTypeProvided) { |
| 293 return file_system_provider_delegate_->CreateFileStreamReader( |
| 294 url, offset, expected_modification_time, context); |
| 295 } |
| 296 |
289 return scoped_ptr<webkit_blob::FileStreamReader>( | 297 return scoped_ptr<webkit_blob::FileStreamReader>( |
290 webkit_blob::FileStreamReader::CreateForFileSystemFile( | 298 webkit_blob::FileStreamReader::CreateForFileSystemFile( |
291 context, url, offset, expected_modification_time)); | 299 context, url, offset, expected_modification_time)); |
292 } | 300 } |
293 | 301 |
294 scoped_ptr<fileapi::FileStreamWriter> | 302 scoped_ptr<fileapi::FileStreamWriter> |
295 FileSystemBackend::CreateFileStreamWriter( | 303 FileSystemBackend::CreateFileStreamWriter( |
296 const fileapi::FileSystemURL& url, | 304 const fileapi::FileSystemURL& url, |
297 int64 offset, | 305 int64 offset, |
298 fileapi::FileSystemContext* context) const { | 306 fileapi::FileSystemContext* context) const { |
299 DCHECK(url.is_valid()); | 307 DCHECK(url.is_valid()); |
300 | 308 |
301 if (!IsAccessAllowed(url)) | 309 if (!IsAccessAllowed(url)) |
302 return scoped_ptr<fileapi::FileStreamWriter>(); | 310 return scoped_ptr<fileapi::FileStreamWriter>(); |
303 | 311 |
304 if (url.type() == fileapi::kFileSystemTypeDrive) | 312 if (url.type() == fileapi::kFileSystemTypeDrive) |
305 return drive_delegate_->CreateFileStreamWriter(url, offset, context); | 313 return drive_delegate_->CreateFileStreamWriter(url, offset, context); |
306 | 314 |
307 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 315 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
308 return scoped_ptr<fileapi::FileStreamWriter>(); | 316 return scoped_ptr<fileapi::FileStreamWriter>(); |
309 | 317 |
| 318 if (url.type() == fileapi::kFileSystemTypeProvided) { |
| 319 return file_system_provider_delegate_->CreateFileStreamWriter( |
| 320 url, offset, context); |
| 321 } |
| 322 |
310 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 323 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
311 return scoped_ptr<fileapi::FileStreamWriter>( | 324 return scoped_ptr<fileapi::FileStreamWriter>( |
312 fileapi::FileStreamWriter::CreateForLocalFile( | 325 fileapi::FileStreamWriter::CreateForLocalFile( |
313 context->default_file_task_runner(), url.path(), offset, | 326 context->default_file_task_runner(), url.path(), offset, |
314 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); | 327 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); |
315 } | 328 } |
316 | 329 |
317 bool FileSystemBackend::GetVirtualPath( | 330 bool FileSystemBackend::GetVirtualPath( |
318 const base::FilePath& filesystem_path, | 331 const base::FilePath& filesystem_path, |
319 base::FilePath* virtual_path) { | 332 base::FilePath* virtual_path) { |
320 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 333 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
321 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 334 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
322 } | 335 } |
323 | 336 |
324 } // namespace chromeos | 337 } // namespace chromeos |
OLD | NEW |