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

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/FileSystemCallbacks.h

Issue 2040563002: Remove FileError interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fe-dep
Patch Set: Refactor ErrorCallback Created 4 years, 5 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
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 13 matching lines...) Expand all
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 #ifndef FileSystemCallbacks_h 31 #ifndef FileSystemCallbacks_h
32 #define FileSystemCallbacks_h 32 #define FileSystemCallbacks_h
33 33
34 #include "core/fileapi/FileError.h"
34 #include "modules/filesystem/EntriesCallback.h" 35 #include "modules/filesystem/EntriesCallback.h"
35 #include "platform/AsyncFileSystemCallbacks.h" 36 #include "platform/AsyncFileSystemCallbacks.h"
36 #include "platform/FileSystemType.h" 37 #include "platform/FileSystemType.h"
37 #include "wtf/Vector.h" 38 #include "wtf/Vector.h"
38 #include "wtf/text/WTFString.h" 39 #include "wtf/text/WTFString.h"
39 #include <memory> 40 #include <memory>
40 41
41 namespace blink { 42 namespace blink {
42 43
43 class DOMFileSystemBase; 44 class DOMFileSystemBase;
44 class DirectoryReaderBase; 45 class DirectoryReaderBase;
46 class BlobCallback;
45 class EntriesCallback; 47 class EntriesCallback;
46 class EntryCallback; 48 class EntryCallback;
47 class ErrorCallback; 49 class ErrorCallback;
48 class BlobCallback;
49 class FileMetadata; 50 class FileMetadata;
50 class FileSystemCallback; 51 class FileSystemCallback;
51 class FileWriterBase; 52 class FileWriterBase;
52 class FileWriterBaseCallback; 53 class FileWriterBaseCallback;
53 class MetadataCallback; 54 class MetadataCallback;
54 class ExecutionContext; 55 class ExecutionContext;
55 class VoidCallback; 56 class VoidCallback;
56 57
58 // Passed to DOMFileSystem implementations that may report errors. Subclasses
59 // may capture the error for throwing on return to script (for synchronous APIs)
60 // or call an actual script callback (for asynchronous APIs).
61 class ErrorCallbackBase : public GarbageCollectedFinalized<ErrorCallbackBase> {
62 public:
63 virtual ~ErrorCallbackBase() { }
64 DEFINE_INLINE_VIRTUAL_TRACE() { }
65 virtual void handleEvent(FileError::ErrorCode) = 0;
foolip 2016/07/12 12:42:53 Since this is no longer the thing that interacts w
jsbell 2016/07/12 17:43:52 Done.
66 };
67
57 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks { 68 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
58 public: 69 public:
59 ~FileSystemCallbacksBase() override; 70 ~FileSystemCallbacksBase() override;
60 71
61 // For ErrorCallback. 72 // For ErrorCallback.
62 void didFail(int code) final; 73 void didFail(int code) final;
63 74
64 // Other callback methods are implemented by each subclass. 75 // Other callback methods are implemented by each subclass.
65 76
66 protected: 77 protected:
67 FileSystemCallbacksBase(ErrorCallback*, DOMFileSystemBase*, ExecutionContext *); 78 FileSystemCallbacksBase(ErrorCallbackBase*, DOMFileSystemBase*, ExecutionCon text*);
68 79
69 bool shouldScheduleCallback() const; 80 bool shouldScheduleCallback() const;
70 81
71 template <typename CB, typename CBArg> 82 template <typename CB, typename CBArg>
83 void handleEventOrScheduleCallback(CB*, CBArg);
84
85 template <typename CB, typename CBArg>
72 void handleEventOrScheduleCallback(CB*, CBArg*); 86 void handleEventOrScheduleCallback(CB*, CBArg*);
73 87
74 template <typename CB> 88 template <typename CB>
75 void handleEventOrScheduleCallback(CB*); 89 void handleEventOrScheduleCallback(CB*);
76 90
77 Persistent<ErrorCallback> m_errorCallback; 91 Persistent<ErrorCallbackBase> m_errorCallback;
78 Persistent<DOMFileSystemBase> m_fileSystem; 92 Persistent<DOMFileSystemBase> m_fileSystem;
79 Persistent<ExecutionContext> m_executionContext; 93 Persistent<ExecutionContext> m_executionContext;
80 int m_asyncOperationId; 94 int m_asyncOperationId;
81 }; 95 };
82 96
83 // Subclasses ---------------------------------------------------------------- 97 // Subclasses ----------------------------------------------------------------
84 98
99 // Wraps a script-provided callback for use in DOMFileSystem operations.
100 class ScriptErrorCallback final : public ErrorCallbackBase {
101 public:
102 static ScriptErrorCallback* wrap(ErrorCallback*);
103 virtual ~ScriptErrorCallback() { }
104 DECLARE_VIRTUAL_TRACE();
105
106 virtual void handleEvent(FileError::ErrorCode);
foolip 2016/07/12 12:42:53 Should this be override instead?
jsbell 2016/07/12 17:43:52 Done.
107 private:
108 ScriptErrorCallback(ErrorCallback*);
109 Member<ErrorCallback> m_callback;
110 };
111
85 class EntryCallbacks final : public FileSystemCallbacksBase { 112 class EntryCallbacks final : public FileSystemCallbacksBase {
86 public: 113 public:
87 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntryCallback*, Erro rCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, b ool isDirectory); 114 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntryCallback*, Erro rCallbackBase*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPat h, bool isDirectory);
88 void didSucceed() override; 115 void didSucceed() override;
89 116
90 private: 117 private:
91 EntryCallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSys temBase*, const String& expectedPath, bool isDirectory); 118 EntryCallbacks(EntryCallback*, ErrorCallbackBase*, ExecutionContext*, DOMFil eSystemBase*, const String& expectedPath, bool isDirectory);
92 Persistent<EntryCallback> m_successCallback; 119 Persistent<EntryCallback> m_successCallback;
93 String m_expectedPath; 120 String m_expectedPath;
94 bool m_isDirectory; 121 bool m_isDirectory;
95 }; 122 };
96 123
97 class EntriesCallbacks final : public FileSystemCallbacksBase { 124 class EntriesCallbacks final : public FileSystemCallbacksBase {
98 public: 125 public:
99 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntriesCallback*, Er rorCallback*, ExecutionContext*, DirectoryReaderBase*, const String& basePath); 126 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntriesCallback*, Er rorCallbackBase*, ExecutionContext*, DirectoryReaderBase*, const String& basePat h);
100 void didReadDirectoryEntry(const String& name, bool isDirectory) override; 127 void didReadDirectoryEntry(const String& name, bool isDirectory) override;
101 void didReadDirectoryEntries(bool hasMore) override; 128 void didReadDirectoryEntries(bool hasMore) override;
102 129
103 private: 130 private:
104 EntriesCallbacks(EntriesCallback*, ErrorCallback*, ExecutionContext*, Direct oryReaderBase*, const String& basePath); 131 EntriesCallbacks(EntriesCallback*, ErrorCallbackBase*, ExecutionContext*, Di rectoryReaderBase*, const String& basePath);
105 Persistent<EntriesCallback> m_successCallback; 132 Persistent<EntriesCallback> m_successCallback;
106 Persistent<DirectoryReaderBase> m_directoryReader; 133 Persistent<DirectoryReaderBase> m_directoryReader;
107 String m_basePath; 134 String m_basePath;
108 PersistentHeapVector<Member<Entry>> m_entries; 135 PersistentHeapVector<Member<Entry>> m_entries;
109 }; 136 };
110 137
111 class FileSystemCallbacks final : public FileSystemCallbacksBase { 138 class FileSystemCallbacks final : public FileSystemCallbacksBase {
112 public: 139 public:
113 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType); 140 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileSystemCallback*, ErrorCallbackBase*, ExecutionContext*, FileSystemType);
114 void didOpenFileSystem(const String& name, const KURL& rootURL) override; 141 void didOpenFileSystem(const String& name, const KURL& rootURL) override;
115 142
116 private: 143 private:
117 FileSystemCallbacks(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType); 144 FileSystemCallbacks(FileSystemCallback*, ErrorCallbackBase*, ExecutionContex t*, FileSystemType);
118 Persistent<FileSystemCallback> m_successCallback; 145 Persistent<FileSystemCallback> m_successCallback;
119 FileSystemType m_type; 146 FileSystemType m_type;
120 }; 147 };
121 148
122 class ResolveURICallbacks final : public FileSystemCallbacksBase { 149 class ResolveURICallbacks final : public FileSystemCallbacksBase {
123 public: 150 public:
124 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntryCallback*, Erro rCallback*, ExecutionContext*); 151 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntryCallback*, Erro rCallbackBase*, ExecutionContext*);
125 void didResolveURL(const String& name, const KURL& rootURL, FileSystemType, const String& filePath, bool isDirectry) override; 152 void didResolveURL(const String& name, const KURL& rootURL, FileSystemType, const String& filePath, bool isDirectry) override;
126 153
127 private: 154 private:
128 ResolveURICallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*); 155 ResolveURICallbacks(EntryCallback*, ErrorCallbackBase*, ExecutionContext*);
129 Persistent<EntryCallback> m_successCallback; 156 Persistent<EntryCallback> m_successCallback;
130 }; 157 };
131 158
132 class MetadataCallbacks final : public FileSystemCallbacksBase { 159 class MetadataCallbacks final : public FileSystemCallbacksBase {
133 public: 160 public:
134 static std::unique_ptr<AsyncFileSystemCallbacks> create(MetadataCallback*, E rrorCallback*, ExecutionContext*, DOMFileSystemBase*); 161 static std::unique_ptr<AsyncFileSystemCallbacks> create(MetadataCallback*, E rrorCallbackBase*, ExecutionContext*, DOMFileSystemBase*);
135 void didReadMetadata(const FileMetadata&) override; 162 void didReadMetadata(const FileMetadata&) override;
136 163
137 private: 164 private:
138 MetadataCallbacks(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMF ileSystemBase*); 165 MetadataCallbacks(MetadataCallback*, ErrorCallbackBase*, ExecutionContext*, DOMFileSystemBase*);
139 Persistent<MetadataCallback> m_successCallback; 166 Persistent<MetadataCallback> m_successCallback;
140 }; 167 };
141 168
142 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase { 169 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase {
143 public: 170 public:
144 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileWriterBase*, Fil eWriterBaseCallback*, ErrorCallback*, ExecutionContext*); 171 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileWriterBase*, Fil eWriterBaseCallback*, ErrorCallbackBase*, ExecutionContext*);
145 void didCreateFileWriter(std::unique_ptr<WebFileWriter>, long long length) o verride; 172 void didCreateFileWriter(std::unique_ptr<WebFileWriter>, long long length) o verride;
146 173
147 private: 174 private:
148 FileWriterBaseCallbacks(FileWriterBase*, FileWriterBaseCallback*, ErrorCallb ack*, ExecutionContext*); 175 FileWriterBaseCallbacks(FileWriterBase*, FileWriterBaseCallback*, ErrorCallb ackBase*, ExecutionContext*);
149 Persistent<FileWriterBase> m_fileWriter; 176 Persistent<FileWriterBase> m_fileWriter;
150 Persistent<FileWriterBaseCallback> m_successCallback; 177 Persistent<FileWriterBaseCallback> m_successCallback;
151 }; 178 };
152 179
153 class SnapshotFileCallback final : public FileSystemCallbacksBase { 180 class SnapshotFileCallback final : public FileSystemCallbacksBase {
154 public: 181 public:
155 static std::unique_ptr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, const String& name, const KURL&, BlobCallback*, ErrorCallback*, ExecutionContext *); 182 static std::unique_ptr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, const String& name, const KURL&, BlobCallback*, ErrorCallbackBase*, ExecutionCon text*);
156 virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataH andle> snapshot); 183 virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataH andle> snapshot);
157 184
158 private: 185 private:
159 SnapshotFileCallback(DOMFileSystemBase*, const String& name, const KURL&, Bl obCallback*, ErrorCallback*, ExecutionContext*); 186 SnapshotFileCallback(DOMFileSystemBase*, const String& name, const KURL&, Bl obCallback*, ErrorCallbackBase*, ExecutionContext*);
160 String m_name; 187 String m_name;
161 KURL m_url; 188 KURL m_url;
162 Persistent<BlobCallback> m_successCallback; 189 Persistent<BlobCallback> m_successCallback;
163 }; 190 };
164 191
165 class VoidCallbacks final : public FileSystemCallbacksBase { 192 class VoidCallbacks final : public FileSystemCallbacksBase {
166 public: 193 public:
167 static std::unique_ptr<AsyncFileSystemCallbacks> create(VoidCallback*, Error Callback*, ExecutionContext*, DOMFileSystemBase*); 194 static std::unique_ptr<AsyncFileSystemCallbacks> create(VoidCallback*, Error CallbackBase*, ExecutionContext*, DOMFileSystemBase*);
168 void didSucceed() override; 195 void didSucceed() override;
169 196
170 private: 197 private:
171 VoidCallbacks(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSyste mBase*); 198 VoidCallbacks(VoidCallback*, ErrorCallbackBase*, ExecutionContext*, DOMFileS ystemBase*);
172 Persistent<VoidCallback> m_successCallback; 199 Persistent<VoidCallback> m_successCallback;
173 }; 200 };
174 201
175 } // namespace blink 202 } // namespace blink
176 203
177 #endif // FileSystemCallbacks_h 204 #endif // FileSystemCallbacks_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698