OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/filesystem/DOMFileSystem.h" | 32 #include "modules/filesystem/DOMFileSystem.h" |
33 | 33 |
34 #include "core/fileapi/File.h" | |
35 #include "modules/filesystem/DOMFilePath.h" | 34 #include "modules/filesystem/DOMFilePath.h" |
36 #include "modules/filesystem/DirectoryEntry.h" | 35 #include "modules/filesystem/DirectoryEntry.h" |
37 #include "modules/filesystem/ErrorCallback.h" | 36 #include "modules/filesystem/ErrorCallback.h" |
38 #include "modules/filesystem/FileCallback.h" | 37 #include "modules/filesystem/FileCallback.h" |
39 #include "modules/filesystem/FileEntry.h" | 38 #include "modules/filesystem/FileEntry.h" |
40 #include "modules/filesystem/FileSystemCallbacks.h" | 39 #include "modules/filesystem/FileSystemCallbacks.h" |
41 #include "modules/filesystem/FileWriter.h" | 40 #include "modules/filesystem/FileWriter.h" |
42 #include "modules/filesystem/FileWriterBaseCallback.h" | 41 #include "modules/filesystem/FileWriterBaseCallback.h" |
43 #include "modules/filesystem/FileWriterCallback.h" | 42 #include "modules/filesystem/FileWriterCallback.h" |
44 #include "modules/filesystem/MetadataCallback.h" | 43 #include "modules/filesystem/MetadataCallback.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassOwnPtr<FileWrit
erCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback) | 145 void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassOwnPtr<FileWrit
erCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
147 { | 146 { |
148 ASSERT(fileEntry); | 147 ASSERT(fileEntry); |
149 | 148 |
150 FileWriter* fileWriter = FileWriter::create(executionContext()); | 149 FileWriter* fileWriter = FileWriter::create(executionContext()); |
151 OwnPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb
ack::create(successCallback); | 150 OwnPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb
ack::create(successCallback); |
152 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create
(fileWriter, conversionCallback.release(), errorCallback, m_context); | 151 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create
(fileWriter, conversionCallback.release(), errorCallback, m_context); |
153 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter, c
allbacks.release()); | 152 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter, c
allbacks.release()); |
154 } | 153 } |
155 | 154 |
156 namespace { | |
157 | |
158 class SnapshotFileCallback : public FileSystemCallbacksBase { | |
159 public: | |
160 static PassOwnPtr<AsyncFileSystemCallbacks> create(DOMFileSystem* filesystem
, const String& name, const KURL& url, PassOwnPtr<FileCallback> successCallback,
PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext* context) | |
161 { | |
162 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new SnapshotFileC
allback(filesystem, name, url, successCallback, errorCallback, context))); | |
163 } | |
164 | |
165 virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<
BlobDataHandle> snapshot) | |
166 { | |
167 if (!m_successCallback) | |
168 return; | |
169 | |
170 // We can't directly use the snapshot blob data handle because the conte
nt type on it hasn't been set. | |
171 // The |snapshot| param is here to provide a a chain of custody thru thr
ead bridging that is held onto until | |
172 // *after* we've coined a File with a new handle that has the correct ty
pe set on it. This allows the | |
173 // blob storage system to track when a temp file can and can't be safely
deleted. | |
174 | |
175 // For regular filesystem types (temporary or persistent), we should not
cache file metadata as it could change File semantics. | |
176 // For other filesystem types (which could be platform-specific ones), t
here's a chance that the files are on remote filesystem. If the port has returne
d metadata just pass it to File constructor (so we may cache the metadata). | |
177 // FIXME: We should use the snapshot metadata for all files. | |
178 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746 | |
179 if (m_fileSystem->type() == FileSystemTypeTemporary || m_fileSystem->typ
e() == FileSystemTypePersistent) { | |
180 m_successCallback->handleEvent(File::createWithName(metadata.platfor
mPath, m_name).get()); | |
181 } else if (!metadata.platformPath.isEmpty()) { | |
182 // If the platformPath in the returned metadata is given, we create
a File object for the path. | |
183 m_successCallback->handleEvent(File::createForFileSystemFile(m_name,
metadata).get()); | |
184 } else { | |
185 // Otherwise create a File from the FileSystem URL. | |
186 m_successCallback->handleEvent(File::createForFileSystemFile(m_url,
metadata).get()); | |
187 } | |
188 | |
189 m_successCallback.release(); | |
190 } | |
191 | |
192 private: | |
193 SnapshotFileCallback(DOMFileSystem* filesystem, const String& name, const KU
RL& url, PassOwnPtr<FileCallback> successCallback, PassOwnPtr<ErrorCallback> err
orCallback, ExecutionContext* context) | |
194 : FileSystemCallbacksBase(errorCallback, filesystem, context) | |
195 , m_name(name) | |
196 , m_url(url) | |
197 , m_successCallback(successCallback) | |
198 { | |
199 } | |
200 | |
201 String m_name; | |
202 KURL m_url; | |
203 OwnPtr<FileCallback> m_successCallback; | |
204 }; | |
205 | |
206 } // namespace | |
207 | |
208 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassOwnPtr<FileCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) | 155 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassOwnPtr<FileCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback) |
209 { | 156 { |
210 KURL fileSystemURL = createFileSystemURL(fileEntry); | 157 KURL fileSystemURL = createFileSystemURL(fileEntry); |
211 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileC
allback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCa
llback, m_context)); | 158 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileC
allback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCa
llback, m_context)); |
212 } | 159 } |
213 | 160 |
214 } // namespace WebCore | 161 } // namespace WebCore |
OLD | NEW |