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

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

Issue 2782373002: Remove MediaControls methods needed for the Cast button (Closed)
Patch Set: Rebased Created 3 years, 8 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 9e4ef798287770377e66decdf769141fe347ed58..b7af6cd1b1d9d11a6379c64143e017fbcc03058b 100644
--- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
+++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp
@@ -86,28 +86,10 @@ ScriptPromise RemotePlayback::watchAvailability(
return promise;
}
- int id;
- do {
- id = GetExecutionContext()->CircularSequentialID();
- } while (
- !availability_callbacks_
- .insert(id, TraceWrapperMember<RemotePlaybackAvailabilityCallback>(
- this, callback))
- .is_new_entry);
-
- // Report the current availability via the callback.
- // 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);
- probe::AsyncTaskScheduled(GetExecutionContext(), "watchAvailabilityCallback",
- task.get());
- TaskRunnerHelper::Get(TaskType::kMediaElementEvent, GetExecutionContext())
- ->PostTask(BLINK_FROM_HERE,
- WTF::Bind(RunNotifyInitialAvailabilityTask,
- WrapPersistent(GetExecutionContext()),
- WTF::Passed(std::move(task))));
+ std::unique_ptr<WTF::Closure> callback_closure =
+ WTF::Bind(&RemotePlayback::AvailabilityCallbackWithBindings,
+ WrapPersistent(this), WrapPersistent(callback));
+ int id = WatchAvailabilityInternal(std::move(callback_closure));
// 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
@@ -130,15 +112,12 @@ ScriptPromise RemotePlayback::cancelWatchAvailability(ScriptState* script_state,
return promise;
}
- auto iter = availability_callbacks_.Find(id);
- if (iter == availability_callbacks_.end()) {
+ if (!CancelWatchAvailabilityInternal(id)) {
resolver->Reject(DOMException::Create(
kNotFoundError, "A callback with the given id is not found."));
return promise;
}
- availability_callbacks_.erase(iter);
-
resolver->Resolve();
return promise;
}
@@ -200,13 +179,8 @@ ScriptPromise RemotePlayback::prompt(ScriptState* script_state) {
return promise;
}
- if (state_ == WebRemotePlaybackState::kDisconnected) {
- prompt_promise_resolver_ = resolver;
- media_element_->RequestRemotePlayback();
- } else {
- prompt_promise_resolver_ = resolver;
- media_element_->RequestRemotePlaybackControl();
- }
+ prompt_promise_resolver_ = resolver;
+ PromptInternal();
return promise;
}
@@ -220,13 +194,57 @@ bool RemotePlayback::HasPendingActivity() const {
prompt_promise_resolver_;
}
+void RemotePlayback::PromptInternal() {
+ if (state_ == WebRemotePlaybackState::kDisconnected)
+ media_element_->RequestRemotePlayback();
+ else
+ media_element_->RequestRemotePlaybackControl();
+}
+
+int RemotePlayback::WatchAvailabilityInternal(
+ std::unique_ptr<WTF::Closure> callback) {
+ Member<WTF::Closure> callback_member(callback.release());
+ int id;
+ do {
+ id = GetExecutionContext()->CircularSequentialID();
+ } while (!availability_callbacks_.insert(id, callback_member).is_new_entry);
+
+ // Report the current availability via the callback.
+ // 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);
+ probe::AsyncTaskScheduled(GetExecutionContext(), "watchAvailabilityCallback",
+ task.get());
+ TaskRunnerHelper::Get(TaskType::kMediaElementEvent, GetExecutionContext())
+ ->PostTask(BLINK_FROM_HERE,
+ WTF::Bind(RunNotifyInitialAvailabilityTask,
+ WrapPersistent(GetExecutionContext()),
+ WTF::Passed(std::move(task))));
+ return id;
+}
+
+bool RemotePlayback::CancelWatchAvailabilityInternal(int id) {
+ auto iter = availability_callbacks_.Find(id);
+ if (iter == availability_callbacks_.end())
+ return false;
+ availability_callbacks_.erase(iter);
+ return true;
+}
+
+void RemotePlayback::AvailabilityCallbackWithBindings(
+ RemotePlaybackAvailabilityCallback* callback) {
+ callback->call(this, RemotePlaybackAvailable());
+}
+
void RemotePlayback::NotifyInitialAvailability(int callback_id) {
// May not find the callback if the website cancels it fast enough.
auto iter = availability_callbacks_.Find(callback_id);
if (iter == availability_callbacks_.end())
return;
- iter->value->call(this, RemotePlaybackAvailable());
+ (*iter->value)();
}
void RemotePlayback::StateChanged(WebRemotePlaybackState state) {
@@ -278,7 +296,7 @@ void RemotePlayback::AvailabilityChanged(
return;
for (auto& callback : availability_callbacks_.Values())
- callback->call(this, new_availability);
+ (*callback)();
}
void RemotePlayback::PromptCancelled() {
@@ -314,11 +332,4 @@ DEFINE_TRACE(RemotePlayback) {
EventTargetWithInlineData::Trace(visitor);
}
-DEFINE_TRACE_WRAPPERS(RemotePlayback) {
- for (auto callback : availability_callbacks_.Values()) {
- visitor->TraceWrappers(callback);
- }
- EventTargetWithInlineData::TraceWrappers(visitor);
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698