blob: db59e35c8578a33da23ae2322a3a44fecdd79d03 [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]b76b556d2013-05-29 03:09:4316#include "webkit/browser/blob/local_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]c6f9203a2013-05-28 02:08:0719#include "webkit/browser/fileapi/file_system_context.h"
20#include "webkit/browser/fileapi/file_system_file_stream_reader.h"
21#include "webkit/browser/fileapi/file_system_operation_context.h"
[email protected]61b48e02013-08-01 15:00:1022#include "webkit/browser/fileapi/file_system_operation_impl.h"
[email protected]f25e1132013-05-24 13:58:0423#include "webkit/browser/fileapi/isolated_context.h"
[email protected]5a20d042013-05-22 12:54:1824#include "webkit/browser/fileapi/isolated_file_util.h"
[email protected]c6f9203a2013-05-28 02:08:0725#include "webkit/browser/fileapi/local_file_stream_writer.h"
[email protected]5a20d042013-05-22 12:54:1826#include "webkit/browser/fileapi/native_file_util.h"
27#include "webkit/browser/fileapi/transient_file_util.h"
[email protected]61d271f32013-05-28 04:59:2328#include "webkit/common/fileapi/file_system_types.h"
29#include "webkit/common/fileapi/file_system_util.h"
[email protected]6fe69652012-04-02 09:35:0530
[email protected]6fe69652012-04-02 09:35:0531namespace fileapi {
32
[email protected]f19bbf62013-07-09 01:22:3233IsolatedFileSystemBackend::IsolatedFileSystemBackend()
[email protected]c3d638b32013-04-22 02:18:4934 : isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())),
[email protected]b2582862013-05-14 08:50:1835 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())),
36 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) {
[email protected]6fe69652012-04-02 09:35:0537}
38
[email protected]f19bbf62013-07-09 01:22:3239IsolatedFileSystemBackend::~IsolatedFileSystemBackend() {
[email protected]6fe69652012-04-02 09:35:0540}
41
[email protected]f19bbf62013-07-09 01:22:3242bool IsolatedFileSystemBackend::CanHandleType(FileSystemType type) const {
[email protected]420fb562013-04-18 01:46:3443 switch (type) {
44 case kFileSystemTypeIsolated:
45 case kFileSystemTypeDragged:
[email protected]b2582862013-05-14 08:50:1846 case kFileSystemTypeForTransientFile:
[email protected]420fb562013-04-18 01:46:3447 return true;
48#if !defined(OS_CHROMEOS)
49 case kFileSystemTypeNativeLocal:
50 case kFileSystemTypeNativeForPlatformApp:
51 return true;
52#endif
53 default:
54 return false;
55 }
56}
57
[email protected]3fc17aed2013-07-24 10:01:5058void IsolatedFileSystemBackend::Initialize(FileSystemContext* context) {
59}
60
61void IsolatedFileSystemBackend::OpenFileSystem(
[email protected]6fe69652012-04-02 09:35:0562 const GURL& origin_url,
63 FileSystemType type,
[email protected]22dea52c2013-05-29 07:44:4064 OpenFileSystemMode mode,
[email protected]3fc17aed2013-07-24 10:01:5065 const OpenFileSystemCallback& callback) {
[email protected]6fe69652012-04-02 09:35:0566 // We never allow opening a new isolated FileSystem via usual OpenFileSystem.
67 base::MessageLoopProxy::current()->PostTask(
68 FROM_HERE,
[email protected]a836883d2013-07-12 03:50:0269 base::Bind(callback,
70 GetFileSystemRootURI(origin_url, type),
71 GetFileSystemName(origin_url, type),
72 base::PLATFORM_FILE_ERROR_SECURITY));
[email protected]6fe69652012-04-02 09:35:0573}
74
[email protected]f19bbf62013-07-09 01:22:3275FileSystemFileUtil* IsolatedFileSystemBackend::GetFileUtil(
[email protected]d6afd112012-07-25 22:55:0476 FileSystemType type) {
[email protected]6ef35d62012-08-02 02:55:2877 switch (type) {
[email protected]9fb9294a2012-08-21 14:55:3778 case kFileSystemTypeNativeLocal:
[email protected]25b697992013-01-29 07:10:0579 return isolated_file_util_->sync_file_util();
80 case kFileSystemTypeDragged:
81 return dragged_file_util_->sync_file_util();
[email protected]b2582862013-05-14 08:50:1882 case kFileSystemTypeForTransientFile:
83 return transient_file_util_->sync_file_util();
[email protected]25b697992013-01-29 07:10:0584 default:
85 NOTREACHED();
86 }
87 return NULL;
88}
89
[email protected]f19bbf62013-07-09 01:22:3290AsyncFileUtil* IsolatedFileSystemBackend::GetAsyncFileUtil(
[email protected]25b697992013-01-29 07:10:0591 FileSystemType type) {
92 switch (type) {
93 case kFileSystemTypeNativeLocal:
[email protected]6ef35d62012-08-02 02:55:2894 return isolated_file_util_.get();
95 case kFileSystemTypeDragged:
96 return dragged_file_util_.get();
[email protected]b2582862013-05-14 08:50:1897 case kFileSystemTypeForTransientFile:
98 return transient_file_util_.get();
[email protected]9fb9294a2012-08-21 14:55:3799 default:
[email protected]6ef35d62012-08-02 02:55:28100 NOTREACHED();
101 }
102 return NULL;
[email protected]6fe69652012-04-02 09:35:05103}
104
[email protected]98407ee2013-04-04 08:52:17105CopyOrMoveFileValidatorFactory*
[email protected]f19bbf62013-07-09 01:22:32106IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
[email protected]98407ee2013-04-04 08:52:17107 FileSystemType type, base::PlatformFileError* error_code) {
108 DCHECK(error_code);
109 *error_code = base::PLATFORM_FILE_OK;
[email protected]98407ee2013-04-04 08:52:17110 return NULL;
111}
112
[email protected]f19bbf62013-07-09 01:22:32113FileSystemOperation* IsolatedFileSystemBackend::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09114 const FileSystemURL& url,
[email protected]d23a00cc2012-09-11 17:38:13115 FileSystemContext* context,
116 base::PlatformFileError* error_code) const {
[email protected]61b48e02013-08-01 15:00:10117 return new FileSystemOperationImpl(
[email protected]5dfa47c2013-06-10 04:57:15118 url, context, make_scoped_ptr(new FileSystemOperationContext(context)));
[email protected]6fe69652012-04-02 09:35:05119}
120
[email protected]3ee9eb02013-04-10 09:17:05121scoped_ptr<webkit_blob::FileStreamReader>
[email protected]f19bbf62013-07-09 01:22:32122IsolatedFileSystemBackend::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09123 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19124 int64 offset,
[email protected]a1057832012-10-15 13:28:06125 const base::Time& expected_modification_time,
[email protected]ad117b12012-04-19 05:40:19126 FileSystemContext* context) const {
[email protected]3ee9eb02013-04-10 09:17:05127 return scoped_ptr<webkit_blob::FileStreamReader>(
128 new webkit_blob::LocalFileStreamReader(
[email protected]8dd68f82013-08-04 08:02:44129 context->default_file_task_runner(),
[email protected]3ee9eb02013-04-10 09:17:05130 url.path(), offset, expected_modification_time));
[email protected]ad117b12012-04-19 05:40:19131}
132
[email protected]f19bbf62013-07-09 01:22:32133scoped_ptr<FileStreamWriter> IsolatedFileSystemBackend::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09134 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01135 int64 offset,
136 FileSystemContext* context) const {
[email protected]b3d90122013-06-20 22:55:02137 return scoped_ptr<FileStreamWriter>(new LocalFileStreamWriter(
[email protected]8dd68f82013-08-04 08:02:44138 context->default_file_task_runner(), url.path(), offset));
[email protected]7e84b912012-05-16 04:42:01139}
140
[email protected]f19bbf62013-07-09 01:22:32141FileSystemQuotaUtil* IsolatedFileSystemBackend::GetQuotaUtil() {
[email protected]6faad822012-05-11 12:58:29142 // No quota support.
143 return NULL;
144}
145
[email protected]6fe69652012-04-02 09:35:05146} // namespace fileapi