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

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/FileSystemSync.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/DOMFileSystemSync.h" 31 #include "modules/filesystem/FileSystemSync.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.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 "modules/filesystem/DOMFilePath.h" 36 #include "modules/filesystem/DOMFilePath.h"
37 #include "modules/filesystem/DirectoryEntrySync.h"
38 #include "modules/filesystem/ErrorCallback.h" 37 #include "modules/filesystem/ErrorCallback.h"
39 #include "modules/filesystem/FileEntrySync.h"
40 #include "modules/filesystem/FileSystemCallbacks.h" 38 #include "modules/filesystem/FileSystemCallbacks.h"
39 #include "modules/filesystem/FileSystemDirectoryEntrySync.h"
40 #include "modules/filesystem/FileSystemFileEntrySync.h"
41 #include "modules/filesystem/FileWriterBaseCallback.h" 41 #include "modules/filesystem/FileWriterBaseCallback.h"
42 #include "modules/filesystem/FileWriterSync.h" 42 #include "modules/filesystem/FileWriterSync.h"
43 #include "platform/FileMetadata.h" 43 #include "platform/FileMetadata.h"
44 #include "public/platform/WebFileSystem.h" 44 #include "public/platform/WebFileSystem.h"
45 #include "public/platform/WebFileSystemCallbacks.h" 45 #include "public/platform/WebFileSystemCallbacks.h"
46 #include "wtf/PtrUtil.h" 46 #include "wtf/PtrUtil.h"
47 #include <memory> 47 #include <memory>
48 48
49 namespace blink { 49 namespace blink {
50 50
51 class FileWriterBase; 51 class FileWriterBase;
52 52
53 DOMFileSystemSync* DOMFileSystemSync::create(DOMFileSystemBase* fileSystem) { 53 FileSystemSync* FileSystemSync::create(FileSystemBase* fileSystem) {
54 return new DOMFileSystemSync(fileSystem->m_context, fileSystem->name(), 54 return new FileSystemSync(fileSystem->m_context, fileSystem->name(),
55 fileSystem->type(), fileSystem->rootURL()); 55 fileSystem->type(), fileSystem->rootURL());
56 } 56 }
57 57
58 DOMFileSystemSync::DOMFileSystemSync(ExecutionContext* context, 58 FileSystemSync::FileSystemSync(ExecutionContext* context,
59 const String& name, 59 const String& name,
60 FileSystemType type, 60 FileSystemType type,
61 const KURL& rootURL) 61 const KURL& rootURL)
62 : DOMFileSystemBase(context, name, type, rootURL), 62 : FileSystemBase(context, name, type, rootURL),
63 m_rootEntry(DirectoryEntrySync::create(this, DOMFilePath::root)) {} 63 m_rootEntry(
64 FileSystemDirectoryEntrySync::create(this, DOMFilePath::root)) {}
64 65
65 DOMFileSystemSync::~DOMFileSystemSync() {} 66 FileSystemSync::~FileSystemSync() {}
66 67
67 void DOMFileSystemSync::reportError(ErrorCallbackBase* errorCallback, 68 void FileSystemSync::reportError(ErrorCallbackBase* errorCallback,
68 FileError::ErrorCode fileError) { 69 FileError::ErrorCode fileError) {
69 errorCallback->invoke(fileError); 70 errorCallback->invoke(fileError);
70 } 71 }
71 72
72 DirectoryEntrySync* DOMFileSystemSync::root() { 73 FileSystemDirectoryEntrySync* FileSystemSync::root() {
73 return m_rootEntry.get(); 74 return m_rootEntry.get();
74 } 75 }
75 76
76 namespace { 77 namespace {
77 78
78 class CreateFileHelper final : public AsyncFileSystemCallbacks { 79 class CreateFileHelper final : public AsyncFileSystemCallbacks {
79 public: 80 public:
80 class CreateFileResult : public GarbageCollected<CreateFileResult> { 81 class CreateFileResult : public GarbageCollected<CreateFileResult> {
81 public: 82 public:
82 static CreateFileResult* create() { return new CreateFileResult(); } 83 static CreateFileResult* create() { return new CreateFileResult(); }
(...skipping 27 matching lines...) Expand all
110 void didCreateSnapshotFile(const FileMetadata& metadata, 111 void didCreateSnapshotFile(const FileMetadata& metadata,
111 PassRefPtr<BlobDataHandle> snapshot) override { 112 PassRefPtr<BlobDataHandle> snapshot) override {
112 // We can't directly use the snapshot blob data handle because the content 113 // We can't directly use the snapshot blob data handle because the content
113 // type on it hasn't been set. The |snapshot| param is here to provide a a 114 // type on it hasn't been set. The |snapshot| param is here to provide a a
114 // chain of custody thru thread bridging that is held onto until *after* 115 // chain of custody thru thread bridging that is held onto until *after*
115 // we've coined a File with a new handle that has the correct type set on 116 // we've coined a File with a new handle that has the correct type set on
116 // it. This allows the blob storage system to track when a temp file can and 117 // it. This allows the blob storage system to track when a temp file can and
117 // can't be safely deleted. 118 // can't be safely deleted.
118 119
119 m_result->m_file = 120 m_result->m_file =
120 DOMFileSystemBase::createFile(metadata, m_url, m_type, m_name); 121 FileSystemBase::createFile(metadata, m_url, m_type, m_name);
121 } 122 }
122 123
123 bool shouldBlockUntilCompletion() const override { return true; } 124 bool shouldBlockUntilCompletion() const override { return true; }
124 125
125 private: 126 private:
126 CreateFileHelper(CreateFileResult* result, 127 CreateFileHelper(CreateFileResult* result,
127 const String& name, 128 const String& name,
128 const KURL& url, 129 const KURL& url,
129 FileSystemType type) 130 FileSystemType type)
130 : m_result(result), m_name(name), m_url(url), m_type(type) {} 131 : m_result(result), m_name(name), m_url(url), m_type(type) {}
131 132
132 Persistent<CreateFileResult> m_result; 133 Persistent<CreateFileResult> m_result;
133 String m_name; 134 String m_name;
134 KURL m_url; 135 KURL m_url;
135 FileSystemType m_type; 136 FileSystemType m_type;
136 }; 137 };
137 138
138 } // namespace 139 } // namespace
139 140
140 File* DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, 141 File* FileSystemSync::createFile(const FileSystemFileEntrySync* fileEntry,
141 ExceptionState& exceptionState) { 142 ExceptionState& exceptionState) {
142 KURL fileSystemURL = createFileSystemURL(fileEntry); 143 KURL fileSystemURL = createFileSystemURL(fileEntry);
143 CreateFileHelper::CreateFileResult* result( 144 CreateFileHelper::CreateFileResult* result(
144 CreateFileHelper::CreateFileResult::create()); 145 CreateFileHelper::CreateFileResult::create());
145 fileSystem()->createSnapshotFileAndReadMetadata( 146 fileSystem()->createSnapshotFileAndReadMetadata(
146 fileSystemURL, CreateFileHelper::create(result, fileEntry->name(), 147 fileSystemURL, CreateFileHelper::create(result, fileEntry->name(),
147 fileSystemURL, type())); 148 fileSystemURL, type()));
148 if (result->m_failed) { 149 if (result->m_failed) {
149 exceptionState.throwDOMException( 150 exceptionState.throwDOMException(
150 result->m_code, "Could not create '" + fileEntry->name() + "'."); 151 result->m_code, "Could not create '" + fileEntry->name() + "'.");
151 return nullptr; 152 return nullptr;
(...skipping 28 matching lines...) Expand all
180 181
181 private: 182 private:
182 explicit LocalErrorCallback(FileError::ErrorCode& errorCode) 183 explicit LocalErrorCallback(FileError::ErrorCode& errorCode)
183 : m_errorCode(errorCode) {} 184 : m_errorCode(errorCode) {}
184 185
185 FileError::ErrorCode& m_errorCode; 186 FileError::ErrorCode& m_errorCode;
186 }; 187 };
187 188
188 } // namespace 189 } // namespace
189 190
190 FileWriterSync* DOMFileSystemSync::createWriter( 191 FileWriterSync* FileSystemSync::createWriter(
191 const FileEntrySync* fileEntry, 192 const FileSystemFileEntrySync* fileEntry,
192 ExceptionState& exceptionState) { 193 ExceptionState& exceptionState) {
193 ASSERT(fileEntry); 194 DCHECK(fileEntry);
194 195
195 FileWriterSync* fileWriter = FileWriterSync::create(); 196 FileWriterSync* fileWriter = FileWriterSync::create();
196 ReceiveFileWriterCallback* successCallback = 197 ReceiveFileWriterCallback* successCallback =
197 ReceiveFileWriterCallback::create(); 198 ReceiveFileWriterCallback::create();
198 FileError::ErrorCode errorCode = FileError::kOK; 199 FileError::ErrorCode errorCode = FileError::kOK;
199 LocalErrorCallback* errorCallback = LocalErrorCallback::create(errorCode); 200 LocalErrorCallback* errorCallback = LocalErrorCallback::create(errorCode);
200 201
201 std::unique_ptr<AsyncFileSystemCallbacks> callbacks = 202 std::unique_ptr<AsyncFileSystemCallbacks> callbacks =
202 FileWriterBaseCallbacks::create(fileWriter, successCallback, 203 FileWriterBaseCallbacks::create(fileWriter, successCallback,
203 errorCallback, m_context); 204 errorCallback, m_context);
204 callbacks->setShouldBlockUntilCompletion(true); 205 callbacks->setShouldBlockUntilCompletion(true);
205 206
206 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter, 207 fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter,
207 std::move(callbacks)); 208 std::move(callbacks));
208 if (errorCode != FileError::kOK) { 209 if (errorCode != FileError::kOK) {
209 FileError::throwDOMException(exceptionState, errorCode); 210 FileError::throwDOMException(exceptionState, errorCode);
210 return 0; 211 return 0;
211 } 212 }
212 return fileWriter; 213 return fileWriter;
213 } 214 }
214 215
215 DEFINE_TRACE(DOMFileSystemSync) { 216 DEFINE_TRACE(FileSystemSync) {
216 DOMFileSystemBase::trace(visitor); 217 FileSystemBase::trace(visitor);
217 visitor->trace(m_rootEntry); 218 visitor->trace(m_rootEntry);
218 } 219 }
219 220
220 } // namespace blink 221 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698