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

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/FileSystem.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/DOMFileSystem.h" 31 #include "modules/filesystem/FileSystem.h"
32 32
33 #include "core/fileapi/BlobCallback.h" 33 #include "core/fileapi/BlobCallback.h"
34 #include "modules/filesystem/DOMFilePath.h" 34 #include "modules/filesystem/DOMFilePath.h"
35 #include "modules/filesystem/DirectoryEntry.h"
36 #include "modules/filesystem/FileEntry.h"
37 #include "modules/filesystem/FileSystemCallbacks.h" 35 #include "modules/filesystem/FileSystemCallbacks.h"
36 #include "modules/filesystem/FileSystemDirectoryEntry.h"
37 #include "modules/filesystem/FileSystemFileEntry.h"
38 #include "modules/filesystem/FileSystemMetadataCallback.h"
38 #include "modules/filesystem/FileWriter.h" 39 #include "modules/filesystem/FileWriter.h"
39 #include "modules/filesystem/FileWriterBaseCallback.h" 40 #include "modules/filesystem/FileWriterBaseCallback.h"
40 #include "modules/filesystem/FileWriterCallback.h" 41 #include "modules/filesystem/FileWriterCallback.h"
41 #include "modules/filesystem/MetadataCallback.h"
42 #include "platform/FileMetadata.h" 42 #include "platform/FileMetadata.h"
43 #include "platform/weborigin/SecurityOrigin.h" 43 #include "platform/weborigin/SecurityOrigin.h"
44 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
45 #include "public/platform/WebFileSystem.h" 45 #include "public/platform/WebFileSystem.h"
46 #include "public/platform/WebFileSystemCallbacks.h" 46 #include "public/platform/WebFileSystemCallbacks.h"
47 #include "public/platform/WebSecurityOrigin.h" 47 #include "public/platform/WebSecurityOrigin.h"
48 #include "wtf/text/StringBuilder.h" 48 #include "wtf/text/StringBuilder.h"
49 #include "wtf/text/WTFString.h" 49 #include "wtf/text/WTFString.h"
50 #include <memory> 50 #include <memory>
51 51
52 namespace blink { 52 namespace blink {
53 53
54 // static 54 // static
55 DOMFileSystem* DOMFileSystem::create(ExecutionContext* context, 55 FileSystem* FileSystem::create(ExecutionContext* context,
56 const String& name, 56 const String& name,
57 FileSystemType type, 57 FileSystemType type,
58 const KURL& rootURL) { 58 const KURL& rootURL) {
59 DOMFileSystem* fileSystem(new DOMFileSystem(context, name, type, rootURL)); 59 FileSystem* fileSystem(new FileSystem(context, name, type, rootURL));
60 fileSystem->suspendIfNeeded(); 60 fileSystem->suspendIfNeeded();
61 return fileSystem; 61 return fileSystem;
62 } 62 }
63 63
64 DOMFileSystem* DOMFileSystem::createIsolatedFileSystem( 64 FileSystem* FileSystem::createIsolatedFileSystem(ExecutionContext* context,
65 ExecutionContext* context, 65 const String& filesystemId) {
66 const String& filesystemId) {
67 if (filesystemId.isEmpty()) 66 if (filesystemId.isEmpty())
68 return 0; 67 return 0;
69 68
70 StringBuilder filesystemName; 69 StringBuilder filesystemName;
71 filesystemName.append(Platform::current()->fileSystemCreateOriginIdentifier( 70 filesystemName.append(Platform::current()->fileSystemCreateOriginIdentifier(
72 WebSecurityOrigin(context->getSecurityOrigin()))); 71 WebSecurityOrigin(context->getSecurityOrigin())));
73 filesystemName.append(":Isolated_"); 72 filesystemName.append(":Isolated_");
74 filesystemName.append(filesystemId); 73 filesystemName.append(filesystemId);
75 74
76 // The rootURL created here is going to be attached to each filesystem request 75 // The rootURL created here is going to be attached to each filesystem request
77 // and is to be validated each time the request is being handled. 76 // and is to be validated each time the request is being handled.
78 StringBuilder rootURL; 77 StringBuilder rootURL;
79 rootURL.append("filesystem:"); 78 rootURL.append("filesystem:");
80 rootURL.append(context->getSecurityOrigin()->toString()); 79 rootURL.append(context->getSecurityOrigin()->toString());
81 rootURL.append('/'); 80 rootURL.append('/');
82 rootURL.append(isolatedPathPrefix); 81 rootURL.append(isolatedPathPrefix);
83 rootURL.append('/'); 82 rootURL.append('/');
84 rootURL.append(filesystemId); 83 rootURL.append(filesystemId);
85 rootURL.append('/'); 84 rootURL.append('/');
86 85
87 return DOMFileSystem::create(context, filesystemName.toString(), 86 return FileSystem::create(context, filesystemName.toString(),
88 FileSystemTypeIsolated, 87 FileSystemTypeIsolated,
89 KURL(ParsedURLString, rootURL.toString())); 88 KURL(ParsedURLString, rootURL.toString()));
90 } 89 }
91 90
92 DOMFileSystem::DOMFileSystem(ExecutionContext* context, 91 FileSystem::FileSystem(ExecutionContext* context,
93 const String& name, 92 const String& name,
94 FileSystemType type, 93 FileSystemType type,
95 const KURL& rootURL) 94 const KURL& rootURL)
96 : DOMFileSystemBase(context, name, type, rootURL), 95 : FileSystemBase(context, name, type, rootURL),
97 ActiveScriptWrappable(this), 96 ActiveScriptWrappable(this),
98 ActiveDOMObject(context), 97 ActiveDOMObject(context),
99 m_numberOfPendingCallbacks(0), 98 m_numberOfPendingCallbacks(0),
100 m_rootEntry(DirectoryEntry::create(this, DOMFilePath::root)) {} 99 m_rootEntry(FileSystemDirectoryEntry::create(this, DOMFilePath::root)) {}
101 100
102 DirectoryEntry* DOMFileSystem::root() const { 101 FileSystemDirectoryEntry* FileSystem::root() const {
103 return m_rootEntry.get(); 102 return m_rootEntry.get();
104 } 103 }
105 104
106 void DOMFileSystem::addPendingCallbacks() { 105 void FileSystem::addPendingCallbacks() {
107 ++m_numberOfPendingCallbacks; 106 ++m_numberOfPendingCallbacks;
108 } 107 }
109 108
110 void DOMFileSystem::removePendingCallbacks() { 109 void FileSystem::removePendingCallbacks() {
111 ASSERT(m_numberOfPendingCallbacks > 0); 110 DCHECK_GT(m_numberOfPendingCallbacks, 0);
112 --m_numberOfPendingCallbacks; 111 --m_numberOfPendingCallbacks;
113 } 112 }
114 113
115 bool DOMFileSystem::hasPendingActivity() const { 114 bool FileSystem::hasPendingActivity() const {
116 ASSERT(m_numberOfPendingCallbacks >= 0); 115 DCHECK_GE(m_numberOfPendingCallbacks, 0);
117 return m_numberOfPendingCallbacks; 116 return m_numberOfPendingCallbacks;
118 } 117 }
119 118
120 void DOMFileSystem::reportError(ErrorCallbackBase* errorCallback, 119 void FileSystem::reportError(ErrorCallbackBase* errorCallback,
121 FileError::ErrorCode fileError) { 120 FileError::ErrorCode fileError) {
122 reportError(getExecutionContext(), errorCallback, fileError); 121 reportError(getExecutionContext(), errorCallback, fileError);
123 } 122 }
124 123
125 void DOMFileSystem::reportError(ExecutionContext* executionContext, 124 void FileSystem::reportError(ExecutionContext* executionContext,
126 ErrorCallbackBase* errorCallback, 125 ErrorCallbackBase* errorCallback,
127 FileError::ErrorCode fileError) { 126 FileError::ErrorCode fileError) {
128 if (errorCallback) 127 if (errorCallback) {
129 scheduleCallback( 128 scheduleCallback(
130 executionContext, 129 executionContext,
131 createSameThreadTask(&ErrorCallbackBase::invoke, 130 createSameThreadTask(&ErrorCallbackBase::invoke,
132 wrapPersistent(errorCallback), fileError)); 131 wrapPersistent(errorCallback), fileError));
132 }
133 } 133 }
134 134
135 namespace { 135 namespace {
136 136
137 class ConvertToFileWriterCallback : public FileWriterBaseCallback { 137 class ConvertToFileWriterCallback : public FileWriterBaseCallback {
138 public: 138 public:
139 static ConvertToFileWriterCallback* create(FileWriterCallback* callback) { 139 static ConvertToFileWriterCallback* create(FileWriterCallback* callback) {
140 return new ConvertToFileWriterCallback(callback); 140 return new ConvertToFileWriterCallback(callback);
141 } 141 }
142 142
143 DEFINE_INLINE_TRACE() { 143 DEFINE_INLINE_TRACE() {
144 visitor->trace(m_callback); 144 visitor->trace(m_callback);
145 FileWriterBaseCallback::trace(visitor); 145 FileWriterBaseCallback::trace(visitor);
146 } 146 }
147 147
148 void handleEvent(FileWriterBase* fileWriterBase) { 148 void handleEvent(FileWriterBase* fileWriterBase) {
149 m_callback->handleEvent(static_cast<FileWriter*>(fileWriterBase)); 149 m_callback->handleEvent(static_cast<FileWriter*>(fileWriterBase));
150 } 150 }
151 151
152 private: 152 private:
153 explicit ConvertToFileWriterCallback(FileWriterCallback* callback) 153 explicit ConvertToFileWriterCallback(FileWriterCallback* callback)
154 : m_callback(callback) {} 154 : m_callback(callback) {}
155 Member<FileWriterCallback> m_callback; 155 Member<FileWriterCallback> m_callback;
156 }; 156 };
157 157
158 } // namespace 158 } // namespace
159 159
160 void DOMFileSystem::createWriter(const FileEntry* fileEntry, 160 void FileSystem::createWriter(const FileSystemFileEntry* fileEntry,
161 FileWriterCallback* successCallback, 161 FileWriterCallback* successCallback,
162 ErrorCallbackBase* errorCallback) { 162 ErrorCallbackBase* errorCallback) {
163 ASSERT(fileEntry); 163 DCHECK(fileEntry);
164 164
165 if (!fileSystem()) { 165 if (!fileSystem()) {
166 reportError(errorCallback, FileError::kAbortErr); 166 reportError(errorCallback, FileError::kAbortErr);
167 return; 167 return;
168 } 168 }
169 169
170 FileWriter* fileWriter = FileWriter::create(getExecutionContext()); 170 FileWriter* fileWriter = FileWriter::create(getExecutionContext());
171 FileWriterBaseCallback* conversionCallback = 171 FileWriterBaseCallback* conversionCallback =
172 ConvertToFileWriterCallback::create(successCallback); 172 ConvertToFileWriterCallback::create(successCallback);
173 std::unique_ptr<AsyncFileSystemCallbacks> callbacks = 173 std::unique_ptr<AsyncFileSystemCallbacks> callbacks =
174 FileWriterBaseCallbacks::create(fileWriter, conversionCallback, 174 FileWriterBaseCallbacks::create(fileWriter, conversionCallback,
175 errorCallback, m_context); 175 errorCallback, m_context);
176 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter, 176 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter,
177 std::move(callbacks)); 177 std::move(callbacks));
178 } 178 }
179 179
180 void DOMFileSystem::createFile(const FileEntry* fileEntry, 180 void FileSystem::createFile(const FileSystemFileEntry* fileEntry,
181 BlobCallback* successCallback, 181 BlobCallback* successCallback,
182 ErrorCallbackBase* errorCallback) { 182 ErrorCallbackBase* errorCallback) {
183 KURL fileSystemURL = createFileSystemURL(fileEntry); 183 KURL fileSystemURL = createFileSystemURL(fileEntry);
184 if (!fileSystem()) { 184 if (!fileSystem()) {
185 reportError(errorCallback, FileError::kAbortErr); 185 reportError(errorCallback, FileError::kAbortErr);
186 return; 186 return;
187 } 187 }
188 188
189 fileSystem()->createSnapshotFileAndReadMetadata( 189 fileSystem()->createSnapshotFileAndReadMetadata(
190 fileSystemURL, 190 fileSystemURL,
191 SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, 191 SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL,
192 successCallback, errorCallback, m_context)); 192 successCallback, errorCallback, m_context));
193 } 193 }
194 194
195 DEFINE_TRACE(DOMFileSystem) { 195 DEFINE_TRACE(FileSystem) {
196 DOMFileSystemBase::trace(visitor); 196 FileSystemBase::trace(visitor);
197 ActiveDOMObject::trace(visitor); 197 ActiveDOMObject::trace(visitor);
198 visitor->trace(m_rootEntry); 198 visitor->trace(m_rootEntry);
199 } 199 }
200 200
201 } // namespace blink 201 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/filesystem/FileSystem.h ('k') | third_party/WebKit/Source/modules/filesystem/FileSystem.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698