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

Side by Side Diff: Source/modules/filesystem/DOMFileSystemSync.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 17 matching lines...) Expand all
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/DOMFileSystemSync.h" 32 #include "modules/filesystem/DOMFileSystemSync.h"
33 33
34 #include "bindings/v8/ExceptionState.h" 34 #include "bindings/v8/ExceptionState.h"
35 #include "core/dom/ExceptionCode.h" 35 #include "core/dom/ExceptionCode.h"
36 #include "core/fileapi/File.h" 36 #include "core/fileapi/File.h"
37 #include "core/fileapi/FileError.h" 37 #include "core/fileapi/FileError.h"
38 #include "core/platform/AsyncFileSystem.h"
39 #include "core/platform/FileMetadata.h" 38 #include "core/platform/FileMetadata.h"
40 #include "modules/filesystem/DOMFilePath.h" 39 #include "modules/filesystem/DOMFilePath.h"
41 #include "modules/filesystem/DirectoryEntrySync.h" 40 #include "modules/filesystem/DirectoryEntrySync.h"
42 #include "modules/filesystem/ErrorCallback.h" 41 #include "modules/filesystem/ErrorCallback.h"
43 #include "modules/filesystem/FileEntrySync.h" 42 #include "modules/filesystem/FileEntrySync.h"
44 #include "modules/filesystem/FileSystemCallbacks.h" 43 #include "modules/filesystem/FileSystemCallbacks.h"
45 #include "modules/filesystem/FileWriterBaseCallback.h" 44 #include "modules/filesystem/FileWriterBaseCallback.h"
46 #include "modules/filesystem/FileWriterSync.h" 45 #include "modules/filesystem/FileWriterSync.h"
46 #include "public/platform/WebFileSystem.h"
47 #include "public/platform/WebFileSystemCallbacks.h"
47 48
48 namespace WebCore { 49 namespace WebCore {
49 50
50 class FileWriterBase; 51 class FileWriterBase;
51 52
52 PassRefPtr<DOMFileSystemSync> DOMFileSystemSync::create(DOMFileSystemBase* fileS ystem) 53 PassRefPtr<DOMFileSystemSync> DOMFileSystemSync::create(DOMFileSystemBase* fileS ystem)
53 { 54 {
54 return adoptRef(new DOMFileSystemSync(fileSystem->m_context, fileSystem->nam e(), fileSystem->type(), fileSystem->rootURL(), fileSystem->m_asyncFileSystem.re lease())); 55 return adoptRef(new DOMFileSystemSync(fileSystem->m_context, fileSystem->nam e(), fileSystem->type(), fileSystem->rootURL()));
55 } 56 }
56 57
57 DOMFileSystemSync::DOMFileSystemSync(ScriptExecutionContext* context, const Stri ng& name, FileSystemType type, const KURL& rootURL, PassOwnPtr<AsyncFileSystem> asyncFileSystem) 58 DOMFileSystemSync::DOMFileSystemSync(ScriptExecutionContext* context, const Stri ng& name, FileSystemType type, const KURL& rootURL)
58 : DOMFileSystemBase(context, name, type, rootURL, asyncFileSystem) 59 : DOMFileSystemBase(context, name, type, rootURL)
59 { 60 {
60 ScriptWrappable::init(this); 61 ScriptWrappable::init(this);
61 } 62 }
62 63
63 DOMFileSystemSync::~DOMFileSystemSync() 64 DOMFileSystemSync::~DOMFileSystemSync()
64 { 65 {
65 } 66 }
66 67
67 PassRefPtr<DirectoryEntrySync> DOMFileSystemSync::root() 68 PassRefPtr<DirectoryEntrySync> DOMFileSystemSync::root()
68 { 69 {
(...skipping 21 matching lines...) Expand all
90 , m_code(0) 91 , m_code(0)
91 { 92 {
92 } 93 }
93 94
94 ~CreateFileResult() 95 ~CreateFileResult()
95 { 96 {
96 } 97 }
97 friend class WTF::RefCounted<CreateFileResult>; 98 friend class WTF::RefCounted<CreateFileResult>;
98 }; 99 };
99 100
100 static PassOwnPtr<CreateFileHelper> create(PassRefPtr<CreateFileResult> resu lt, const String& name, const KURL& url, FileSystemType type) 101 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtr<CreateFileResu lt> result, const String& name, const KURL& url, FileSystemType type)
101 { 102 {
102 return adoptPtr(new CreateFileHelper(result, name, url, type)); 103 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new CreateFileHel per(result, name, url, type)));
103 } 104 }
104 105
105 virtual void didFail(int code) 106 virtual void didFail(int code)
106 { 107 {
107 m_result->m_failed = true; 108 m_result->m_failed = true;
108 m_result->m_code = code; 109 m_result->m_code = code;
109 } 110 }
110 111
111 virtual ~CreateFileHelper() 112 virtual ~CreateFileHelper()
112 { 113 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 KURL m_url; 155 KURL m_url;
155 FileSystemType m_type; 156 FileSystemType m_type;
156 }; 157 };
157 158
158 } // namespace 159 } // namespace
159 160
160 PassRefPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, E xceptionState& es) 161 PassRefPtr<File> DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, E xceptionState& es)
161 { 162 {
162 KURL fileSystemURL = createFileSystemURL(fileEntry); 163 KURL fileSystemURL = createFileSystemURL(fileEntry);
163 RefPtr<CreateFileHelper::CreateFileResult> result(CreateFileHelper::CreateFi leResult::create()); 164 RefPtr<CreateFileHelper::CreateFileResult> result(CreateFileHelper::CreateFi leResult::create());
164 m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileSystemURL, CreateFi leHelper::create(result, fileEntry->name(), fileSystemURL, type())); 165 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, CreateFileHel per::create(result, fileEntry->name(), fileSystemURL, type()));
165 if (!m_asyncFileSystem->waitForOperationToComplete()) {
166 es.throwDOMException(AbortError, FileError::abortErrorMessage);
167 return 0;
168 }
169 if (result->m_failed) { 166 if (result->m_failed) {
170 es.throwDOMException(result->m_code); 167 es.throwDOMException(result->m_code);
171 return 0; 168 return 0;
172 } 169 }
173 return result->m_file; 170 return result->m_file;
174 } 171 }
175 172
176 namespace { 173 namespace {
177 174
178 class ReceiveFileWriterCallback : public FileWriterBaseCallback { 175 class ReceiveFileWriterCallback : public FileWriterBaseCallback {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 237 }
241 238
242 PassRefPtr<FileWriterSync> DOMFileSystemSync::createWriter(const FileEntrySync* fileEntry, ExceptionState& es) 239 PassRefPtr<FileWriterSync> DOMFileSystemSync::createWriter(const FileEntrySync* fileEntry, ExceptionState& es)
243 { 240 {
244 ASSERT(fileEntry); 241 ASSERT(fileEntry);
245 242
246 RefPtr<FileWriterSync> fileWriter = FileWriterSync::create(); 243 RefPtr<FileWriterSync> fileWriter = FileWriterSync::create();
247 RefPtr<ReceiveFileWriterCallback> successCallback = ReceiveFileWriterCallbac k::create(); 244 RefPtr<ReceiveFileWriterCallback> successCallback = ReceiveFileWriterCallbac k::create();
248 RefPtr<LocalErrorCallback> errorCallback = LocalErrorCallback::create(); 245 RefPtr<LocalErrorCallback> errorCallback = LocalErrorCallback::create();
249 246
250 OwnPtr<FileWriterBaseCallbacks> callbacks = FileWriterBaseCallbacks::create( fileWriter, successCallback, errorCallback); 247 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create (fileWriter, successCallback, errorCallback);
251 callbacks->setShouldBlockUntilCompletion(true); 248 callbacks->setShouldBlockUntilCompletion(true);
252 249
253 m_asyncFileSystem->createWriter(fileWriter.get(), createFileSystemURL(fileEn try), callbacks.release()); 250 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.ge t(), callbacks.release());
254 if (!m_asyncFileSystem->waitForOperationToComplete()) {
255 es.throwDOMException(AbortError, FileError::abortErrorMessage);
256 return 0;
257 }
258 if (errorCallback->error()) { 251 if (errorCallback->error()) {
259 ASSERT(!successCallback->fileWriterBase()); 252 ASSERT(!successCallback->fileWriterBase());
260 FileError::ErrorCode errorCode = errorCallback->error()->code(); 253 FileError::ErrorCode errorCode = errorCallback->error()->code();
261 if (errorCode) 254 if (errorCode)
262 FileError::throwDOMException(es, errorCode); 255 FileError::throwDOMException(es, errorCode);
263 return 0; 256 return 0;
264 } 257 }
265 ASSERT(successCallback->fileWriterBase()); 258 ASSERT(successCallback->fileWriterBase());
266 ASSERT(static_cast<FileWriterSync*>(successCallback->fileWriterBase()) == fi leWriter.get()); 259 ASSERT(static_cast<FileWriterSync*>(successCallback->fileWriterBase()) == fi leWriter.get());
267 return fileWriter; 260 return fileWriter;
268 } 261 }
269 262
270 } 263 }
OLDNEW
« no previous file with comments | « Source/modules/filesystem/DOMFileSystemSync.h ('k') | Source/modules/filesystem/DOMWindowFileSystem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698