Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / storage / browser / fileapi / isolated_file_system_backend.cc
blob6ecc9e212ba221286aa0e92072c7de53287d5c4b
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/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"
30 namespace storage {
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 {
46 switch (type) {
47 case kFileSystemTypeIsolated:
48 case kFileSystemTypeDragged:
49 case kFileSystemTypeForTransientFile:
50 return true;
51 case kFileSystemTypeNativeLocal:
52 return use_for_type_native_local_;
53 case kFileSystemTypeNativeForPlatformApp:
54 return use_for_type_platform_app_;
55 default:
56 return false;
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(
69 FROM_HERE,
70 base::Bind(callback,
71 GURL(),
72 std::string(),
73 base::File::FILE_ERROR_SECURITY));
76 AsyncFileUtil* IsolatedFileSystemBackend::GetAsyncFileUtil(
77 FileSystemType type) {
78 switch (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();
85 default:
86 NOTREACHED();
88 return NULL;
91 WatcherManager* IsolatedFileSystemBackend::GetWatcherManager(
92 FileSystemType type) {
93 return NULL;
96 CopyOrMoveFileValidatorFactory*
97 IsolatedFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
98 FileSystemType type, base::File::Error* error_code) {
99 DCHECK(error_code);
100 *error_code = base::File::FILE_OK;
101 return NULL;
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 {
114 return false;
117 bool IsolatedFileSystemBackend::HasInplaceCopyImplementation(
118 storage::FileSystemType type) const {
119 DCHECK(type == kFileSystemTypeNativeLocal || type == kFileSystemTypeDragged ||
120 type == kFileSystemTypeForTransientFile);
121 return false;
124 scoped_ptr<storage::FileStreamReader>
125 IsolatedFileSystemBackend::CreateFileStreamReader(
126 const FileSystemURL& url,
127 int64 offset,
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(),
134 url.path(),
135 offset,
136 expected_modification_time));
139 scoped_ptr<FileStreamWriter> IsolatedFileSystemBackend::CreateFileStreamWriter(
140 const FileSystemURL& url,
141 int64 offset,
142 FileSystemContext* context) const {
143 return scoped_ptr<FileStreamWriter>(
144 FileStreamWriter::CreateForLocalFile(
145 context->default_file_task_runner(),
146 url.path(),
147 offset,
148 FileStreamWriter::OPEN_EXISTING_FILE));
151 FileSystemQuotaUtil* IsolatedFileSystemBackend::GetQuotaUtil() {
152 // No quota support.
153 return NULL;
156 const UpdateObserverList* IsolatedFileSystemBackend::GetUpdateObservers(
157 FileSystemType type) const {
158 return NULL;
161 const ChangeObserverList* IsolatedFileSystemBackend::GetChangeObservers(
162 FileSystemType type) const {
163 return NULL;
166 const AccessObserverList* IsolatedFileSystemBackend::GetAccessObservers(
167 FileSystemType type) const {
168 return NULL;
171 } // namespace storage