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
3 // found in the LICENSE file.
5 #include "webkit/browser/fileapi/isolated_file_system_backend.h"
10 #include "base/files/file_path.h"
11 #include "base/files/file_util_proxy.h"
12 #include "base/logging.h"
13 #include "base/message_loop/message_loop_proxy.h"
14 #include "base/sequenced_task_runner.h"
15 #include "webkit/browser/blob/file_stream_reader.h"
16 #include "webkit/browser/fileapi/async_file_util_adapter.h"
17 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
18 #include "webkit/browser/fileapi/dragged_file_util.h"
19 #include "webkit/browser/fileapi/file_stream_writer.h"
20 #include "webkit/browser/fileapi/file_system_context.h"
21 #include "webkit/browser/fileapi/file_system_operation.h"
22 #include "webkit/browser/fileapi/file_system_operation_context.h"
23 #include "webkit/browser/fileapi/isolated_context.h"
24 #include "webkit/browser/fileapi/native_file_util.h"
25 #include "webkit/browser/fileapi/transient_file_util.h"
26 #include "webkit/common/fileapi/file_system_types.h"
27 #include "webkit/common/fileapi/file_system_util.h"
31 IsolatedFileSystemBackend::IsolatedFileSystemBackend()
32 : isolated_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
33 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
34 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {
37 IsolatedFileSystemBackend::~IsolatedFileSystemBackend() {
40 bool IsolatedFileSystemBackend::CanHandleType(FileSystemType type
) const {
42 case kFileSystemTypeIsolated
:
43 case kFileSystemTypeDragged
:
44 case kFileSystemTypeForTransientFile
:
46 #if !defined(OS_CHROMEOS)
47 case kFileSystemTypeNativeLocal
:
48 case kFileSystemTypeNativeForPlatformApp
:
56 void IsolatedFileSystemBackend::Initialize(FileSystemContext
* context
) {
59 void IsolatedFileSystemBackend::ResolveURL(
60 const FileSystemURL
& url
,
61 OpenFileSystemMode mode
,
62 const OpenFileSystemCallback
& callback
) {
63 // We never allow opening a new isolated FileSystem via usual ResolveURL.
64 base::MessageLoopProxy::current()->PostTask(
69 base::File::FILE_ERROR_SECURITY
));
72 AsyncFileUtil
* IsolatedFileSystemBackend::GetAsyncFileUtil(
73 FileSystemType type
) {
75 case kFileSystemTypeNativeLocal
:
76 return isolated_file_util_
.get();
77 case kFileSystemTypeDragged
:
78 return dragged_file_util_
.get();
79 case kFileSystemTypeForTransientFile
:
80 return transient_file_util_
.get();
87 CopyOrMoveFileValidatorFactory
*
88 IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
89 FileSystemType type
, base::File::Error
* error_code
) {
91 *error_code
= base::File::FILE_OK
;
95 FileSystemOperation
* IsolatedFileSystemBackend::CreateFileSystemOperation(
96 const FileSystemURL
& url
,
97 FileSystemContext
* context
,
98 base::File::Error
* error_code
) const {
99 return FileSystemOperation::Create(
100 url
, context
, make_scoped_ptr(new FileSystemOperationContext(context
)));
103 bool IsolatedFileSystemBackend::SupportsStreaming(
104 const fileapi::FileSystemURL
& url
) const {
108 scoped_ptr
<webkit_blob::FileStreamReader
>
109 IsolatedFileSystemBackend::CreateFileStreamReader(
110 const FileSystemURL
& url
,
112 const base::Time
& expected_modification_time
,
113 FileSystemContext
* context
) const {
114 return scoped_ptr
<webkit_blob::FileStreamReader
>(
115 webkit_blob::FileStreamReader::CreateForLocalFile(
116 context
->default_file_task_runner(),
117 url
.path(), offset
, expected_modification_time
));
120 scoped_ptr
<FileStreamWriter
> IsolatedFileSystemBackend::CreateFileStreamWriter(
121 const FileSystemURL
& url
,
123 FileSystemContext
* context
) const {
124 return scoped_ptr
<FileStreamWriter
>(
125 FileStreamWriter::CreateForLocalFile(
126 context
->default_file_task_runner(),
129 FileStreamWriter::OPEN_EXISTING_FILE
));
132 FileSystemQuotaUtil
* IsolatedFileSystemBackend::GetQuotaUtil() {
137 } // namespace fileapi