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

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

Issue 383123009: DevTools: Support async call stacks for FileSystem API (part 1). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | 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 17 matching lines...) Expand all
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/FileSystemCallbacks.h" 32 #include "modules/filesystem/FileSystemCallbacks.h"
33 33
34 #include "core/dom/ExecutionContext.h" 34 #include "core/dom/ExecutionContext.h"
35 #include "core/fileapi/File.h" 35 #include "core/fileapi/File.h"
36 #include "core/fileapi/FileError.h" 36 #include "core/fileapi/FileError.h"
37 #include "core/html/VoidCallback.h" 37 #include "core/html/VoidCallback.h"
38 #include "core/inspector/InspectorInstrumentation.h"
38 #include "modules/filesystem/DOMFilePath.h" 39 #include "modules/filesystem/DOMFilePath.h"
39 #include "modules/filesystem/DOMFileSystem.h" 40 #include "modules/filesystem/DOMFileSystem.h"
40 #include "modules/filesystem/DOMFileSystemBase.h" 41 #include "modules/filesystem/DOMFileSystemBase.h"
41 #include "modules/filesystem/DirectoryEntry.h" 42 #include "modules/filesystem/DirectoryEntry.h"
42 #include "modules/filesystem/DirectoryReader.h" 43 #include "modules/filesystem/DirectoryReader.h"
43 #include "modules/filesystem/Entry.h" 44 #include "modules/filesystem/Entry.h"
44 #include "modules/filesystem/EntryCallback.h" 45 #include "modules/filesystem/EntryCallback.h"
45 #include "modules/filesystem/ErrorCallback.h" 46 #include "modules/filesystem/ErrorCallback.h"
46 #include "modules/filesystem/FileCallback.h" 47 #include "modules/filesystem/FileCallback.h"
47 #include "modules/filesystem/FileEntry.h" 48 #include "modules/filesystem/FileEntry.h"
48 #include "modules/filesystem/FileSystemCallback.h" 49 #include "modules/filesystem/FileSystemCallback.h"
49 #include "modules/filesystem/FileWriterBase.h" 50 #include "modules/filesystem/FileWriterBase.h"
50 #include "modules/filesystem/FileWriterBaseCallback.h" 51 #include "modules/filesystem/FileWriterBaseCallback.h"
51 #include "modules/filesystem/Metadata.h" 52 #include "modules/filesystem/Metadata.h"
52 #include "modules/filesystem/MetadataCallback.h" 53 #include "modules/filesystem/MetadataCallback.h"
53 #include "platform/FileMetadata.h" 54 #include "platform/FileMetadata.h"
54 #include "public/platform/WebFileWriter.h" 55 #include "public/platform/WebFileWriter.h"
55 56
56 namespace WebCore { 57 namespace WebCore {
57 58
59 namespace {
60
61 class HandleCallbackScope FINAL {
62 WTF_MAKE_NONCOPYABLE(HandleCallbackScope);
63 public:
64 HandleCallbackScope(PassRefPtrWillBeRawPtr<ExecutionContext> executionContex t, FileSystemCallbacksBase* callback, bool reschedule = false, bool hasMore = fa lse)
65 : m_executionContext(executionContext)
66 , m_callback(callback)
67 , m_reschedule(reschedule)
68 {
69 if (m_executionContext)
70 InspectorInstrumentation::willHandleAsyncFileSystemCallback(m_execut ionContext.get(), m_callback, m_reschedule, hasMore);
yurys 2014/07/14 14:55:54 Consider inlining these instrumentation calls. We
71 }
72
73 ~HandleCallbackScope()
74 {
75 if (m_executionContext)
76 InspectorInstrumentation::didHandleAsyncFileSystemCallback(m_executi onContext.get(), m_callback, m_reschedule);
77 }
78
79 private:
80 RefPtrWillBePersistent<ExecutionContext> m_executionContext;
81 FileSystemCallbacksBase* m_callback;
82 bool m_reschedule;
83 };
84
85 } // namespace
86
58 FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error Callback, DOMFileSystemBase* fileSystem, ExecutionContext* context) 87 FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error Callback, DOMFileSystemBase* fileSystem, ExecutionContext* context)
59 : m_errorCallback(errorCallback) 88 : m_errorCallback(errorCallback)
60 , m_fileSystem(fileSystem) 89 , m_fileSystem(fileSystem)
61 , m_executionContext(context) 90 , m_executionContext(context)
62 { 91 {
63 if (m_fileSystem) 92 if (m_fileSystem)
64 m_fileSystem->addPendingCallbacks(); 93 m_fileSystem->addPendingCallbacks();
94 if (m_executionContext)
95 InspectorInstrumentation::didEnqueueAsyncFileSystemCallback(m_executionC ontext.get(), this);
65 } 96 }
66 97
67 FileSystemCallbacksBase::~FileSystemCallbacksBase() 98 FileSystemCallbacksBase::~FileSystemCallbacksBase()
68 { 99 {
100 if (m_executionContext)
101 InspectorInstrumentation::didRemoveAsyncFileSystemCallback(m_executionCo ntext.get(), this);
69 if (m_fileSystem) 102 if (m_fileSystem)
70 m_fileSystem->removePendingCallbacks(); 103 m_fileSystem->removePendingCallbacks();
71 } 104 }
72 105
73 void FileSystemCallbacksBase::didFail(int code) 106 void FileSystemCallbacksBase::didFail(int code)
74 { 107 {
75 if (m_errorCallback) 108 if (m_errorCallback)
76 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea te(static_cast<FileError::ErrorCode>(code))); 109 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea te(static_cast<FileError::ErrorCode>(code)));
77 } 110 }
78 111
79 bool FileSystemCallbacksBase::shouldScheduleCallback() const 112 bool FileSystemCallbacksBase::shouldScheduleCallback() const
80 { 113 {
81 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon text->activeDOMObjectsAreSuspended(); 114 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon text->activeDOMObjectsAreSuspended();
82 } 115 }
83 116
84 template <typename CB, typename CBArg> 117 template <typename CB, typename CBArg>
85 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, CBArg* arg) 118 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, CBArg* arg)
86 { 119 {
87 ASSERT(callback.get()); 120 ASSERT(callback.get());
88 if (shouldScheduleCallback()) 121 if (shouldScheduleCallback()) {
122 HandleCallbackScope scope(m_executionContext, this, true /* reschedule * /);
89 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ; 123 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ;
90 else if (callback) 124 } else {
91 callback->handleEvent(arg); 125 HandleCallbackScope scope(m_executionContext, this);
126 if (callback)
127 callback->handleEvent(arg);
128 }
92 m_executionContext.clear(); 129 m_executionContext.clear();
93 } 130 }
94 131
95 template <typename CB, typename CBArg> 132 template <typename CB, typename CBArg>
96 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, PassRefPtrWillBeRawPtr<CBArg> arg) 133 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, PassRefPtrWillBeRawPtr<CBArg> arg)
97 { 134 {
98 ASSERT(callback.get()); 135 ASSERT(callback.get());
99 if (shouldScheduleCallback()) 136 if (shouldScheduleCallback()) {
137 HandleCallbackScope scope(m_executionContext, this, true /* reschedule * /);
100 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ; 138 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ;
101 else if (callback) 139 } else {
102 callback->handleEvent(arg.get()); 140 HandleCallbackScope scope(m_executionContext, this);
141 if (callback)
142 callback->handleEvent(arg.get());
143 }
103 m_executionContext.clear(); 144 m_executionContext.clear();
104 } 145 }
105 146
106 template <typename CB> 147 template <typename CB>
107 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack) 148 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack)
108 { 149 {
109 ASSERT(callback.get()); 150 ASSERT(callback.get());
110 if (shouldScheduleCallback()) 151 if (shouldScheduleCallback()) {
152 HandleCallbackScope scope(m_executionContext, this, true /* reschedule * /);
111 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback); 153 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback);
112 else if (callback) 154 } else {
113 callback->handleEvent(); 155 HandleCallbackScope scope(m_executionContext, this);
156 if (callback)
157 callback->handleEvent();
158 }
114 m_executionContext.clear(); 159 m_executionContext.clear();
115 } 160 }
116 161
117 // EntryCallbacks ------------------------------------------------------------- 162 // EntryCallbacks -------------------------------------------------------------
118 163
119 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(PassOwnPtr<EntryCall back> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext * context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDir ectory) 164 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(PassOwnPtr<EntryCall back> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext * context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDir ectory)
120 { 165 {
121 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context, fileSystem, expectedPath, isDirectory)); 166 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context, fileSystem, expectedPath, isDirectory));
122 } 167 }
123 168
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 else 207 else
163 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF ilePath::append(m_basePath, name))); 208 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF ilePath::append(m_basePath, name)));
164 } 209 }
165 210
166 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) 211 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore)
167 { 212 {
168 m_directoryReader->setHasMoreEntries(hasMore); 213 m_directoryReader->setHasMoreEntries(hasMore);
169 EntryHeapVector entries; 214 EntryHeapVector entries;
170 entries.swap(m_entries); 215 entries.swap(m_entries);
171 // FIXME: delay the callback iff shouldScheduleCallback() is true. 216 // FIXME: delay the callback iff shouldScheduleCallback() is true.
217 HandleCallbackScope scope(m_executionContext, this, false /* reschedule */, hasMore);
172 if (m_successCallback) 218 if (m_successCallback)
173 m_successCallback->handleEvent(entries); 219 m_successCallback->handleEvent(entries);
174 } 220 }
175 221
176 // FileSystemCallbacks -------------------------------------------------------- 222 // FileSystemCallbacks --------------------------------------------------------
177 223
178 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(PassOwnPtr<File SystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Execut ionContext* context, FileSystemType type) 224 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(PassOwnPtr<File SystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Execut ionContext* context, FileSystemType type)
179 { 225 {
180 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont ext, type)); 226 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont ext, type));
181 } 227 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 { 362 {
317 } 363 }
318 364
319 void VoidCallbacks::didSucceed() 365 void VoidCallbacks::didSucceed()
320 { 366 {
321 if (m_successCallback) 367 if (m_successCallback)
322 handleEventOrScheduleCallback(m_successCallback.release()); 368 handleEventOrScheduleCallback(m_successCallback.release());
323 } 369 }
324 370
325 } // namespace 371 } // namespace
OLDNEW
« Source/modules/filesystem/DOMFileSystem.h ('K') | « Source/modules/filesystem/DOMFileSystem.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698