Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/FileSystemBase.cpp

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 "modules/filesystem/DOMFileSystemBase.h" 31 #include "modules/filesystem/FileSystemBase.h"
32 32
33 #include "core/dom/ExecutionContext.h" 33 #include "core/dom/ExecutionContext.h"
34 #include "core/fileapi/File.h" 34 #include "core/fileapi/File.h"
35 #include "core/fileapi/FileError.h" 35 #include "core/fileapi/FileError.h"
36 #include "core/html/VoidCallback.h" 36 #include "core/html/VoidCallback.h"
37 #include "modules/filesystem/DOMFilePath.h" 37 #include "modules/filesystem/DOMFilePath.h"
38 #include "modules/filesystem/DirectoryEntry.h"
39 #include "modules/filesystem/DirectoryReaderBase.h"
40 #include "modules/filesystem/EntriesCallback.h"
41 #include "modules/filesystem/Entry.h"
42 #include "modules/filesystem/EntryBase.h"
43 #include "modules/filesystem/EntryCallback.h"
44 #include "modules/filesystem/FileSystemCallbacks.h" 38 #include "modules/filesystem/FileSystemCallbacks.h"
45 #include "modules/filesystem/MetadataCallback.h" 39 #include "modules/filesystem/FileSystemDirectoryEntry.h"
40 #include "modules/filesystem/FileSystemDirectoryReaderBase.h"
41 #include "modules/filesystem/FileSystemEntriesCallback.h"
42 #include "modules/filesystem/FileSystemEntry.h"
43 #include "modules/filesystem/FileSystemEntryBase.h"
44 #include "modules/filesystem/FileSystemEntryCallback.h"
45 #include "modules/filesystem/FileSystemMetadataCallback.h"
46 #include "platform/weborigin/SecurityOrigin.h" 46 #include "platform/weborigin/SecurityOrigin.h"
47 #include "public/platform/Platform.h" 47 #include "public/platform/Platform.h"
48 #include "public/platform/WebFileSystem.h" 48 #include "public/platform/WebFileSystem.h"
49 #include "public/platform/WebFileSystemCallbacks.h" 49 #include "public/platform/WebFileSystemCallbacks.h"
50 #include "wtf/text/StringBuilder.h" 50 #include "wtf/text/StringBuilder.h"
51 #include "wtf/text/TextEncoding.h" 51 #include "wtf/text/TextEncoding.h"
52 #include <memory> 52 #include <memory>
53 53
54 namespace blink { 54 namespace blink {
55 55
56 const char DOMFileSystemBase::persistentPathPrefix[] = "persistent"; 56 const char FileSystemBase::persistentPathPrefix[] = "persistent";
57 const char DOMFileSystemBase::temporaryPathPrefix[] = "temporary"; 57 const char FileSystemBase::temporaryPathPrefix[] = "temporary";
58 const char DOMFileSystemBase::isolatedPathPrefix[] = "isolated"; 58 const char FileSystemBase::isolatedPathPrefix[] = "isolated";
59 const char DOMFileSystemBase::externalPathPrefix[] = "external"; 59 const char FileSystemBase::externalPathPrefix[] = "external";
60 60
61 DOMFileSystemBase::DOMFileSystemBase(ExecutionContext* context, 61 FileSystemBase::FileSystemBase(ExecutionContext* context,
62 const String& name, 62 const String& name,
63 FileSystemType type, 63 FileSystemType type,
64 const KURL& rootURL) 64 const KURL& rootURL)
65 : m_context(context), 65 : m_context(context),
66 m_name(name), 66 m_name(name),
67 m_type(type), 67 m_type(type),
68 m_filesystemRootURL(rootURL), 68 m_filesystemRootURL(rootURL),
69 m_clonable(false) {} 69 m_clonable(false) {}
70 70
71 DOMFileSystemBase::~DOMFileSystemBase() {} 71 FileSystemBase::~FileSystemBase() {}
72 72
73 DEFINE_TRACE(DOMFileSystemBase) { 73 DEFINE_TRACE(FileSystemBase) {
74 visitor->trace(m_context); 74 visitor->trace(m_context);
75 } 75 }
76 76
77 WebFileSystem* DOMFileSystemBase::fileSystem() const { 77 WebFileSystem* FileSystemBase::fileSystem() const {
78 Platform* platform = Platform::current(); 78 Platform* platform = Platform::current();
79 if (!platform) 79 if (!platform)
80 return nullptr; 80 return nullptr;
81 return platform->fileSystem(); 81 return platform->fileSystem();
82 } 82 }
83 83
84 SecurityOrigin* DOMFileSystemBase::getSecurityOrigin() const { 84 SecurityOrigin* FileSystemBase::getSecurityOrigin() const {
85 return m_context->getSecurityOrigin(); 85 return m_context->getSecurityOrigin();
86 } 86 }
87 87
88 bool DOMFileSystemBase::isValidType(FileSystemType type) { 88 bool FileSystemBase::isValidType(FileSystemType type) {
89 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent || 89 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent ||
90 type == FileSystemTypeIsolated || type == FileSystemTypeExternal; 90 type == FileSystemTypeIsolated || type == FileSystemTypeExternal;
91 } 91 }
92 92
93 KURL DOMFileSystemBase::createFileSystemRootURL(const String& origin, 93 KURL FileSystemBase::createFileSystemRootURL(const String& origin,
94 FileSystemType type) { 94 FileSystemType type) {
95 String typeString; 95 String typeString;
96 if (type == FileSystemTypeTemporary) 96 if (type == FileSystemTypeTemporary)
97 typeString = temporaryPathPrefix; 97 typeString = temporaryPathPrefix;
98 else if (type == FileSystemTypePersistent) 98 else if (type == FileSystemTypePersistent)
99 typeString = persistentPathPrefix; 99 typeString = persistentPathPrefix;
100 else if (type == FileSystemTypeExternal) 100 else if (type == FileSystemTypeExternal)
101 typeString = externalPathPrefix; 101 typeString = externalPathPrefix;
102 else 102 else
103 return KURL(); 103 return KURL();
104 104
105 String result = "filesystem:" + origin + "/" + typeString + "/"; 105 String result = "filesystem:" + origin + "/" + typeString + "/";
106 return KURL(ParsedURLString, result); 106 return KURL(ParsedURLString, result);
107 } 107 }
108 108
109 bool DOMFileSystemBase::supportsToURL() const { 109 bool FileSystemBase::supportsToURL() const {
110 ASSERT(isValidType(m_type)); 110 DCHECK(isValidType(m_type));
111 return m_type != FileSystemTypeIsolated; 111 return m_type != FileSystemTypeIsolated;
112 } 112 }
113 113
114 KURL DOMFileSystemBase::createFileSystemURL(const EntryBase* entry) const { 114 KURL FileSystemBase::createFileSystemURL(
115 const FileSystemEntryBase* entry) const {
115 return createFileSystemURL(entry->fullPath()); 116 return createFileSystemURL(entry->fullPath());
116 } 117 }
117 118
118 KURL DOMFileSystemBase::createFileSystemURL(const String& fullPath) const { 119 KURL FileSystemBase::createFileSystemURL(const String& fullPath) const {
119 ASSERT(DOMFilePath::isAbsolute(fullPath)); 120 DCHECK(DOMFilePath::isAbsolute(fullPath));
120 121
121 if (type() == FileSystemTypeExternal) { 122 if (type() == FileSystemTypeExternal) {
122 // For external filesystem originString could be different from what we have 123 // For external filesystem originString could be different from what we have
123 // in m_filesystemRootURL. 124 // in m_filesystemRootURL.
124 StringBuilder result; 125 StringBuilder result;
125 result.append("filesystem:"); 126 result.append("filesystem:");
126 result.append(getSecurityOrigin()->toString()); 127 result.append(getSecurityOrigin()->toString());
127 result.append('/'); 128 result.append('/');
128 result.append(externalPathPrefix); 129 result.append(externalPathPrefix);
129 result.append(m_filesystemRootURL.path()); 130 result.append(m_filesystemRootURL.path());
130 // Remove the extra leading slash. 131 // Remove the extra leading slash.
131 result.append(encodeWithURLEscapeSequences(fullPath.substring(1))); 132 result.append(encodeWithURLEscapeSequences(fullPath.substring(1)));
132 return KURL(ParsedURLString, result.toString()); 133 return KURL(ParsedURLString, result.toString());
133 } 134 }
134 135
135 // For regular types we can just append the entry's fullPath to the 136 // For regular types we can just append the entry's fullPath to the
136 // m_filesystemRootURL that should look like 137 // m_filesystemRootURL that should look like
137 // 'filesystem:<origin>/<typePrefix>'. 138 // 'filesystem:<origin>/<typePrefix>'.
138 ASSERT(!m_filesystemRootURL.isEmpty()); 139 DCHECK(!m_filesystemRootURL.isEmpty());
139 KURL url = m_filesystemRootURL; 140 KURL url = m_filesystemRootURL;
140 // Remove the extra leading slash. 141 // Remove the extra leading slash.
141 url.setPath(url.path() + encodeWithURLEscapeSequences(fullPath.substring(1))); 142 url.setPath(url.path() + encodeWithURLEscapeSequences(fullPath.substring(1)));
142 return url; 143 return url;
143 } 144 }
144 145
145 bool DOMFileSystemBase::pathToAbsolutePath(FileSystemType type, 146 bool FileSystemBase::pathToAbsolutePath(FileSystemType type,
146 const EntryBase* base, 147 const FileSystemEntryBase* base,
147 String path, 148 String path,
148 String& absolutePath) { 149 String& absolutePath) {
149 ASSERT(base); 150 DCHECK(base);
150 151
151 if (!DOMFilePath::isAbsolute(path)) 152 if (!DOMFilePath::isAbsolute(path))
152 path = DOMFilePath::append(base->fullPath(), path); 153 path = DOMFilePath::append(base->fullPath(), path);
153 absolutePath = DOMFilePath::removeExtraParentReferences(path); 154 absolutePath = DOMFilePath::removeExtraParentReferences(path);
154 155
155 return (type != FileSystemTypeTemporary && 156 return (type != FileSystemTypeTemporary &&
156 type != FileSystemTypePersistent) || 157 type != FileSystemTypePersistent) ||
157 DOMFilePath::isValidPath(absolutePath); 158 DOMFilePath::isValidPath(absolutePath);
158 } 159 }
159 160
160 bool DOMFileSystemBase::pathPrefixToFileSystemType(const String& pathPrefix, 161 bool FileSystemBase::pathPrefixToFileSystemType(const String& pathPrefix,
161 FileSystemType& type) { 162 FileSystemType& type) {
162 if (pathPrefix == temporaryPathPrefix) { 163 if (pathPrefix == temporaryPathPrefix) {
163 type = FileSystemTypeTemporary; 164 type = FileSystemTypeTemporary;
164 return true; 165 return true;
165 } 166 }
166 167
167 if (pathPrefix == persistentPathPrefix) { 168 if (pathPrefix == persistentPathPrefix) {
168 type = FileSystemTypePersistent; 169 type = FileSystemTypePersistent;
169 return true; 170 return true;
170 } 171 }
171 172
172 if (pathPrefix == externalPathPrefix) { 173 if (pathPrefix == externalPathPrefix) {
173 type = FileSystemTypeExternal; 174 type = FileSystemTypeExternal;
174 return true; 175 return true;
175 } 176 }
176 177
177 return false; 178 return false;
178 } 179 }
179 180
180 File* DOMFileSystemBase::createFile(const FileMetadata& metadata, 181 File* FileSystemBase::createFile(const FileMetadata& metadata,
181 const KURL& fileSystemURL, 182 const KURL& fileSystemURL,
182 FileSystemType type, 183 FileSystemType type,
183 const String name) { 184 const String name) {
184 // For regular filesystem types (temporary or persistent), we should not cache 185 // For regular filesystem types (temporary or persistent), we should not cache
185 // file metadata as it could change File semantics. For other filesystem 186 // file metadata as it could change File semantics. For other filesystem
186 // types (which could be platform-specific ones), there's a chance that the 187 // types (which could be platform-specific ones), there's a chance that the
187 // files are on remote filesystem. If the port has returned metadata just 188 // files are on remote filesystem. If the port has returned metadata just
188 // pass it to File constructor (so we may cache the metadata). 189 // pass it to File constructor (so we may cache the metadata).
189 // FIXME: We should use the snapshot metadata for all files. 190 // FIXME: We should use the snapshot metadata for all files.
190 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746 191 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746
191 if (type == FileSystemTypeTemporary || type == FileSystemTypePersistent) 192 if (type == FileSystemTypeTemporary || type == FileSystemTypePersistent)
192 return File::createForFileSystemFile(metadata.platformPath, name); 193 return File::createForFileSystemFile(metadata.platformPath, name);
193 194
194 const File::UserVisibility userVisibility = (type == FileSystemTypeExternal) 195 const File::UserVisibility userVisibility = (type == FileSystemTypeExternal)
195 ? File::IsUserVisible 196 ? File::IsUserVisible
196 : File::IsNotUserVisible; 197 : File::IsNotUserVisible;
197 198
198 if (!metadata.platformPath.isEmpty()) { 199 if (!metadata.platformPath.isEmpty()) {
199 // If the platformPath in the returned metadata is given, we create a File 200 // If the platformPath in the returned metadata is given, we create a File
200 // object for the snapshot path. 201 // object for the snapshot path.
201 return File::createForFileSystemFile(name, metadata, userVisibility); 202 return File::createForFileSystemFile(name, metadata, userVisibility);
202 } else {
203 // Otherwise we create a File object for the fileSystemURL.
204 return File::createForFileSystemFile(fileSystemURL, metadata,
205 userVisibility);
206 } 203 }
204
205 // Otherwise we create a File object for the fileSystemURL.
206 return File::createForFileSystemFile(fileSystemURL, metadata, userVisibility);
207 } 207 }
208 208
209 void DOMFileSystemBase::getMetadata(const EntryBase* entry, 209 void FileSystemBase::getMetadata(const FileSystemEntryBase* entry,
210 MetadataCallback* successCallback, 210 FileSystemMetadataCallback* successCallback,
211 ErrorCallbackBase* errorCallback, 211 ErrorCallbackBase* errorCallback,
212 SynchronousType synchronousType) { 212 SynchronousType synchronousType) {
213 if (!fileSystem()) { 213 if (!fileSystem()) {
214 reportError(errorCallback, FileError::kAbortErr); 214 reportError(errorCallback, FileError::kAbortErr);
215 return; 215 return;
216 } 216 }
217 217
218 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create( 218 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(
219 successCallback, errorCallback, m_context, this)); 219 successCallback, errorCallback, m_context, this));
220 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 220 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
221 fileSystem()->readMetadata(createFileSystemURL(entry), std::move(callbacks)); 221 fileSystem()->readMetadata(createFileSystemURL(entry), std::move(callbacks));
222 } 222 }
223 223
224 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, 224 static bool verifyAndGetDestinationPathForCopyOrMove(
225 EntryBase* parent, 225 const FileSystemEntryBase* source,
226 const String& newName, 226 FileSystemEntryBase* parent,
227 String& destinationPath) { 227 const String& newName,
228 ASSERT(source); 228 String& destinationPath) {
229 DCHECK(source);
229 230
230 if (!parent || !parent->isDirectory()) 231 if (!parent || !parent->isDirectory())
231 return false; 232 return false;
232 233
233 if (!newName.isEmpty() && !DOMFilePath::isValidName(newName)) 234 if (!newName.isEmpty() && !DOMFilePath::isValidName(newName))
234 return false; 235 return false;
235 236
236 const bool isSameFileSystem = 237 const bool isSameFileSystem =
237 (*source->filesystem() == *parent->filesystem()); 238 (*source->filesystem() == *parent->filesystem());
238 239
(...skipping 11 matching lines...) Expand all
250 251
251 destinationPath = parent->fullPath(); 252 destinationPath = parent->fullPath();
252 if (!newName.isEmpty()) 253 if (!newName.isEmpty())
253 destinationPath = DOMFilePath::append(destinationPath, newName); 254 destinationPath = DOMFilePath::append(destinationPath, newName);
254 else 255 else
255 destinationPath = DOMFilePath::append(destinationPath, source->name()); 256 destinationPath = DOMFilePath::append(destinationPath, source->name());
256 257
257 return true; 258 return true;
258 } 259 }
259 260
260 void DOMFileSystemBase::move(const EntryBase* source, 261 void FileSystemBase::move(const FileSystemEntryBase* source,
261 EntryBase* parent, 262 FileSystemEntryBase* parent,
262 const String& newName, 263 const String& newName,
263 EntryCallback* successCallback, 264 FileSystemEntryCallback* successCallback,
264 ErrorCallbackBase* errorCallback, 265 ErrorCallbackBase* errorCallback,
265 SynchronousType synchronousType) { 266 SynchronousType synchronousType) {
266 if (!fileSystem()) { 267 if (!fileSystem()) {
267 reportError(errorCallback, FileError::kAbortErr); 268 reportError(errorCallback, FileError::kAbortErr);
268 return; 269 return;
269 } 270 }
270 271
271 String destinationPath; 272 String destinationPath;
272 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, 273 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName,
273 destinationPath)) { 274 destinationPath)) {
274 reportError(errorCallback, FileError::kInvalidModificationErr); 275 reportError(errorCallback, FileError::kInvalidModificationErr);
275 return; 276 return;
276 } 277 }
277 278
278 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create( 279 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(
279 successCallback, errorCallback, m_context, parent->filesystem(), 280 successCallback, errorCallback, m_context, parent->filesystem(),
280 destinationPath, source->isDirectory())); 281 destinationPath, source->isDirectory()));
281 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 282 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
282 283
283 fileSystem()->move(createFileSystemURL(source), 284 fileSystem()->move(createFileSystemURL(source),
284 parent->filesystem()->createFileSystemURL(destinationPath), 285 parent->filesystem()->createFileSystemURL(destinationPath),
285 std::move(callbacks)); 286 std::move(callbacks));
286 } 287 }
287 288
288 void DOMFileSystemBase::copy(const EntryBase* source, 289 void FileSystemBase::copy(const FileSystemEntryBase* source,
289 EntryBase* parent, 290 FileSystemEntryBase* parent,
290 const String& newName, 291 const String& newName,
291 EntryCallback* successCallback, 292 FileSystemEntryCallback* successCallback,
292 ErrorCallbackBase* errorCallback, 293 ErrorCallbackBase* errorCallback,
293 SynchronousType synchronousType) { 294 SynchronousType synchronousType) {
294 if (!fileSystem()) { 295 if (!fileSystem()) {
295 reportError(errorCallback, FileError::kAbortErr); 296 reportError(errorCallback, FileError::kAbortErr);
296 return; 297 return;
297 } 298 }
298 299
299 String destinationPath; 300 String destinationPath;
300 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, 301 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName,
301 destinationPath)) { 302 destinationPath)) {
302 reportError(errorCallback, FileError::kInvalidModificationErr); 303 reportError(errorCallback, FileError::kInvalidModificationErr);
303 return; 304 return;
304 } 305 }
305 306
306 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create( 307 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(
307 successCallback, errorCallback, m_context, parent->filesystem(), 308 successCallback, errorCallback, m_context, parent->filesystem(),
308 destinationPath, source->isDirectory())); 309 destinationPath, source->isDirectory()));
309 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 310 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
310 311
311 fileSystem()->copy(createFileSystemURL(source), 312 fileSystem()->copy(createFileSystemURL(source),
312 parent->filesystem()->createFileSystemURL(destinationPath), 313 parent->filesystem()->createFileSystemURL(destinationPath),
313 std::move(callbacks)); 314 std::move(callbacks));
314 } 315 }
315 316
316 void DOMFileSystemBase::remove(const EntryBase* entry, 317 void FileSystemBase::remove(const FileSystemEntryBase* entry,
317 VoidCallback* successCallback, 318 VoidCallback* successCallback,
318 ErrorCallbackBase* errorCallback, 319 ErrorCallbackBase* errorCallback,
319 SynchronousType synchronousType) { 320 SynchronousType synchronousType) {
320 if (!fileSystem()) { 321 if (!fileSystem()) {
321 reportError(errorCallback, FileError::kAbortErr); 322 reportError(errorCallback, FileError::kAbortErr);
322 return; 323 return;
323 } 324 }
324 325
325 ASSERT(entry); 326 DCHECK(entry);
326 // We don't allow calling remove() on the root directory. 327 // We don't allow calling remove() on the root directory.
327 if (entry->fullPath() == String(DOMFilePath::root)) { 328 if (entry->fullPath() == String(DOMFilePath::root)) {
328 reportError(errorCallback, FileError::kInvalidModificationErr); 329 reportError(errorCallback, FileError::kInvalidModificationErr);
329 return; 330 return;
330 } 331 }
331 332
332 std::unique_ptr<AsyncFileSystemCallbacks> callbacks( 333 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(
333 VoidCallbacks::create(successCallback, errorCallback, m_context, this)); 334 VoidCallbacks::create(successCallback, errorCallback, m_context, this));
334 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 335 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
335 336
336 fileSystem()->remove(createFileSystemURL(entry), std::move(callbacks)); 337 fileSystem()->remove(createFileSystemURL(entry), std::move(callbacks));
337 } 338 }
338 339
339 void DOMFileSystemBase::removeRecursively(const EntryBase* entry, 340 void FileSystemBase::removeRecursively(const FileSystemEntryBase* entry,
340 VoidCallback* successCallback, 341 VoidCallback* successCallback,
341 ErrorCallbackBase* errorCallback, 342 ErrorCallbackBase* errorCallback,
342 SynchronousType synchronousType) { 343 SynchronousType synchronousType) {
343 if (!fileSystem()) { 344 if (!fileSystem()) {
344 reportError(errorCallback, FileError::kAbortErr); 345 reportError(errorCallback, FileError::kAbortErr);
345 return; 346 return;
346 } 347 }
347 348
348 ASSERT(entry && entry->isDirectory()); 349 DCHECK(entry && entry->isDirectory());
349 // We don't allow calling remove() on the root directory. 350 // We don't allow calling remove() on the root directory.
350 if (entry->fullPath() == String(DOMFilePath::root)) { 351 if (entry->fullPath() == String(DOMFilePath::root)) {
351 reportError(errorCallback, FileError::kInvalidModificationErr); 352 reportError(errorCallback, FileError::kInvalidModificationErr);
352 return; 353 return;
353 } 354 }
354 355
355 std::unique_ptr<AsyncFileSystemCallbacks> callbacks( 356 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(
356 VoidCallbacks::create(successCallback, errorCallback, m_context, this)); 357 VoidCallbacks::create(successCallback, errorCallback, m_context, this));
357 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 358 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
358 359
359 fileSystem()->removeRecursively(createFileSystemURL(entry), 360 fileSystem()->removeRecursively(createFileSystemURL(entry),
360 std::move(callbacks)); 361 std::move(callbacks));
361 } 362 }
362 363
363 void DOMFileSystemBase::getParent(const EntryBase* entry, 364 void FileSystemBase::getParent(const FileSystemEntryBase* entry,
364 EntryCallback* successCallback, 365 FileSystemEntryCallback* successCallback,
365 ErrorCallbackBase* errorCallback) { 366 ErrorCallbackBase* errorCallback) {
366 if (!fileSystem()) { 367 if (!fileSystem()) {
367 reportError(errorCallback, FileError::kAbortErr); 368 reportError(errorCallback, FileError::kAbortErr);
368 return; 369 return;
369 } 370 }
370 371
371 ASSERT(entry); 372 DCHECK(entry);
372 String path = DOMFilePath::getDirectory(entry->fullPath()); 373 String path = DOMFilePath::getDirectory(entry->fullPath());
373 374
374 fileSystem()->directoryExists( 375 fileSystem()->directoryExists(
375 createFileSystemURL(path), 376 createFileSystemURL(path),
376 EntryCallbacks::create(successCallback, errorCallback, m_context, this, 377 EntryCallbacks::create(successCallback, errorCallback, m_context, this,
377 path, true)); 378 path, true));
378 } 379 }
379 380
380 void DOMFileSystemBase::getFile(const EntryBase* entry, 381 void FileSystemBase::getFile(const FileSystemEntryBase* entry,
381 const String& path, 382 const String& path,
382 const FileSystemFlags& flags, 383 const FileSystemFlags& flags,
383 EntryCallback* successCallback, 384 FileSystemEntryCallback* successCallback,
384 ErrorCallbackBase* errorCallback, 385 ErrorCallbackBase* errorCallback,
385 SynchronousType synchronousType) { 386 SynchronousType synchronousType) {
386 if (!fileSystem()) { 387 if (!fileSystem()) {
387 reportError(errorCallback, FileError::kAbortErr); 388 reportError(errorCallback, FileError::kAbortErr);
388 return; 389 return;
389 } 390 }
390 391
391 String absolutePath; 392 String absolutePath;
392 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { 393 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) {
393 reportError(errorCallback, FileError::kInvalidModificationErr); 394 reportError(errorCallback, FileError::kInvalidModificationErr);
394 return; 395 return;
395 } 396 }
396 397
397 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create( 398 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(
398 successCallback, errorCallback, m_context, this, absolutePath, false)); 399 successCallback, errorCallback, m_context, this, absolutePath, false));
399 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 400 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
400 401
401 if (flags.createFlag()) 402 if (flags.createFlag()) {
402 fileSystem()->createFile(createFileSystemURL(absolutePath), 403 fileSystem()->createFile(createFileSystemURL(absolutePath),
403 flags.exclusive(), std::move(callbacks)); 404 flags.exclusive(), std::move(callbacks));
404 else 405 } else {
405 fileSystem()->fileExists(createFileSystemURL(absolutePath), 406 fileSystem()->fileExists(createFileSystemURL(absolutePath),
406 std::move(callbacks)); 407 std::move(callbacks));
408 }
407 } 409 }
408 410
409 void DOMFileSystemBase::getDirectory(const EntryBase* entry, 411 void FileSystemBase::getDirectory(const FileSystemEntryBase* entry,
410 const String& path, 412 const String& path,
411 const FileSystemFlags& flags, 413 const FileSystemFlags& flags,
412 EntryCallback* successCallback, 414 FileSystemEntryCallback* successCallback,
413 ErrorCallbackBase* errorCallback, 415 ErrorCallbackBase* errorCallback,
414 SynchronousType synchronousType) { 416 SynchronousType synchronousType) {
415 if (!fileSystem()) { 417 if (!fileSystem()) {
416 reportError(errorCallback, FileError::kAbortErr); 418 reportError(errorCallback, FileError::kAbortErr);
417 return; 419 return;
418 } 420 }
419 421
420 String absolutePath; 422 String absolutePath;
421 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) { 423 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) {
422 reportError(errorCallback, FileError::kInvalidModificationErr); 424 reportError(errorCallback, FileError::kInvalidModificationErr);
423 return; 425 return;
424 } 426 }
425 427
426 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create( 428 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(
427 successCallback, errorCallback, m_context, this, absolutePath, true)); 429 successCallback, errorCallback, m_context, this, absolutePath, true));
428 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 430 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
429 431
430 if (flags.createFlag()) 432 if (flags.createFlag()) {
431 fileSystem()->createDirectory(createFileSystemURL(absolutePath), 433 fileSystem()->createDirectory(createFileSystemURL(absolutePath),
432 flags.exclusive(), std::move(callbacks)); 434 flags.exclusive(), std::move(callbacks));
433 else 435 } else {
434 fileSystem()->directoryExists(createFileSystemURL(absolutePath), 436 fileSystem()->directoryExists(createFileSystemURL(absolutePath),
435 std::move(callbacks)); 437 std::move(callbacks));
438 }
436 } 439 }
437 440
438 int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, 441 int FileSystemBase::readDirectory(FileSystemDirectoryReaderBase* reader,
439 const String& path, 442 const String& path,
440 EntriesCallback* successCallback, 443 FileSystemEntriesCallback* successCallback,
441 ErrorCallbackBase* errorCallback, 444 ErrorCallbackBase* errorCallback,
442 SynchronousType synchronousType) { 445 SynchronousType synchronousType) {
443 if (!fileSystem()) { 446 if (!fileSystem()) {
444 reportError(errorCallback, FileError::kAbortErr); 447 reportError(errorCallback, FileError::kAbortErr);
445 return 0; 448 return 0;
446 } 449 }
447 450
448 ASSERT(DOMFilePath::isAbsolute(path)); 451 DCHECK(DOMFilePath::isAbsolute(path));
449 452
450 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create( 453 std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(
451 successCallback, errorCallback, m_context, reader, path)); 454 successCallback, errorCallback, m_context, reader, path));
452 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 455 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
453 456
454 return fileSystem()->readDirectory(createFileSystemURL(path), 457 return fileSystem()->readDirectory(createFileSystemURL(path),
455 std::move(callbacks)); 458 std::move(callbacks));
456 } 459 }
457 460
458 bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId) { 461 bool FileSystemBase::waitForAdditionalResult(int callbacksId) {
459 if (!fileSystem()) 462 if (!fileSystem())
460 return false; 463 return false;
461 return fileSystem()->waitForAdditionalResult(callbacksId); 464 return fileSystem()->waitForAdditionalResult(callbacksId);
462 } 465 }
463 466
464 } // namespace blink 467 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698