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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 ASSERT(fileEntry); | 141 ASSERT(fileEntry); |
142 | 142 |
143 RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext())
; | 143 RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext())
; |
144 RefPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb
ack::create(successCallback); | 144 RefPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb
ack::create(successCallback); |
145 OwnPtr<FileWriterBaseCallbacks> callbacks = FileWriterBaseCallbacks::create(
fileWriter, conversionCallback, errorCallback); | 145 OwnPtr<FileWriterBaseCallbacks> callbacks = FileWriterBaseCallbacks::create(
fileWriter, conversionCallback, errorCallback); |
146 m_asyncFileSystem->createWriter(fileWriter.get(), createFileSystemURL(fileEn
try), callbacks.release()); | 146 m_asyncFileSystem->createWriter(fileWriter.get(), createFileSystemURL(fileEn
try), callbacks.release()); |
147 } | 147 } |
148 | 148 |
149 namespace { | 149 namespace { |
150 | 150 |
151 class GetMetadataCallback : public FileSystemCallbacksBase { | 151 class SnapshotFileCallback : public FileSystemCallbacksBase { |
152 public: | 152 public: |
153 static PassOwnPtr<GetMetadataCallback> create(PassRefPtr<DOMFileSystem> file
system, const String& name, const KURL& url, PassRefPtr<FileCallback> successCal
lback, PassRefPtr<ErrorCallback> errorCallback) | 153 static PassOwnPtr<SnapshotFileCallback> create(PassRefPtr<DOMFileSystem> fil
esystem, const String& name, const KURL& url, PassRefPtr<FileCallback> successCa
llback, PassRefPtr<ErrorCallback> errorCallback) |
154 { | 154 { |
155 return adoptPtr(new GetMetadataCallback(filesystem, name, url, successCa
llback, errorCallback)); | 155 return adoptPtr(new SnapshotFileCallback(filesystem, name, url, successC
allback, errorCallback)); |
156 } | 156 } |
157 | 157 |
158 virtual void didReadMetadata(const FileMetadata& metadata) | 158 virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<
BlobDataHandle> snapshot) |
159 { | 159 { |
160 ASSERT(!metadata.platformPath.isEmpty()); | 160 ASSERT(!metadata.platformPath.isEmpty()); |
161 if (!m_successCallback) | 161 if (!m_successCallback) |
162 return; | 162 return; |
163 | 163 |
| 164 // We can't directly use the snapshot blob data handle because the conte
nt type on it hasn't been set. |
| 165 // The |snapshot| param is here to provide a a chain of custody thru thr
ead bridging that is held onto until |
| 166 // *after* we've coined a File with a new handle that has the correct ty
pe set on it. This allows the |
| 167 // blob storage system to track when a temp file can and can't be safely
deleted. |
| 168 |
164 // For regular filesystem types (temporary or persistent), we should not
cache file metadata as it could change File semantics. | 169 // For regular filesystem types (temporary or persistent), we should not
cache file metadata as it could change File semantics. |
165 // 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). | 170 // 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). |
166 // FIXME: We should use the snapshot metadata for all files. | 171 // FIXME: We should use the snapshot metadata for all files. |
167 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746 | 172 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746 |
168 if (m_filesystem->type() == FileSystemTypeTemporary || m_filesystem->typ
e() == FileSystemTypePersistent) { | 173 if (m_filesystem->type() == FileSystemTypeTemporary || m_filesystem->typ
e() == FileSystemTypePersistent) { |
169 m_successCallback->handleEvent(File::createWithName(metadata.platfor
mPath, m_name).get()); | 174 m_successCallback->handleEvent(File::createWithName(metadata.platfor
mPath, m_name).get()); |
170 } else if (!metadata.platformPath.isEmpty()) { | 175 } else if (!metadata.platformPath.isEmpty()) { |
171 // If the platformPath in the returned metadata is given, we create
a File object for the path. | 176 // If the platformPath in the returned metadata is given, we create
a File object for the path. |
172 m_successCallback->handleEvent(File::createForFileSystemFile(m_name,
metadata).get()); | 177 m_successCallback->handleEvent(File::createForFileSystemFile(m_name,
metadata).get()); |
173 } else { | 178 } else { |
174 // Otherwise create a File from the FileSystem URL. | 179 // Otherwise create a File from the FileSystem URL. |
175 m_successCallback->handleEvent(File::createForFileSystemFile(m_url,
metadata).get()); | 180 m_successCallback->handleEvent(File::createForFileSystemFile(m_url,
metadata).get()); |
176 } | 181 } |
177 | 182 |
178 m_successCallback.release(); | 183 m_successCallback.release(); |
179 } | 184 } |
180 | 185 |
181 private: | 186 private: |
182 GetMetadataCallback(PassRefPtr<DOMFileSystem> filesystem, const String& name
, const KURL& url, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCa
llback> errorCallback) | 187 SnapshotFileCallback(PassRefPtr<DOMFileSystem> filesystem, const String& nam
e, const KURL& url, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorC
allback> errorCallback) |
183 : FileSystemCallbacksBase(errorCallback) | 188 : FileSystemCallbacksBase(errorCallback) |
184 , m_filesystem(filesystem) | 189 , m_filesystem(filesystem) |
185 , m_name(name) | 190 , m_name(name) |
186 , m_url(url) | 191 , m_url(url) |
187 , m_successCallback(successCallback) | 192 , m_successCallback(successCallback) |
188 { | 193 { |
189 } | 194 } |
190 | 195 |
191 RefPtr<DOMFileSystem> m_filesystem; | 196 RefPtr<DOMFileSystem> m_filesystem; |
192 String m_name; | 197 String m_name; |
193 KURL m_url; | 198 KURL m_url; |
194 RefPtr<FileCallback> m_successCallback; | 199 RefPtr<FileCallback> m_successCallback; |
195 }; | 200 }; |
196 | 201 |
197 } // namespace | 202 } // namespace |
198 | 203 |
199 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallba
ck> successCallback, PassRefPtr<ErrorCallback> errorCallback) | 204 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallba
ck> successCallback, PassRefPtr<ErrorCallback> errorCallback) |
200 { | 205 { |
201 KURL fileSystemURL = createFileSystemURL(fileEntry); | 206 KURL fileSystemURL = createFileSystemURL(fileEntry); |
202 m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileSystemURL, GetMetad
ataCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, err
orCallback)); | 207 m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileSystemURL, Snapshot
FileCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, er
rorCallback)); |
203 } | 208 } |
204 | 209 |
205 } // namespace WebCore | 210 } // namespace WebCore |
206 | 211 |
207 #endif // ENABLE(FILE_SYSTEM) | 212 #endif // ENABLE(FILE_SYSTEM) |
OLD | NEW |