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 "storage/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/sequenced_task_runner.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "storage/browser/fileapi/async_file_util_adapter.h"
16 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
17 #include "storage/browser/fileapi/dragged_file_util.h"
18 #include "storage/browser/fileapi/file_stream_reader.h"
19 #include "storage/browser/fileapi/file_stream_writer.h"
20 #include "storage/browser/fileapi/file_system_context.h"
21 #include "storage/browser/fileapi/file_system_operation.h"
22 #include "storage/browser/fileapi/file_system_operation_context.h"
23 #include "storage/browser/fileapi/isolated_context.h"
24 #include "storage/browser/fileapi/native_file_util.h"
25 #include "storage/browser/fileapi/transient_file_util.h"
26 #include "storage/browser/fileapi/watcher_manager.h"
27 #include "storage/common/fileapi/file_system_types.h"
28 #include "storage/common/fileapi/file_system_util.h"
32 IsolatedFileSystemBackend::IsolatedFileSystemBackend(
33 bool use_for_type_native_local
,
34 bool use_for_type_platform_app
)
35 : use_for_type_native_local_(use_for_type_native_local
),
36 use_for_type_platform_app_(use_for_type_platform_app
),
37 isolated_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
38 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
39 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {
42 IsolatedFileSystemBackend::~IsolatedFileSystemBackend() {
45 bool IsolatedFileSystemBackend::CanHandleType(FileSystemType type
) const {
47 case kFileSystemTypeIsolated
:
48 case kFileSystemTypeDragged
:
49 case kFileSystemTypeForTransientFile
:
51 case kFileSystemTypeNativeLocal
:
52 return use_for_type_native_local_
;
53 case kFileSystemTypeNativeForPlatformApp
:
54 return use_for_type_platform_app_
;
60 void IsolatedFileSystemBackend::Initialize(FileSystemContext
* context
) {
63 void IsolatedFileSystemBackend::ResolveURL(
64 const FileSystemURL
& url
,
65 OpenFileSystemMode mode
,
66 const OpenFileSystemCallback
& callback
) {
67 // We never allow opening a new isolated FileSystem via usual ResolveURL.
68 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 base::File::FILE_ERROR_SECURITY
));
76 AsyncFileUtil
* IsolatedFileSystemBackend::GetAsyncFileUtil(
77 FileSystemType type
) {
79 case kFileSystemTypeNativeLocal
:
80 return isolated_file_util_
.get();
81 case kFileSystemTypeDragged
:
82 return dragged_file_util_
.get();
83 case kFileSystemTypeForTransientFile
:
84 return transient_file_util_
.get();
91 WatcherManager
* IsolatedFileSystemBackend::GetWatcherManager(
92 FileSystemType type
) {
96 CopyOrMoveFileValidatorFactory
*
97 IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
98 FileSystemType type
, base::File::Error
* error_code
) {
100 *error_code
= base::File::FILE_OK
;
104 FileSystemOperation
* IsolatedFileSystemBackend::CreateFileSystemOperation(
105 const FileSystemURL
& url
,
106 FileSystemContext
* context
,
107 base::File::Error
* error_code
) const {
108 return FileSystemOperation::Create(
109 url
, context
, make_scoped_ptr(new FileSystemOperationContext(context
)));
112 bool IsolatedFileSystemBackend::SupportsStreaming(
113 const storage::FileSystemURL
& url
) const {
117 bool IsolatedFileSystemBackend::HasInplaceCopyImplementation(
118 storage::FileSystemType type
) const {
119 DCHECK(type
== kFileSystemTypeNativeLocal
|| type
== kFileSystemTypeDragged
||
120 type
== kFileSystemTypeForTransientFile
);
124 scoped_ptr
<storage::FileStreamReader
>
125 IsolatedFileSystemBackend::CreateFileStreamReader(
126 const FileSystemURL
& url
,
128 int64 max_bytes_to_read
,
129 const base::Time
& expected_modification_time
,
130 FileSystemContext
* context
) const {
131 return scoped_ptr
<storage::FileStreamReader
>(
132 storage::FileStreamReader::CreateForLocalFile(
133 context
->default_file_task_runner(),
136 expected_modification_time
));
139 scoped_ptr
<FileStreamWriter
> IsolatedFileSystemBackend::CreateFileStreamWriter(
140 const FileSystemURL
& url
,
142 FileSystemContext
* context
) const {
143 return scoped_ptr
<FileStreamWriter
>(
144 FileStreamWriter::CreateForLocalFile(
145 context
->default_file_task_runner(),
148 FileStreamWriter::OPEN_EXISTING_FILE
));
151 FileSystemQuotaUtil
* IsolatedFileSystemBackend::GetQuotaUtil() {
156 const UpdateObserverList
* IsolatedFileSystemBackend::GetUpdateObservers(
157 FileSystemType type
) const {
161 const ChangeObserverList
* IsolatedFileSystemBackend::GetChangeObservers(
162 FileSystemType type
) const {
166 const AccessObserverList
* IsolatedFileSystemBackend::GetAccessObservers(
167 FileSystemType type
) const {
171 } // namespace storage