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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "modules/filesystem/EntryCallback.h" 44 #include "modules/filesystem/EntryCallback.h"
45 #include "modules/filesystem/ErrorCallback.h" 45 #include "modules/filesystem/ErrorCallback.h"
46 #include "modules/filesystem/FileEntry.h" 46 #include "modules/filesystem/FileEntry.h"
47 #include "modules/filesystem/FileSystemCallback.h" 47 #include "modules/filesystem/FileSystemCallback.h"
48 #include "modules/filesystem/FileWriterBase.h" 48 #include "modules/filesystem/FileWriterBase.h"
49 #include "modules/filesystem/FileWriterBaseCallback.h" 49 #include "modules/filesystem/FileWriterBaseCallback.h"
50 #include "modules/filesystem/Metadata.h" 50 #include "modules/filesystem/Metadata.h"
51 #include "modules/filesystem/MetadataCallback.h" 51 #include "modules/filesystem/MetadataCallback.h"
52 #include "platform/FileMetadata.h" 52 #include "platform/FileMetadata.h"
53 #include "public/platform/WebFileWriter.h" 53 #include "public/platform/WebFileWriter.h"
54 #include "wtf/PtrUtil.h"
55 #include <memory>
56 54
57 namespace blink { 55 namespace blink {
58 56
59 FileSystemCallbacksBase::FileSystemCallbacksBase(ErrorCallback* errorCallback, D OMFileSystemBase* fileSystem, ExecutionContext* context) 57 FileSystemCallbacksBase::FileSystemCallbacksBase(ErrorCallback* errorCallback, D OMFileSystemBase* fileSystem, ExecutionContext* context)
60 : m_errorCallback(errorCallback) 58 : m_errorCallback(errorCallback)
61 , m_fileSystem(fileSystem) 59 , m_fileSystem(fileSystem)
62 , m_executionContext(context) 60 , m_executionContext(context)
63 { 61 {
64 if (m_fileSystem) 62 if (m_fileSystem)
65 m_fileSystem->addPendingCallbacks(); 63 m_fileSystem->addPendingCallbacks();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ASSERT(callback); 97 ASSERT(callback);
100 if (shouldScheduleCallback()) 98 if (shouldScheduleCallback())
101 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback); 99 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback);
102 else if (callback) 100 else if (callback)
103 callback->handleEvent(); 101 callback->handleEvent();
104 m_executionContext.clear(); 102 m_executionContext.clear();
105 } 103 }
106 104
107 // EntryCallbacks ------------------------------------------------------------- 105 // EntryCallbacks -------------------------------------------------------------
108 106
109 std::unique_ptr<AsyncFileSystemCallbacks> EntryCallbacks::create(EntryCallback* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFil eSystemBase* fileSystem, const String& expectedPath, bool isDirectory) 107 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(EntryCallback* succe ssCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileSyst emBase* fileSystem, const String& expectedPath, bool isDirectory)
110 { 108 {
111 return wrapUnique(new EntryCallbacks(successCallback, errorCallback, context , fileSystem, expectedPath, isDirectory)); 109 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context, fileSystem, expectedPath, isDirectory));
112 } 110 }
113 111
114 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, ErrorCallback* er rorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const Str ing& expectedPath, bool isDirectory) 112 EntryCallbacks::EntryCallbacks(EntryCallback* successCallback, ErrorCallback* er rorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const Str ing& expectedPath, bool isDirectory)
115 : FileSystemCallbacksBase(errorCallback, fileSystem, context) 113 : FileSystemCallbacksBase(errorCallback, fileSystem, context)
116 , m_successCallback(successCallback) 114 , m_successCallback(successCallback)
117 , m_expectedPath(expectedPath) 115 , m_expectedPath(expectedPath)
118 , m_isDirectory(isDirectory) 116 , m_isDirectory(isDirectory)
119 { 117 {
120 } 118 }
121 119
122 void EntryCallbacks::didSucceed() 120 void EntryCallbacks::didSucceed()
123 { 121 {
124 if (m_successCallback) { 122 if (m_successCallback) {
125 if (m_isDirectory) 123 if (m_isDirectory)
126 handleEventOrScheduleCallback(m_successCallback.release(), Directory Entry::create(m_fileSystem, m_expectedPath)); 124 handleEventOrScheduleCallback(m_successCallback.release(), Directory Entry::create(m_fileSystem, m_expectedPath));
127 else 125 else
128 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry ::create(m_fileSystem, m_expectedPath)); 126 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry ::create(m_fileSystem, m_expectedPath));
129 } 127 }
130 } 128 }
131 129
132 // EntriesCallbacks ----------------------------------------------------------- 130 // EntriesCallbacks -----------------------------------------------------------
133 131
134 std::unique_ptr<AsyncFileSystemCallbacks> EntriesCallbacks::create(EntriesCallba ck* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, Di rectoryReaderBase* directoryReader, const String& basePath) 132 PassOwnPtr<AsyncFileSystemCallbacks> EntriesCallbacks::create(EntriesCallback* s uccessCallback, ErrorCallback* errorCallback, ExecutionContext* context, Directo ryReaderBase* directoryReader, const String& basePath)
135 { 133 {
136 return wrapUnique(new EntriesCallbacks(successCallback, errorCallback, conte xt, directoryReader, basePath)); 134 return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, context , directoryReader, basePath));
137 } 135 }
138 136
139 EntriesCallbacks::EntriesCallbacks(EntriesCallback* successCallback, ErrorCallba ck* errorCallback, ExecutionContext* context, DirectoryReaderBase* directoryRead er, const String& basePath) 137 EntriesCallbacks::EntriesCallbacks(EntriesCallback* successCallback, ErrorCallba ck* errorCallback, ExecutionContext* context, DirectoryReaderBase* directoryRead er, const String& basePath)
140 : FileSystemCallbacksBase(errorCallback, directoryReader->filesystem(), cont ext) 138 : FileSystemCallbacksBase(errorCallback, directoryReader->filesystem(), cont ext)
141 , m_successCallback(successCallback) 139 , m_successCallback(successCallback)
142 , m_directoryReader(directoryReader) 140 , m_directoryReader(directoryReader)
143 , m_basePath(basePath) 141 , m_basePath(basePath)
144 { 142 {
145 ASSERT(m_directoryReader); 143 ASSERT(m_directoryReader);
146 } 144 }
(...skipping 11 matching lines...) Expand all
158 m_directoryReader->setHasMoreEntries(hasMore); 156 m_directoryReader->setHasMoreEntries(hasMore);
159 EntryHeapVector entries; 157 EntryHeapVector entries;
160 entries.swap(m_entries); 158 entries.swap(m_entries);
161 // FIXME: delay the callback iff shouldScheduleCallback() is true. 159 // FIXME: delay the callback iff shouldScheduleCallback() is true.
162 if (m_successCallback) 160 if (m_successCallback)
163 m_successCallback->handleEvent(entries); 161 m_successCallback->handleEvent(entries);
164 } 162 }
165 163
166 // FileSystemCallbacks -------------------------------------------------------- 164 // FileSystemCallbacks --------------------------------------------------------
167 165
168 std::unique_ptr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(FileSystem Callback* successCallback, ErrorCallback* errorCallback, ExecutionContext* conte xt, FileSystemType type) 166 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(FileSystemCallb ack* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, F ileSystemType type)
169 { 167 {
170 return wrapUnique(new FileSystemCallbacks(successCallback, errorCallback, co ntext, type)); 168 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont ext, type));
171 } 169 }
172 170
173 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, Er rorCallback* errorCallback, ExecutionContext* context, FileSystemType type) 171 FileSystemCallbacks::FileSystemCallbacks(FileSystemCallback* successCallback, Er rorCallback* errorCallback, ExecutionContext* context, FileSystemType type)
174 : FileSystemCallbacksBase(errorCallback, nullptr, context) 172 : FileSystemCallbacksBase(errorCallback, nullptr, context)
175 , m_successCallback(successCallback) 173 , m_successCallback(successCallback)
176 , m_type(type) 174 , m_type(type)
177 { 175 {
178 } 176 }
179 177
180 void FileSystemCallbacks::didOpenFileSystem(const String& name, const KURL& root URL) 178 void FileSystemCallbacks::didOpenFileSystem(const String& name, const KURL& root URL)
181 { 179 {
182 if (m_successCallback) 180 if (m_successCallback)
183 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystem ::create(m_executionContext.get(), name, m_type, rootURL)); 181 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystem ::create(m_executionContext.get(), name, m_type, rootURL));
184 } 182 }
185 183
186 // ResolveURICallbacks -------------------------------------------------------- 184 // ResolveURICallbacks --------------------------------------------------------
187 185
188 std::unique_ptr<AsyncFileSystemCallbacks> ResolveURICallbacks::create(EntryCallb ack* successCallback, ErrorCallback* errorCallback, ExecutionContext* context) 186 PassOwnPtr<AsyncFileSystemCallbacks> ResolveURICallbacks::create(EntryCallback* successCallback, ErrorCallback* errorCallback, ExecutionContext* context)
189 { 187 {
190 return wrapUnique(new ResolveURICallbacks(successCallback, errorCallback, co ntext)); 188 return adoptPtr(new ResolveURICallbacks(successCallback, errorCallback, cont ext));
191 } 189 }
192 190
193 ResolveURICallbacks::ResolveURICallbacks(EntryCallback* successCallback, ErrorCa llback* errorCallback, ExecutionContext* context) 191 ResolveURICallbacks::ResolveURICallbacks(EntryCallback* successCallback, ErrorCa llback* errorCallback, ExecutionContext* context)
194 : FileSystemCallbacksBase(errorCallback, nullptr, context) 192 : FileSystemCallbacksBase(errorCallback, nullptr, context)
195 , m_successCallback(successCallback) 193 , m_successCallback(successCallback)
196 { 194 {
197 } 195 }
198 196
199 void ResolveURICallbacks::didResolveURL(const String& name, const KURL& rootURL, FileSystemType type, const String& filePath, bool isDirectory) 197 void ResolveURICallbacks::didResolveURL(const String& name, const KURL& rootURL, FileSystemType type, const String& filePath, bool isDirectory)
200 { 198 {
201 DOMFileSystem* filesystem = DOMFileSystem::create(m_executionContext.get(), name, type, rootURL); 199 DOMFileSystem* filesystem = DOMFileSystem::create(m_executionContext.get(), name, type, rootURL);
202 DirectoryEntry* root = filesystem->root(); 200 DirectoryEntry* root = filesystem->root();
203 201
204 String absolutePath; 202 String absolutePath;
205 if (!DOMFileSystemBase::pathToAbsolutePath(type, root, filePath, absolutePat h)) { 203 if (!DOMFileSystemBase::pathToAbsolutePath(type, root, filePath, absolutePat h)) {
206 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea te(FileError::INVALID_MODIFICATION_ERR)); 204 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea te(FileError::INVALID_MODIFICATION_ERR));
207 return; 205 return;
208 } 206 }
209 207
210 if (isDirectory) 208 if (isDirectory)
211 handleEventOrScheduleCallback(m_successCallback.release(), DirectoryEntr y::create(filesystem, absolutePath)); 209 handleEventOrScheduleCallback(m_successCallback.release(), DirectoryEntr y::create(filesystem, absolutePath));
212 else 210 else
213 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry::cr eate(filesystem, absolutePath)); 211 handleEventOrScheduleCallback(m_successCallback.release(), FileEntry::cr eate(filesystem, absolutePath));
214 } 212 }
215 213
216 // MetadataCallbacks ---------------------------------------------------------- 214 // MetadataCallbacks ----------------------------------------------------------
217 215
218 std::unique_ptr<AsyncFileSystemCallbacks> MetadataCallbacks::create(MetadataCall back* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem) 216 PassOwnPtr<AsyncFileSystemCallbacks> MetadataCallbacks::create(MetadataCallback* successCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFi leSystemBase* fileSystem)
219 { 217 {
220 return wrapUnique(new MetadataCallbacks(successCallback, errorCallback, cont ext, fileSystem)); 218 return adoptPtr(new MetadataCallbacks(successCallback, errorCallback, contex t, fileSystem));
221 } 219 }
222 220
223 MetadataCallbacks::MetadataCallbacks(MetadataCallback* successCallback, ErrorCal lback* errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem) 221 MetadataCallbacks::MetadataCallbacks(MetadataCallback* successCallback, ErrorCal lback* errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem)
224 : FileSystemCallbacksBase(errorCallback, fileSystem, context) 222 : FileSystemCallbacksBase(errorCallback, fileSystem, context)
225 , m_successCallback(successCallback) 223 , m_successCallback(successCallback)
226 { 224 {
227 } 225 }
228 226
229 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) 227 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata)
230 { 228 {
231 if (m_successCallback) 229 if (m_successCallback)
232 handleEventOrScheduleCallback(m_successCallback.release(), Metadata::cre ate(metadata)); 230 handleEventOrScheduleCallback(m_successCallback.release(), Metadata::cre ate(metadata));
233 } 231 }
234 232
235 // FileWriterBaseCallbacks ---------------------------------------------------- 233 // FileWriterBaseCallbacks ----------------------------------------------------
236 234
237 std::unique_ptr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create(FileWr iterBase* fileWriter, FileWriterBaseCallback* successCallback, ErrorCallback* er rorCallback, ExecutionContext* context) 235 PassOwnPtr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create(FileWriterB ase* fileWriter, FileWriterBaseCallback* successCallback, ErrorCallback* errorCa llback, ExecutionContext* context)
238 { 236 {
239 return wrapUnique(new FileWriterBaseCallbacks(fileWriter, successCallback, e rrorCallback, context)); 237 return adoptPtr(new FileWriterBaseCallbacks(fileWriter, successCallback, err orCallback, context));
240 } 238 }
241 239
242 FileWriterBaseCallbacks::FileWriterBaseCallbacks(FileWriterBase* fileWriter, Fil eWriterBaseCallback* successCallback, ErrorCallback* errorCallback, ExecutionCon text* context) 240 FileWriterBaseCallbacks::FileWriterBaseCallbacks(FileWriterBase* fileWriter, Fil eWriterBaseCallback* successCallback, ErrorCallback* errorCallback, ExecutionCon text* context)
243 : FileSystemCallbacksBase(errorCallback, nullptr, context) 241 : FileSystemCallbacksBase(errorCallback, nullptr, context)
244 , m_fileWriter(fileWriter) 242 , m_fileWriter(fileWriter)
245 , m_successCallback(successCallback) 243 , m_successCallback(successCallback)
246 { 244 {
247 } 245 }
248 246
249 void FileWriterBaseCallbacks::didCreateFileWriter(std::unique_ptr<WebFileWriter> fileWriter, long long length) 247 void FileWriterBaseCallbacks::didCreateFileWriter(PassOwnPtr<WebFileWriter> file Writer, long long length)
250 { 248 {
251 m_fileWriter->initialize(std::move(fileWriter), length); 249 m_fileWriter->initialize(std::move(fileWriter), length);
252 if (m_successCallback) 250 if (m_successCallback)
253 handleEventOrScheduleCallback(m_successCallback.release(), m_fileWriter. release()); 251 handleEventOrScheduleCallback(m_successCallback.release(), m_fileWriter. release());
254 } 252 }
255 253
256 // SnapshotFileCallback ------------------------------------------------------- 254 // SnapshotFileCallback -------------------------------------------------------
257 255
258 std::unique_ptr<AsyncFileSystemCallbacks> SnapshotFileCallback::create(DOMFileSy stemBase* filesystem, const String& name, const KURL& url, BlobCallback* success Callback, ErrorCallback* errorCallback, ExecutionContext* context) 256 PassOwnPtr<AsyncFileSystemCallbacks> SnapshotFileCallback::create(DOMFileSystemB ase* filesystem, const String& name, const KURL& url, BlobCallback* successCallb ack, ErrorCallback* errorCallback, ExecutionContext* context)
259 { 257 {
260 return wrapUnique(new SnapshotFileCallback(filesystem, name, url, successCal lback, errorCallback, context)); 258 return adoptPtr(new SnapshotFileCallback(filesystem, name, url, successCallb ack, errorCallback, context));
261 } 259 }
262 260
263 SnapshotFileCallback::SnapshotFileCallback(DOMFileSystemBase* filesystem, const String& name, const KURL& url, BlobCallback* successCallback, ErrorCallback* err orCallback, ExecutionContext* context) 261 SnapshotFileCallback::SnapshotFileCallback(DOMFileSystemBase* filesystem, const String& name, const KURL& url, BlobCallback* successCallback, ErrorCallback* err orCallback, ExecutionContext* context)
264 : FileSystemCallbacksBase(errorCallback, filesystem, context) 262 : FileSystemCallbacksBase(errorCallback, filesystem, context)
265 , m_name(name) 263 , m_name(name)
266 , m_url(url) 264 , m_url(url)
267 , m_successCallback(successCallback) 265 , m_successCallback(successCallback)
268 { 266 {
269 } 267 }
270 268
271 void SnapshotFileCallback::didCreateSnapshotFile(const FileMetadata& metadata, P assRefPtr<BlobDataHandle> snapshot) 269 void SnapshotFileCallback::didCreateSnapshotFile(const FileMetadata& metadata, P assRefPtr<BlobDataHandle> snapshot)
272 { 270 {
273 if (!m_successCallback) 271 if (!m_successCallback)
274 return; 272 return;
275 273
276 // We can't directly use the snapshot blob data handle because the content t ype on it hasn't been set. 274 // We can't directly use the snapshot blob data handle because the content t ype on it hasn't been set.
277 // The |snapshot| param is here to provide a a chain of custody thru thread bridging that is held onto until 275 // The |snapshot| param is here to provide a a chain of custody thru thread bridging that is held onto until
278 // *after* we've coined a File with a new handle that has the correct type s et on it. This allows the 276 // *after* we've coined a File with a new handle that has the correct type s et on it. This allows the
279 // blob storage system to track when a temp file can and can't be safely del eted. 277 // blob storage system to track when a temp file can and can't be safely del eted.
280 278
281 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystemBase ::createFile(metadata, m_url, m_fileSystem->type(), m_name)); 279 handleEventOrScheduleCallback(m_successCallback.release(), DOMFileSystemBase ::createFile(metadata, m_url, m_fileSystem->type(), m_name));
282 } 280 }
283 281
284 // VoidCallbacks -------------------------------------------------------------- 282 // VoidCallbacks --------------------------------------------------------------
285 283
286 std::unique_ptr<AsyncFileSystemCallbacks> VoidCallbacks::create(VoidCallback* su ccessCallback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileS ystemBase* fileSystem) 284 PassOwnPtr<AsyncFileSystemCallbacks> VoidCallbacks::create(VoidCallback* success Callback, ErrorCallback* errorCallback, ExecutionContext* context, DOMFileSystem Base* fileSystem)
287 { 285 {
288 return wrapUnique(new VoidCallbacks(successCallback, errorCallback, context, fileSystem)); 286 return adoptPtr(new VoidCallbacks(successCallback, errorCallback, context, f ileSystem));
289 } 287 }
290 288
291 VoidCallbacks::VoidCallbacks(VoidCallback* successCallback, ErrorCallback* error Callback, ExecutionContext* context, DOMFileSystemBase* fileSystem) 289 VoidCallbacks::VoidCallbacks(VoidCallback* successCallback, ErrorCallback* error Callback, ExecutionContext* context, DOMFileSystemBase* fileSystem)
292 : FileSystemCallbacksBase(errorCallback, fileSystem, context) 290 : FileSystemCallbacksBase(errorCallback, fileSystem, context)
293 , m_successCallback(successCallback) 291 , m_successCallback(successCallback)
294 { 292 {
295 } 293 }
296 294
297 void VoidCallbacks::didSucceed() 295 void VoidCallbacks::didSucceed()
298 { 296 {
299 if (m_successCallback) 297 if (m_successCallback)
300 handleEventOrScheduleCallback(m_successCallback.release()); 298 handleEventOrScheduleCallback(m_successCallback.release());
301 } 299 }
302 300
303 } // namespace blink 301 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698