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

Side by Side Diff: Source/modules/filesystem/DOMFileSystem.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 15 matching lines...) Expand all
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/dom/ScriptExecutionContext.h" 34 #include "core/dom/ScriptExecutionContext.h"
35 #include "core/fileapi/File.h" 35 #include "core/fileapi/File.h"
36 #include "core/platform/AsyncFileSystem.h"
37 #include "core/platform/FileMetadata.h" 36 #include "core/platform/FileMetadata.h"
38 #include "modules/filesystem/DOMFilePath.h" 37 #include "modules/filesystem/DOMFilePath.h"
39 #include "modules/filesystem/DirectoryEntry.h" 38 #include "modules/filesystem/DirectoryEntry.h"
40 #include "modules/filesystem/ErrorCallback.h" 39 #include "modules/filesystem/ErrorCallback.h"
41 #include "modules/filesystem/FileCallback.h" 40 #include "modules/filesystem/FileCallback.h"
42 #include "modules/filesystem/FileEntry.h" 41 #include "modules/filesystem/FileEntry.h"
43 #include "modules/filesystem/FileSystemCallbacks.h" 42 #include "modules/filesystem/FileSystemCallbacks.h"
44 #include "modules/filesystem/FileWriter.h" 43 #include "modules/filesystem/FileWriter.h"
45 #include "modules/filesystem/FileWriterBaseCallback.h" 44 #include "modules/filesystem/FileWriterBaseCallback.h"
46 #include "modules/filesystem/FileWriterCallback.h" 45 #include "modules/filesystem/FileWriterCallback.h"
47 #include "modules/filesystem/MetadataCallback.h" 46 #include "modules/filesystem/MetadataCallback.h"
47 #include "public/platform/WebFileSystem.h"
48 #include "public/platform/WebFileSystemCallbacks.h"
48 #include "weborigin/DatabaseIdentifier.h" 49 #include "weborigin/DatabaseIdentifier.h"
49 #include "weborigin/SecurityOrigin.h" 50 #include "weborigin/SecurityOrigin.h"
50 #include "wtf/OwnPtr.h" 51 #include "wtf/OwnPtr.h"
51 #include "wtf/text/StringBuilder.h" 52 #include "wtf/text/StringBuilder.h"
52 #include "wtf/text/WTFString.h" 53 #include "wtf/text/WTFString.h"
53 54
54 namespace WebCore { 55 namespace WebCore {
55 56
56 // static 57 // static
57 PassRefPtr<DOMFileSystem> DOMFileSystem::create(ScriptExecutionContext* context, const String& name, FileSystemType type, const KURL& rootURL, PassOwnPtr<AsyncF ileSystem> asyncFileSystem) 58 PassRefPtr<DOMFileSystem> DOMFileSystem::create(ScriptExecutionContext* context, const String& name, FileSystemType type, const KURL& rootURL)
58 { 59 {
59 RefPtr<DOMFileSystem> fileSystem(adoptRef(new DOMFileSystem(context, name, t ype, rootURL, asyncFileSystem))); 60 RefPtr<DOMFileSystem> fileSystem(adoptRef(new DOMFileSystem(context, name, t ype, rootURL)));
60 fileSystem->suspendIfNeeded(); 61 fileSystem->suspendIfNeeded();
61 return fileSystem.release(); 62 return fileSystem.release();
62 } 63 }
63 64
64 PassRefPtr<DOMFileSystem> DOMFileSystem::createIsolatedFileSystem(ScriptExecutio nContext* context, const String& filesystemId) 65 PassRefPtr<DOMFileSystem> DOMFileSystem::createIsolatedFileSystem(ScriptExecutio nContext* context, const String& filesystemId)
65 { 66 {
66 if (filesystemId.isEmpty()) 67 if (filesystemId.isEmpty())
67 return 0; 68 return 0;
68 69
69 StringBuilder filesystemName; 70 StringBuilder filesystemName;
70 filesystemName.append(createDatabaseIdentifierFromSecurityOrigin(context->se curityOrigin())); 71 filesystemName.append(createDatabaseIdentifierFromSecurityOrigin(context->se curityOrigin()));
71 filesystemName.append(":Isolated_"); 72 filesystemName.append(":Isolated_");
72 filesystemName.append(filesystemId); 73 filesystemName.append(filesystemId);
73 74
74 // The rootURL created here is going to be attached to each filesystem reque st and 75 // The rootURL created here is going to be attached to each filesystem reque st and
75 // is to be validated each time the request is being handled. 76 // is to be validated each time the request is being handled.
76 StringBuilder rootURL; 77 StringBuilder rootURL;
77 rootURL.append("filesystem:"); 78 rootURL.append("filesystem:");
78 rootURL.append(context->securityOrigin()->toString()); 79 rootURL.append(context->securityOrigin()->toString());
79 rootURL.append("/"); 80 rootURL.append("/");
80 rootURL.append(isolatedPathPrefix); 81 rootURL.append(isolatedPathPrefix);
81 rootURL.append("/"); 82 rootURL.append("/");
82 rootURL.append(filesystemId); 83 rootURL.append(filesystemId);
83 rootURL.append("/"); 84 rootURL.append("/");
84 85
85 return DOMFileSystem::create(context, filesystemName.toString(), FileSystemT ypeIsolated, KURL(ParsedURLString, rootURL.toString()), AsyncFileSystem::create( )); 86 return DOMFileSystem::create(context, filesystemName.toString(), FileSystemT ypeIsolated, KURL(ParsedURLString, rootURL.toString()));
86 } 87 }
87 88
88 DOMFileSystem::DOMFileSystem(ScriptExecutionContext* context, const String& name , FileSystemType type, const KURL& rootURL, PassOwnPtr<AsyncFileSystem> asyncFil eSystem) 89 DOMFileSystem::DOMFileSystem(ScriptExecutionContext* context, const String& name , FileSystemType type, const KURL& rootURL)
89 : DOMFileSystemBase(context, name, type, rootURL, asyncFileSystem) 90 : DOMFileSystemBase(context, name, type, rootURL)
90 , ActiveDOMObject(context) 91 , ActiveDOMObject(context)
91 { 92 {
92 ScriptWrappable::init(this); 93 ScriptWrappable::init(this);
93 } 94 }
94 95
95 PassRefPtr<DirectoryEntry> DOMFileSystem::root() 96 PassRefPtr<DirectoryEntry> DOMFileSystem::root()
96 { 97 {
97 return DirectoryEntry::create(this, DOMFilePath::root); 98 return DirectoryEntry::create(this, DOMFilePath::root);
98 } 99 }
99 100
100 void DOMFileSystem::stop() 101 void DOMFileSystem::stop()
101 { 102 {
102 m_asyncFileSystem->stop();
103 } 103 }
104 104
105 bool DOMFileSystem::hasPendingActivity() const 105 bool DOMFileSystem::hasPendingActivity() const
106 { 106 {
107 return m_asyncFileSystem->hasPendingActivity(); 107 return false;
abarth-chromium 2013/08/30 16:18:25 This doesn't seem right. Don't we have pending ac
kinuko 2013/09/03 09:32:49 We do, but we also hold reference to DOMFileSystem
108 } 108 }
109 109
110 void DOMFileSystem::contextDestroyed() 110 void DOMFileSystem::contextDestroyed()
111 { 111 {
112 m_asyncFileSystem->stop();
113 ActiveDOMObject::contextDestroyed(); 112 ActiveDOMObject::contextDestroyed();
114 } 113 }
115 114
116 namespace { 115 namespace {
117 116
118 class ConvertToFileWriterCallback : public FileWriterBaseCallback { 117 class ConvertToFileWriterCallback : public FileWriterBaseCallback {
119 public: 118 public:
120 static PassRefPtr<ConvertToFileWriterCallback> create(PassRefPtr<FileWriterC allback> callback) 119 static PassRefPtr<ConvertToFileWriterCallback> create(PassRefPtr<FileWriterC allback> callback)
121 { 120 {
122 return adoptRef(new ConvertToFileWriterCallback(callback)); 121 return adoptRef(new ConvertToFileWriterCallback(callback));
(...skipping 12 matching lines...) Expand all
135 }; 134 };
136 135
137 } 136 }
138 137
139 void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassRefPtr<FileWrit erCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) 138 void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassRefPtr<FileWrit erCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
140 { 139 {
141 ASSERT(fileEntry); 140 ASSERT(fileEntry);
142 141
143 RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext()) ; 142 RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext()) ;
144 RefPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb ack::create(successCallback); 143 RefPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallb ack::create(successCallback);
145 OwnPtr<FileWriterBaseCallbacks> callbacks = FileWriterBaseCallbacks::create( fileWriter, conversionCallback, errorCallback); 144 OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create (fileWriter, conversionCallback, errorCallback);
146 m_asyncFileSystem->createWriter(fileWriter.get(), createFileSystemURL(fileEn try), callbacks.release()); 145 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.ge t(), callbacks.release());
147 } 146 }
148 147
149 namespace { 148 namespace {
150 149
151 class SnapshotFileCallback : public FileSystemCallbacksBase { 150 class SnapshotFileCallback : public FileSystemCallbacksBase {
152 public: 151 public:
153 static PassOwnPtr<SnapshotFileCallback> create(PassRefPtr<DOMFileSystem> fil esystem, const String& name, const KURL& url, PassRefPtr<FileCallback> successCa llback, PassRefPtr<ErrorCallback> errorCallback) 152 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtr<DOMFileSystem> filesystem, const String& name, const KURL& url, PassRefPtr<FileCallback> succe ssCallback, PassRefPtr<ErrorCallback> errorCallback)
154 { 153 {
155 return adoptPtr(new SnapshotFileCallback(filesystem, name, url, successC allback, errorCallback)); 154 return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new SnapshotFileC allback(filesystem, name, url, successCallback, errorCallback)));
156 } 155 }
157 156
158 virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr< BlobDataHandle> snapshot) 157 virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr< BlobDataHandle> snapshot)
159 { 158 {
160 ASSERT(!metadata.platformPath.isEmpty()); 159 ASSERT(!metadata.platformPath.isEmpty());
161 if (!m_successCallback) 160 if (!m_successCallback)
162 return; 161 return;
163 162
164 // We can't directly use the snapshot blob data handle because the conte nt type on it hasn't been set. 163 // 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 164 // The |snapshot| param is here to provide a a chain of custody thru thr ead bridging that is held onto until
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 String m_name; 196 String m_name;
198 KURL m_url; 197 KURL m_url;
199 RefPtr<FileCallback> m_successCallback; 198 RefPtr<FileCallback> m_successCallback;
200 }; 199 };
201 200
202 } // namespace 201 } // namespace
203 202
204 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallba ck> successCallback, PassRefPtr<ErrorCallback> errorCallback) 203 void DOMFileSystem::createFile(const FileEntry* fileEntry, PassRefPtr<FileCallba ck> successCallback, PassRefPtr<ErrorCallback> errorCallback)
205 { 204 {
206 KURL fileSystemURL = createFileSystemURL(fileEntry); 205 KURL fileSystemURL = createFileSystemURL(fileEntry);
207 m_asyncFileSystem->createSnapshotFileAndReadMetadata(fileSystemURL, Snapshot FileCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, er rorCallback)); 206 fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileC allback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCa llback));
208 } 207 }
209 208
210 } // namespace WebCore 209 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698