PPAPI: Add C++ wrapper for MessageHandler stuff.
[chromium-blink-merge.git] / storage / browser / fileapi / isolated_file_system_backend.cc
blobc9b31d3fa04b5f614bbb781f127800f9ce69f4c2
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"
7 #include <string>
9 #include "base/bind.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"
30 namespace storage {
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 {
42 switch (type) {
43 case kFileSystemTypeIsolated:
44 case kFileSystemTypeDragged:
45 case kFileSystemTypeForTransientFile:
46 return true;
47 #if !defined(OS_CHROMEOS)
48 case kFileSystemTypeNativeLocal:
49 case kFileSystemTypeNativeForPlatformApp:
50 return true;
51 #endif
52 default:
53 return false;
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(
66 FROM_HERE,
67 base::Bind(callback,
68 GURL(),
69 std::string(),
70 base::File::FILE_ERROR_SECURITY));
73 AsyncFileUtil* IsolatedFileSystemBackend::GetAsyncFileUtil(
74 FileSystemType type) {
75 switch (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();
82 default:
83 NOTREACHED();
85 return NULL;
88 WatcherManager* IsolatedFileSystemBackend::GetWatcherManager(
89 FileSystemType type) {
90 return NULL;
93 CopyOrMoveFileValidatorFactory*
94 IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
95 FileSystemType type, base::File::Error* error_code) {
96 DCHECK(error_code);
97 *error_code = base::File::FILE_OK;
98 return NULL;
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 {
111 return false;
114 bool IsolatedFileSystemBackend::HasInplaceCopyImplementation(
115 storage::FileSystemType type) const {
116 DCHECK(type == kFileSystemTypeNativeLocal || type == kFileSystemTypeDragged ||
117 type == kFileSystemTypeForTransientFile);
118 return false;
121 scoped_ptr<storage::FileStreamReader>
122 IsolatedFileSystemBackend::CreateFileStreamReader(
123 const FileSystemURL& url,
124 int64 offset,
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(),
131 url.path(),
132 offset,
133 expected_modification_time));
136 scoped_ptr<FileStreamWriter> IsolatedFileSystemBackend::CreateFileStreamWriter(
137 const FileSystemURL& url,
138 int64 offset,
139 FileSystemContext* context) const {
140 return scoped_ptr<FileStreamWriter>(
141 FileStreamWriter::CreateForLocalFile(
142 context->default_file_task_runner(),
143 url.path(),
144 offset,
145 FileStreamWriter::OPEN_EXISTING_FILE));
148 FileSystemQuotaUtil* IsolatedFileSystemBackend::GetQuotaUtil() {
149 // No quota support.
150 return NULL;
153 const UpdateObserverList* IsolatedFileSystemBackend::GetUpdateObservers(
154 FileSystemType type) const {
155 return NULL;
158 const ChangeObserverList* IsolatedFileSystemBackend::GetChangeObservers(
159 FileSystemType type) const {
160 return NULL;
163 const AccessObserverList* IsolatedFileSystemBackend::GetAccessObservers(
164 FileSystemType type) const {
165 return NULL;
168 } // namespace storage