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

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

Issue 435423004: DevTools: Async call stacks for FileSystem API part 1 (second try). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 blink { 57 namespace blink {
57 58
58 FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error Callback, DOMFileSystemBase* fileSystem, ExecutionContext* context) 59 FileSystemCallbacksBase::FileSystemCallbacksBase(PassOwnPtr<ErrorCallback> error Callback, DOMFileSystemBase* fileSystem, ExecutionContext* context)
59 : m_errorCallback(errorCallback) 60 : m_errorCallback(errorCallback)
60 , m_fileSystem(fileSystem) 61 , m_fileSystem(fileSystem)
61 , m_executionContext(context) 62 , m_executionContext(context)
63 , m_asyncOperationId(0)
62 { 64 {
63 if (m_fileSystem) 65 if (m_fileSystem)
64 m_fileSystem->addPendingCallbacks(); 66 m_fileSystem->addPendingCallbacks();
67 if (m_executionContext)
68 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti ng(m_executionContext.get(), "FileSystem");
65 } 69 }
66 70
67 FileSystemCallbacksBase::~FileSystemCallbacksBase() 71 FileSystemCallbacksBase::~FileSystemCallbacksBase()
68 { 72 {
69 if (m_fileSystem) 73 if (m_fileSystem)
70 m_fileSystem->removePendingCallbacks(); 74 m_fileSystem->removePendingCallbacks();
75 if (m_asyncOperationId && m_executionContext)
76 InspectorInstrumentation::traceAsyncOperationCompleted(m_executionContex t.get(), m_asyncOperationId);
71 } 77 }
72 78
73 void FileSystemCallbacksBase::didFail(int code) 79 void FileSystemCallbacksBase::didFail(int code)
74 { 80 {
75 if (m_errorCallback) 81 if (m_errorCallback)
76 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea te(static_cast<FileError::ErrorCode>(code))); 82 handleEventOrScheduleCallback(m_errorCallback.release(), FileError::crea te(static_cast<FileError::ErrorCode>(code)));
77 } 83 }
78 84
79 bool FileSystemCallbacksBase::shouldScheduleCallback() const 85 bool FileSystemCallbacksBase::shouldScheduleCallback() const
80 { 86 {
81 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon text->activeDOMObjectsAreSuspended(); 87 return !shouldBlockUntilCompletion() && m_executionContext && m_executionCon text->activeDOMObjectsAreSuspended();
82 } 88 }
83 89
84 template <typename CB, typename CBArg> 90 template <typename CB, typename CBArg>
85 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, CBArg* arg) 91 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, CBArg* arg)
86 { 92 {
87 ASSERT(callback.get()); 93 ASSERT(callback.get());
94 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync OperationCompletedCallbackStarting(m_executionContext.get(), m_asyncOperationId) ;
88 if (shouldScheduleCallback()) 95 if (shouldScheduleCallback())
89 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ; 96 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ;
90 else if (callback) 97 else if (callback)
91 callback->handleEvent(arg); 98 callback->handleEvent(arg);
92 m_executionContext.clear(); 99 m_executionContext.clear();
100 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
93 } 101 }
94 102
95 template <typename CB, typename CBArg> 103 template <typename CB, typename CBArg>
96 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, PassRefPtrWillBeRawPtr<CBArg> arg) 104 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack, PassRefPtrWillBeRawPtr<CBArg> arg)
97 { 105 {
98 ASSERT(callback.get()); 106 ASSERT(callback.get());
107 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync OperationCompletedCallbackStarting(m_executionContext.get(), m_asyncOperationId) ;
99 if (shouldScheduleCallback()) 108 if (shouldScheduleCallback())
100 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ; 109 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback, arg) ;
101 else if (callback) 110 else if (callback)
102 callback->handleEvent(arg.get()); 111 callback->handleEvent(arg.get());
103 m_executionContext.clear(); 112 m_executionContext.clear();
113 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
104 } 114 }
105 115
106 template <typename CB> 116 template <typename CB>
107 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack) 117 void FileSystemCallbacksBase::handleEventOrScheduleCallback(PassOwnPtr<CB> callb ack)
108 { 118 {
109 ASSERT(callback.get()); 119 ASSERT(callback.get());
120 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync OperationCompletedCallbackStarting(m_executionContext.get(), m_asyncOperationId) ;
110 if (shouldScheduleCallback()) 121 if (shouldScheduleCallback())
111 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback); 122 DOMFileSystem::scheduleCallback(m_executionContext.get(), callback);
112 else if (callback) 123 else if (callback)
113 callback->handleEvent(); 124 callback->handleEvent();
114 m_executionContext.clear(); 125 m_executionContext.clear();
126 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
115 } 127 }
116 128
117 // EntryCallbacks ------------------------------------------------------------- 129 // EntryCallbacks -------------------------------------------------------------
118 130
119 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(PassOwnPtr<EntryCall back> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext * context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDir ectory) 131 PassOwnPtr<AsyncFileSystemCallbacks> EntryCallbacks::create(PassOwnPtr<EntryCall back> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext * context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDir ectory)
120 { 132 {
121 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context, fileSystem, expectedPath, isDirectory)); 133 return adoptPtr(new EntryCallbacks(successCallback, errorCallback, context, fileSystem, expectedPath, isDirectory));
122 } 134 }
123 135
124 EntryCallbacks::EntryCallbacks(PassOwnPtr<EntryCallback> successCallback, PassOw nPtr<ErrorCallback> errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDirectory) 136 EntryCallbacks::EntryCallbacks(PassOwnPtr<EntryCallback> successCallback, PassOw nPtr<ErrorCallback> errorCallback, ExecutionContext* context, DOMFileSystemBase* fileSystem, const String& expectedPath, bool isDirectory)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 else 174 else
163 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF ilePath::append(m_basePath, name))); 175 m_entries.append(FileEntry::create(m_directoryReader->filesystem(), DOMF ilePath::append(m_basePath, name)));
164 } 176 }
165 177
166 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) 178 void EntriesCallbacks::didReadDirectoryEntries(bool hasMore)
167 { 179 {
168 m_directoryReader->setHasMoreEntries(hasMore); 180 m_directoryReader->setHasMoreEntries(hasMore);
169 EntryHeapVector entries; 181 EntryHeapVector entries;
170 entries.swap(m_entries); 182 entries.swap(m_entries);
171 // FIXME: delay the callback iff shouldScheduleCallback() is true. 183 // FIXME: delay the callback iff shouldScheduleCallback() is true.
184 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync CallbackStarting(m_executionContext.get(), m_asyncOperationId);
172 if (m_successCallback) 185 if (m_successCallback)
173 m_successCallback->handleEvent(entries); 186 m_successCallback->handleEvent(entries);
187 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
188 if (!hasMore)
189 InspectorInstrumentation::traceAsyncOperationCompleted(m_executionContex t.get(), m_asyncOperationId);
174 } 190 }
175 191
176 // FileSystemCallbacks -------------------------------------------------------- 192 // FileSystemCallbacks --------------------------------------------------------
177 193
178 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(PassOwnPtr<File SystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Execut ionContext* context, FileSystemType type) 194 PassOwnPtr<AsyncFileSystemCallbacks> FileSystemCallbacks::create(PassOwnPtr<File SystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, Execut ionContext* context, FileSystemType type)
179 { 195 {
180 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont ext, type)); 196 return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, cont ext, type));
181 } 197 }
182 198
183 FileSystemCallbacks::FileSystemCallbacks(PassOwnPtr<FileSystemCallback> successC allback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext* context, Fil eSystemType type) 199 FileSystemCallbacks::FileSystemCallbacks(PassOwnPtr<FileSystemCallback> successC allback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext* context, Fil eSystemType type)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 { 332 {
317 } 333 }
318 334
319 void VoidCallbacks::didSucceed() 335 void VoidCallbacks::didSucceed()
320 { 336 {
321 if (m_successCallback) 337 if (m_successCallback)
322 handleEventOrScheduleCallback(m_successCallback.release()); 338 handleEventOrScheduleCallback(m_successCallback.release());
323 } 339 }
324 340
325 } // namespace 341 } // namespace
OLDNEW
« Source/modules/filesystem/DOMFileSystem.h ('K') | « Source/modules/filesystem/FileSystemCallbacks.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698