blob: cf70885077719c17b4b0306de8a4ab275778cdca [file] [log] [blame]
[email protected]6fe69652012-04-02 09:35:051// 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
3// found in the LICENSE file.
4
[email protected]f19bbf62013-07-09 01:22:325#include "webkit/browser/fileapi/isolated_file_system_backend.h"
[email protected]6fe69652012-04-02 09:35:056
[email protected]c671c8a2012-04-05 10:28:397#include <string>
8
[email protected]6fe69652012-04-02 09:35:059#include "base/bind.h"
[email protected]57999812013-02-24 05:40:5210#include "base/files/file_path.h"
[email protected]d2691962013-05-16 14:19:2711#include "base/files/file_util_proxy.h"
[email protected]6fe69652012-04-02 09:35:0512#include "base/logging.h"
[email protected]7ccb7072013-06-10 20:56:2813#include "base/message_loop/message_loop_proxy.h"
[email protected]2f9f5b492012-09-12 02:59:0614#include "base/platform_file.h"
[email protected]fb441962013-05-08 05:35:2415#include "base/sequenced_task_runner.h"
[email protected]b8f2f422013-09-12 17:38:3916#include "webkit/browser/blob/file_stream_reader.h"
[email protected]c6f9203a2013-05-28 02:08:0717#include "webkit/browser/fileapi/async_file_util_adapter.h"
[email protected]20c2df62013-05-21 08:26:3618#include "webkit/browser/fileapi/copy_or_move_file_validator.h"
[email protected]a3224752013-09-13 10:40:4419#include "webkit/browser/fileapi/dragged_file_util.h"
[email protected]b8f2f422013-09-12 17:38:3920#include "webkit/browser/fileapi/file_stream_writer.h"
[email protected]c6f9203a2013-05-28 02:08:0721#include "webkit/browser/fileapi/file_system_context.h"
[email protected]bd69f572013-09-09 06:15:2322#include "webkit/browser/fileapi/file_system_operation.h"
[email protected]c6f9203a2013-05-28 02:08:0723#include "webkit/browser/fileapi/file_system_operation_context.h"
[email protected]f25e1132013-05-24 13:58:0424#include "webkit/browser/fileapi/isolated_context.h"
[email protected]5a20d042013-05-22 12:54:1825#include "webkit/browser/fileapi/native_file_util.h"
26#include "webkit/browser/fileapi/transient_file_util.h"
[email protected]61d271f32013-05-28 04:59:2327#include "webkit/common/fileapi/file_system_types.h"
28#include "webkit/common/fileapi/file_system_util.h"
[email protected]6fe69652012-04-02 09:35:0529
30namespace fileapi {
31
[email protected]f19bbf62013-07-09 01:22:3232IsolatedFileSystemBackend::IsolatedFileSystemBackend()
[email protected]a3224752013-09-13 10:40:4433 : isolated_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
[email protected]b2582862013-05-14 08:50:1834 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
35 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {
[email protected]6fe69652012-04-02 09:35:0536}
37
[email protected]f19bbf62013-07-09 01:22:3238IsolatedFileSystemBackend::~IsolatedFileSystemBackend() {
[email protected]6fe69652012-04-02 09:35:0539}
40
[email protected]f19bbf62013-07-09 01:22:3241bool IsolatedFileSystemBackend::CanHandleType(FileSystemType type) const {
[email protected]420fb562013-04-18 01:46:3442 switch (type) {
43 case kFileSystemTypeIsolated:
44 case kFileSystemTypeDragged:
[email protected]b2582862013-05-14 08:50:1845 case kFileSystemTypeForTransientFile:
[email protected]420fb562013-04-18 01:46:3446 return true;
47#if !defined(OS_CHROMEOS)
48 case kFileSystemTypeNativeLocal:
49 case kFileSystemTypeNativeForPlatformApp:
50 return true;
51#endif
52 default:
53 return false;
54 }
55}
56
[email protected]3fc17aed2013-07-24 10:01:5057void IsolatedFileSystemBackend::Initialize(FileSystemContext* context) {
58}
59
60void IsolatedFileSystemBackend::OpenFileSystem(
[email protected]6fe69652012-04-02 09:35:0561 const GURL& origin_url,
62 FileSystemType type,
[email protected]22dea52c2013-05-29 07:44:4063 OpenFileSystemMode mode,
[email protected]3fc17aed2013-07-24 10:01:5064 const OpenFileSystemCallback& callback) {
[email protected]6fe69652012-04-02 09:35:0565 // We never allow opening a new isolated FileSystem via usual OpenFileSystem.
66 base::MessageLoopProxy::current()->PostTask(
67 FROM_HERE,
[email protected]a836883d2013-07-12 03:50:0268 base::Bind(callback,
69 GetFileSystemRootURI(origin_url, type),
70 GetFileSystemName(origin_url, type),
[email protected]141bcc52014-01-27 21:36:0071 base::File::FILE_ERROR_SECURITY));
[email protected]6fe69652012-04-02 09:35:0572}
73
[email protected]f19bbf62013-07-09 01:22:3274AsyncFileUtil* IsolatedFileSystemBackend::GetAsyncFileUtil(
[email protected]25b697992013-01-29 07:10:0575 FileSystemType type) {
76 switch (type) {
77 case kFileSystemTypeNativeLocal:
[email protected]6ef35d62012-08-02 02:55:2878 return isolated_file_util_.get();
79 case kFileSystemTypeDragged:
80 return dragged_file_util_.get();
[email protected]b2582862013-05-14 08:50:1881 case kFileSystemTypeForTransientFile:
82 return transient_file_util_.get();
[email protected]9fb9294a2012-08-21 14:55:3783 default:
[email protected]6ef35d62012-08-02 02:55:2884 NOTREACHED();
85 }
86 return NULL;
[email protected]6fe69652012-04-02 09:35:0587}
88
[email protected]98407ee2013-04-04 08:52:1789CopyOrMoveFileValidatorFactory*
[email protected]f19bbf62013-07-09 01:22:3290IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
[email protected]141bcc52014-01-27 21:36:0091 FileSystemType type, base::File::Error* error_code) {
[email protected]98407ee2013-04-04 08:52:1792 DCHECK(error_code);
[email protected]141bcc52014-01-27 21:36:0093 *error_code = base::File::FILE_OK;
[email protected]98407ee2013-04-04 08:52:1794 return NULL;
95}
96
[email protected]f19bbf62013-07-09 01:22:3297FileSystemOperation* IsolatedFileSystemBackend::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:0998 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:1399 FileSystemContext* context,
[email protected]141bcc52014-01-27 21:36:00100 base::File::Error* error_code) const {
[email protected]bd69f572013-09-09 06:15:23101 return FileSystemOperation::Create(
[email protected]5dfa47c2013-06-10 04:57:15102 url, context, make_scoped_ptr(new FileSystemOperationContext(context)));
[email protected]6fe69652012-04-02 09:35:05103}
104
[email protected]3ee9eb02013-04-10 09:17:05105scoped_ptr<webkit_blob::FileStreamReader>
[email protected]f19bbf62013-07-09 01:22:32106IsolatedFileSystemBackend::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09107 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19108 int64 offset,
[email protected]a1057832012-10-15 13:28:06109 const base::Time& expected_modification_time,
[email protected]ad117b12012-04-19 05:40:19110 FileSystemContext* context) const {
[email protected]3ee9eb02013-04-10 09:17:05111 return scoped_ptr<webkit_blob::FileStreamReader>(
[email protected]b8f2f422013-09-12 17:38:39112 webkit_blob::FileStreamReader::CreateForLocalFile(
[email protected]8dd68f82013-08-04 08:02:44113 context->default_file_task_runner(),
[email protected]3ee9eb02013-04-10 09:17:05114 url.path(), offset, expected_modification_time));
[email protected]ad117b12012-04-19 05:40:19115}
116
[email protected]f19bbf62013-07-09 01:22:32117scoped_ptr<FileStreamWriter> IsolatedFileSystemBackend::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09118 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01119 int64 offset,
120 FileSystemContext* context) const {
[email protected]b8f2f422013-09-12 17:38:39121 return scoped_ptr<FileStreamWriter>(FileStreamWriter::CreateForLocalFile(
[email protected]8dd68f82013-08-04 08:02:44122 context->default_file_task_runner(), url.path(), offset));
[email protected]7e84b912012-05-16 04:42:01123}
124
[email protected]f19bbf62013-07-09 01:22:32125FileSystemQuotaUtil* IsolatedFileSystemBackend::GetQuotaUtil() {
[email protected]6faad822012-05-11 12:58:29126 // No quota support.
127 return NULL;
128}
129
[email protected]6fe69652012-04-02 09:35:05130} // namespace fileapi