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

Side by Side Diff: Source/modules/filesystem/DOMFileSystemBase.cpp

Issue 23704004: Make WebFileSystemCallbacks not self-destruct, deprecate AsyncFileSystem (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months 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 | Annotate | Revision Log
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 26 matching lines...) Expand all
37 #include "modules/filesystem/DOMFilePath.h" 37 #include "modules/filesystem/DOMFilePath.h"
38 #include "modules/filesystem/DirectoryEntry.h" 38 #include "modules/filesystem/DirectoryEntry.h"
39 #include "modules/filesystem/DirectoryReaderBase.h" 39 #include "modules/filesystem/DirectoryReaderBase.h"
40 #include "modules/filesystem/EntriesCallback.h" 40 #include "modules/filesystem/EntriesCallback.h"
41 #include "modules/filesystem/Entry.h" 41 #include "modules/filesystem/Entry.h"
42 #include "modules/filesystem/EntryBase.h" 42 #include "modules/filesystem/EntryBase.h"
43 #include "modules/filesystem/EntryCallback.h" 43 #include "modules/filesystem/EntryCallback.h"
44 #include "modules/filesystem/ErrorCallback.h" 44 #include "modules/filesystem/ErrorCallback.h"
45 #include "modules/filesystem/FileSystemCallbacks.h" 45 #include "modules/filesystem/FileSystemCallbacks.h"
46 #include "modules/filesystem/MetadataCallback.h" 46 #include "modules/filesystem/MetadataCallback.h"
47 #include "public/platform/Platform.h"
48 #include "public/platform/WebFileSystem.h"
49 #include "public/platform/WebFileSystemCallbacks.h"
47 #include "weborigin/SecurityOrigin.h" 50 #include "weborigin/SecurityOrigin.h"
48 #include "wtf/OwnPtr.h" 51 #include "wtf/OwnPtr.h"
49 #include "wtf/text/StringBuilder.h" 52 #include "wtf/text/StringBuilder.h"
50 #include "wtf/text/WTFString.h" 53 #include "wtf/text/WTFString.h"
51 54
52 namespace WebCore { 55 namespace WebCore {
53 56
54 const char DOMFileSystemBase::persistentPathPrefix[] = "persistent"; 57 const char DOMFileSystemBase::persistentPathPrefix[] = "persistent";
55 const char DOMFileSystemBase::temporaryPathPrefix[] = "temporary"; 58 const char DOMFileSystemBase::temporaryPathPrefix[] = "temporary";
56 const char DOMFileSystemBase::isolatedPathPrefix[] = "isolated"; 59 const char DOMFileSystemBase::isolatedPathPrefix[] = "isolated";
57 const char DOMFileSystemBase::externalPathPrefix[] = "external"; 60 const char DOMFileSystemBase::externalPathPrefix[] = "external";
58 61
59 DOMFileSystemBase::DOMFileSystemBase(ScriptExecutionContext* context, const Stri ng& name, FileSystemType type, const KURL& rootURL, PassOwnPtr<AsyncFileSystem> asyncFileSystem) 62 DOMFileSystemBase::DOMFileSystemBase(ScriptExecutionContext* context, const Stri ng& name, FileSystemType type, const KURL& rootURL)
60 : m_context(context) 63 : m_context(context)
61 , m_name(name) 64 , m_name(name)
62 , m_type(type) 65 , m_type(type)
63 , m_filesystemRootURL(rootURL) 66 , m_filesystemRootURL(rootURL)
64 , m_clonable(false) 67 , m_clonable(false)
65 , m_asyncFileSystem(asyncFileSystem)
66 { 68 {
67 } 69 }
68 70
69 DOMFileSystemBase::~DOMFileSystemBase() 71 DOMFileSystemBase::~DOMFileSystemBase()
70 { 72 {
71 } 73 }
72 74
75 WebKit::WebFileSystem* DOMFileSystemBase::fileSystem() const
76 {
77 return WebKit::Platform::current()->fileSystem();
78 }
79
73 SecurityOrigin* DOMFileSystemBase::securityOrigin() const 80 SecurityOrigin* DOMFileSystemBase::securityOrigin() const
74 { 81 {
75 return m_context->securityOrigin(); 82 return m_context->securityOrigin();
76 } 83 }
77 84
78 bool DOMFileSystemBase::isValidType(FileSystemType type) 85 bool DOMFileSystemBase::isValidType(FileSystemType type)
79 { 86 {
80 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent | | type == FileSystemTypeIsolated || type == FileSystemTypeExternal; 87 return type == FileSystemTypeTemporary || type == FileSystemTypePersistent | | type == FileSystemTypeIsolated || type == FileSystemTypeExternal;
81 } 88 }
82 89
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // For regular types we can just append the entry's fullPath to the m_filesy stemRootURL that should look like 'filesystem:<origin>/<typePrefix>'. 140 // For regular types we can just append the entry's fullPath to the m_filesy stemRootURL that should look like 'filesystem:<origin>/<typePrefix>'.
134 ASSERT(!m_filesystemRootURL.isEmpty()); 141 ASSERT(!m_filesystemRootURL.isEmpty());
135 KURL url = m_filesystemRootURL; 142 KURL url = m_filesystemRootURL;
136 // Remove the extra leading slash. 143 // Remove the extra leading slash.
137 url.setPath(url.path() + encodeWithURLEscapeSequences(fullPath.substring(1)) ); 144 url.setPath(url.path() + encodeWithURLEscapeSequences(fullPath.substring(1)) );
138 return url; 145 return url;
139 } 146 }
140 147
141 bool DOMFileSystemBase::getMetadata(const EntryBase* entry, PassRefPtr<MetadataC allback> successCallback, PassRefPtr<ErrorCallback> errorCallback, SynchronousTy pe synchronousType) 148 bool DOMFileSystemBase::getMetadata(const EntryBase* entry, PassRefPtr<MetadataC allback> successCallback, PassRefPtr<ErrorCallback> errorCallback, SynchronousTy pe synchronousType)
142 { 149 {
143 OwnPtr<MetadataCallbacks> callbacks(MetadataCallbacks::create(successCallbac k, errorCallback)); 150 OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(success Callback, errorCallback, this));
144 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 151 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
145 m_asyncFileSystem->readMetadata(createFileSystemURL(entry), callbacks.releas e()); 152 fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release());
146 return true; 153 return true;
147 } 154 }
148 155
149 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En tryBase* parent, const String& newName, String& destinationPath) 156 static bool verifyAndGetDestinationPathForCopyOrMove(const EntryBase* source, En tryBase* parent, const String& newName, String& destinationPath)
150 { 157 {
151 ASSERT(source); 158 ASSERT(source);
152 159
153 if (!parent || !parent->isDirectory()) 160 if (!parent || !parent->isDirectory())
154 return false; 161 return false;
155 162
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return false; 194 return false;
188 return true; 195 return true;
189 } 196 }
190 197
191 bool DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S tring& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) 198 bool DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const S tring& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType)
192 { 199 {
193 String destinationPath; 200 String destinationPath;
194 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) 201 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath))
195 return false; 202 return false;
196 203
197 OwnPtr<EntryCallbacks> callbacks(EntryCallbacks::create(successCallback, err orCallback, parent->filesystem(), destinationPath, source->isDirectory())); 204 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, parent->filesystem(), destinationPath, source->isDirectory ()));
198 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 205 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
199 206
200 m_asyncFileSystem->move(createFileSystemURL(source), parent->filesystem()->c reateFileSystemURL(destinationPath), callbacks.release()); 207 fileSystem()->move(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release());
201 return true; 208 return true;
202 } 209 }
203 210
204 bool DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S tring& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType) 211 bool DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const S tring& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallb ack> errorCallback, SynchronousType synchronousType)
205 { 212 {
206 String destinationPath; 213 String destinationPath;
207 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath)) 214 if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, desti nationPath))
208 return false; 215 return false;
209 216
210 OwnPtr<EntryCallbacks> callbacks(EntryCallbacks::create(successCallback, err orCallback, parent->filesystem(), destinationPath, source->isDirectory())); 217 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, parent->filesystem(), destinationPath, source->isDirectory ()));
211 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 218 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
212 219
213 m_asyncFileSystem->copy(createFileSystemURL(source), parent->filesystem()->c reateFileSystemURL(destinationPath), callbacks.release()); 220 fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->create FileSystemURL(destinationPath), callbacks.release());
214 return true; 221 return true;
215 } 222 }
216 223
217 bool DOMFileSystemBase::remove(const EntryBase* entry, PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, SynchronousType synchr onousType) 224 bool DOMFileSystemBase::remove(const EntryBase* entry, PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, SynchronousType synchr onousType)
218 { 225 {
219 ASSERT(entry); 226 ASSERT(entry);
220 // We don't allow calling remove() on the root directory. 227 // We don't allow calling remove() on the root directory.
221 if (entry->fullPath() == String(DOMFilePath::root)) 228 if (entry->fullPath() == String(DOMFilePath::root))
222 return false; 229 return false;
223 230
224 OwnPtr<VoidCallbacks> callbacks(VoidCallbacks::create(successCallback, error Callback)); 231 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall back, errorCallback, this));
225 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 232 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
226 233
227 m_asyncFileSystem->remove(createFileSystemURL(entry), callbacks.release()); 234 fileSystem()->remove(createFileSystemURL(entry), callbacks.release());
228 return true; 235 return true;
229 } 236 }
230 237
231 bool DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassRefPtr<Voi dCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, Synchronous Type synchronousType) 238 bool DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassRefPtr<Voi dCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, Synchronous Type synchronousType)
232 { 239 {
233 ASSERT(entry && entry->isDirectory()); 240 ASSERT(entry && entry->isDirectory());
234 // We don't allow calling remove() on the root directory. 241 // We don't allow calling remove() on the root directory.
235 if (entry->fullPath() == String(DOMFilePath::root)) 242 if (entry->fullPath() == String(DOMFilePath::root))
236 return false; 243 return false;
237 244
238 OwnPtr<VoidCallbacks> callbacks(VoidCallbacks::create(successCallback, error Callback)); 245 OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCall back, errorCallback, this));
239 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 246 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
240 247
241 m_asyncFileSystem->removeRecursively(createFileSystemURL(entry), callbacks.r elease()); 248 fileSystem()->removeRecursively(createFileSystemURL(entry), callbacks.releas e());
242 return true; 249 return true;
243 } 250 }
244 251
245 bool DOMFileSystemBase::getParent(const EntryBase* entry, PassRefPtr<EntryCallba ck> successCallback, PassRefPtr<ErrorCallback> errorCallback) 252 bool DOMFileSystemBase::getParent(const EntryBase* entry, PassRefPtr<EntryCallba ck> successCallback, PassRefPtr<ErrorCallback> errorCallback)
246 { 253 {
247 ASSERT(entry); 254 ASSERT(entry);
248 String path = DOMFilePath::getDirectory(entry->fullPath()); 255 String path = DOMFilePath::getDirectory(entry->fullPath());
249 256
250 m_asyncFileSystem->directoryExists(createFileSystemURL(path), EntryCallbacks ::create(successCallback, errorCallback, this, path, true)); 257 fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::cre ate(successCallback, errorCallback, this, path, true));
251 return true; 258 return true;
252 } 259 }
253 260
254 bool DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons t FileSystemFlags& flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr< ErrorCallback> errorCallback, SynchronousType synchronousType) 261 bool DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, cons t FileSystemFlags& flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr< ErrorCallback> errorCallback, SynchronousType synchronousType)
255 { 262 {
256 String absolutePath; 263 String absolutePath;
257 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) 264 if (!pathToAbsolutePath(m_type, entry, path, absolutePath))
258 return false; 265 return false;
259 266
260 OwnPtr<EntryCallbacks> callbacks(EntryCallbacks::create(successCallback, err orCallback, this, absolutePath, false)); 267 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, this, absolutePath, false));
261 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 268 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
262 269
263 if (flags.create) 270 if (flags.create)
264 m_asyncFileSystem->createFile(createFileSystemURL(absolutePath), flags.e xclusive, callbacks.release()); 271 fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclus ive, callbacks.release());
265 else 272 else
266 m_asyncFileSystem->fileExists(createFileSystemURL(absolutePath), callbac ks.release()); 273 fileSystem()->fileExists(createFileSystemURL(absolutePath), callbacks.re lease());
267 return true; 274 return true;
268 } 275 }
269 276
270 bool DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, const FileSystemFlags& flags, PassRefPtr<EntryCallback> successCallback, PassRe fPtr<ErrorCallback> errorCallback, SynchronousType synchronousType) 277 bool DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, const FileSystemFlags& flags, PassRefPtr<EntryCallback> successCallback, PassRe fPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
271 { 278 {
272 String absolutePath; 279 String absolutePath;
273 if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) 280 if (!pathToAbsolutePath(m_type, entry, path, absolutePath))
274 return false; 281 return false;
275 282
276 OwnPtr<EntryCallbacks> callbacks(EntryCallbacks::create(successCallback, err orCallback, this, absolutePath, true)); 283 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCal lback, errorCallback, this, absolutePath, true));
277 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 284 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
278 285
279 if (flags.create) 286 if (flags.create)
280 m_asyncFileSystem->createDirectory(createFileSystemURL(absolutePath), fl ags.exclusive, callbacks.release()); 287 fileSystem()->createDirectory(createFileSystemURL(absolutePath), flags.e xclusive, callbacks.release());
281 else 288 else
282 m_asyncFileSystem->directoryExists(createFileSystemURL(absolutePath), ca llbacks.release()); 289 fileSystem()->directoryExists(createFileSystemURL(absolutePath), callbac ks.release());
283 return true; 290 return true;
284 } 291 }
285 292
286 bool DOMFileSystemBase::readDirectory(PassRefPtr<DirectoryReaderBase> reader, co nst String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorC allback> errorCallback, SynchronousType synchronousType) 293 bool DOMFileSystemBase::readDirectory(PassRefPtr<DirectoryReaderBase> reader, co nst String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorC allback> errorCallback, SynchronousType synchronousType)
287 { 294 {
288 ASSERT(DOMFilePath::isAbsolute(path)); 295 ASSERT(DOMFilePath::isAbsolute(path));
289 296
290 OwnPtr<EntriesCallbacks> callbacks(EntriesCallbacks::create(successCallback, errorCallback, reader, path)); 297 OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successC allback, errorCallback, reader, path));
291 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous); 298 callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
292 299
293 m_asyncFileSystem->readDirectory(createFileSystemURL(path), callbacks.releas e()); 300 fileSystem()->readDirectory(createFileSystemURL(path), callbacks.release());
294 return true; 301 return true;
295 } 302 }
296 303
297 } // namespace WebCore 304 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/filesystem/DOMFileSystemBase.h ('k') | Source/modules/filesystem/DOMFileSystemSync.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698