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/message_loop/message_loop_proxy.h"
14 #include "base/sequenced_task_runner.h"
15 #include "storage/browser/blob/file_stream_reader.h"
16 #include "storage/browser/fileapi/async_file_util_adapter.h"
17 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
18 #include "storage/browser/fileapi/dragged_file_util.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 : isolated_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())),
34 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
35 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {
38 IsolatedFileSystemBackend::~IsolatedFileSystemBackend() {
41 bool IsolatedFileSystemBackend::CanHandleType(FileSystemType type
) const {
43 case kFileSystemTypeIsolated
:
44 case kFileSystemTypeDragged
:
45 case kFileSystemTypeForTransientFile
:
47 #if !defined(OS_CHROMEOS)
48 case kFileSystemTypeNativeLocal
:
49 case kFileSystemTypeNativeForPlatformApp
:
57 void IsolatedFileSystemBackend::Initialize(FileSystemContext
* context
) {
60 void IsolatedFileSystemBackend::ResolveURL(
61 const FileSystemURL
& url
,
62 OpenFileSystemMode mode
,
63 const OpenFileSystemCallback
& callback
) {
64 // We never allow opening a new isolated FileSystem via usual ResolveURL.
65 base::MessageLoopProxy::current()->PostTask(
70 base::File::FILE_ERROR_SECURITY
));
73 AsyncFileUtil
* IsolatedFileSystemBackend::GetAsyncFileUtil(
74 FileSystemType type
) {
76 case kFileSystemTypeNativeLocal
:
77 return isolated_file_util_
.get();
78 case kFileSystemTypeDragged
:
79 return dragged_file_util_
.get();
80 case kFileSystemTypeForTransientFile
:
81 return transient_file_util_
.get();
88 WatcherManager
* IsolatedFileSystemBackend::GetWatcherManager(
89 FileSystemType type
) {
93 CopyOrMoveFileValidatorFactory
*
94 IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
95 FileSystemType type
, base::File::Error
* error_code
) {
97 *error_code
= base::File::FILE_OK
;
101 FileSystemOperation
* IsolatedFileSystemBackend::CreateFileSystemOperation(
102 const FileSystemURL
& url
,
103 FileSystemContext
* context
,
104 base::File::Error
* error_code
) const {
105 return FileSystemOperation::Create(
106 url
, context
, make_scoped_ptr(new FileSystemOperationContext(context
)));
109 bool IsolatedFileSystemBackend::SupportsStreaming(
110 const storage::FileSystemURL
& url
) const {
114 bool IsolatedFileSystemBackend::HasInplaceCopyImplementation(
115 storage::FileSystemType type
) const {
116 DCHECK(type
== kFileSystemTypeNativeLocal
|| type
== kFileSystemTypeDragged
||
117 type
== kFileSystemTypeForTransientFile
);
121 scoped_ptr
<storage::FileStreamReader
>
122 IsolatedFileSystemBackend::CreateFileStreamReader(
123 const FileSystemURL
& url
,
125 int64 max_bytes_to_read
,
126 const base::Time
& expected_modification_time
,
127 FileSystemContext
* context
) const {
128 return scoped_ptr
<storage::FileStreamReader
>(
129 storage::FileStreamReader::CreateForLocalFile(
130 context
->default_file_task_runner(),
133 expected_modification_time
));
136 scoped_ptr
<FileStreamWriter
> IsolatedFileSystemBackend::CreateFileStreamWriter(
137 const FileSystemURL
& url
,
139 FileSystemContext
* context
) const {
140 return scoped_ptr
<FileStreamWriter
>(
141 FileStreamWriter::CreateForLocalFile(
142 context
->default_file_task_runner(),
145 FileStreamWriter::OPEN_EXISTING_FILE
));
148 FileSystemQuotaUtil
* IsolatedFileSystemBackend::GetQuotaUtil() {
153 const UpdateObserverList
* IsolatedFileSystemBackend::GetUpdateObservers(
154 FileSystemType type
) const {
158 const ChangeObserverList
* IsolatedFileSystemBackend::GetChangeObservers(
159 FileSystemType type
) const {
163 const AccessObserverList
* IsolatedFileSystemBackend::GetAccessObservers(
164 FileSystemType type
) const {
168 } // namespace storage