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

Unified Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp

Issue 2698153003: Reduce createSameThreadTask usage in modules/ (Closed)
Patch Set: Move a static callback to an anonymous namespace Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
diff --git a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
index f16fb0eea9dbcc423b02d6c46bc693933f981984..3a266f590fad4bedbcf6da978dbc62b4fdea0a66 100644
--- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
+++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
@@ -9,10 +9,10 @@
#include "core/HTMLNames.h"
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
-#include "core/dom/ExecutionContextTask.h"
#include "core/dom/TaskRunnerHelper.h"
#include "core/events/Event.h"
#include "core/html/HTMLMediaElement.h"
+#include "core/inspector/InspectorInstrumentation.h"
#include "modules/EventTargetModules.h"
#include "platform/MemoryCoordinator.h"
#include "platform/UserGestureIndicator.h"
@@ -39,6 +39,12 @@ const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) {
return disconnectedValue;
}
+void runNotifyInitialAvailabilityTask(ExecutionContext* context,
+ std::unique_ptr<WTF::Closure> task) {
+ InspectorInstrumentation::AsyncTask asyncTask(context, task.get());
+ (*task)();
+}
+
} // anonymous namespace
// static
@@ -90,11 +96,18 @@ ScriptPromise RemotePlayback::watchAvailability(
.isNewEntry);
// Report the current availability via the callback.
- getExecutionContext()->postTask(
- TaskType::MediaElementEvent, BLINK_FROM_HERE,
- createSameThreadTask(&RemotePlayback::notifyInitialAvailability,
- wrapPersistent(this), id),
- "watchAvailabilityCallback");
+ // TODO(yuryu): Wrapping notifyInitialAvailability with WTF::Closure as
+ // InspectorInstrumentation requires a globally unique pointer to track tasks.
+ // We can remove the wrapper if InspectorInstrumentation returns a task id.
+ std::unique_ptr<WTF::Closure> task = WTF::bind(
+ &RemotePlayback::notifyInitialAvailability, wrapPersistent(this), id);
+ InspectorInstrumentation::asyncTaskScheduled(
+ getExecutionContext(), "watchAvailabilityCallback", task.get());
+ TaskRunnerHelper::get(TaskType::MediaElementEvent, getExecutionContext())
+ ->postTask(BLINK_FROM_HERE,
+ WTF::bind(runNotifyInitialAvailabilityTask,
+ wrapPersistent(getExecutionContext()),
+ WTF::passed(std::move(task))));
// TODO(avayvod): Currently the availability is tracked for each media element
// as soon as it's created, we probably want to limit that to when the

Powered by Google App Engine
This is Rietveld 408576698