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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2507673002: Scheduler: Deprecate CancellableTaskFactory in favor of WebTaskRunner::postCancellableTask (2) (Closed)
Patch Set: rebase Created 4 years, 1 month 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) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "platform/ContentType.h" 75 #include "platform/ContentType.h"
76 #include "platform/Histogram.h" 76 #include "platform/Histogram.h"
77 #include "platform/LayoutTestSupport.h" 77 #include "platform/LayoutTestSupport.h"
78 #include "platform/MIMETypeFromURL.h" 78 #include "platform/MIMETypeFromURL.h"
79 #include "platform/RuntimeEnabledFeatures.h" 79 #include "platform/RuntimeEnabledFeatures.h"
80 #include "platform/UserGestureIndicator.h" 80 #include "platform/UserGestureIndicator.h"
81 #include "platform/audio/AudioBus.h" 81 #include "platform/audio/AudioBus.h"
82 #include "platform/audio/AudioSourceProviderClient.h" 82 #include "platform/audio/AudioSourceProviderClient.h"
83 #include "platform/graphics/GraphicsLayer.h" 83 #include "platform/graphics/GraphicsLayer.h"
84 #include "platform/mediastream/MediaStreamDescriptor.h" 84 #include "platform/mediastream/MediaStreamDescriptor.h"
85 #include "platform/scheduler/CancellableTaskFactory.h"
86 #include "platform/weborigin/SecurityOrigin.h" 85 #include "platform/weborigin/SecurityOrigin.h"
87 #include "public/platform/Platform.h" 86 #include "public/platform/Platform.h"
88 #include "public/platform/WebAudioSourceProvider.h" 87 #include "public/platform/WebAudioSourceProvider.h"
89 #include "public/platform/WebContentDecryptionModule.h" 88 #include "public/platform/WebContentDecryptionModule.h"
90 #include "public/platform/WebInbandTextTrack.h" 89 #include "public/platform/WebInbandTextTrack.h"
91 #include "public/platform/WebMediaPlayerSource.h" 90 #include "public/platform/WebMediaPlayerSource.h"
92 #include "public/platform/WebMediaStream.h" 91 #include "public/platform/WebMediaStream.h"
93 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h " 92 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h "
94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" 93 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h"
95 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" 94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 m_ignorePreloadNone(false), 444 m_ignorePreloadNone(false),
446 m_textTracksVisible(false), 445 m_textTracksVisible(false),
447 m_shouldPerformAutomaticTrackSelection(true), 446 m_shouldPerformAutomaticTrackSelection(true),
448 m_tracksAreReady(true), 447 m_tracksAreReady(true),
449 m_processingPreferenceChange(false), 448 m_processingPreferenceChange(false),
450 m_playingRemotely(false), 449 m_playingRemotely(false),
451 m_inOverlayFullscreenVideo(false), 450 m_inOverlayFullscreenVideo(false),
452 m_audioTracks(this, AudioTrackList::create(*this)), 451 m_audioTracks(this, AudioTrackList::create(*this)),
453 m_videoTracks(this, VideoTrackList::create(*this)), 452 m_videoTracks(this, VideoTrackList::create(*this)),
454 m_textTracks(this, nullptr), 453 m_textTracks(this, nullptr),
455 m_playPromiseResolveTask(CancellableTaskFactory::create(
456 this,
457 &HTMLMediaElement::resolveScheduledPlayPromises)),
458 m_playPromiseRejectTask(CancellableTaskFactory::create(
459 this,
460 &HTMLMediaElement::rejectScheduledPlayPromises)),
461 m_audioSourceNode(nullptr), 454 m_audioSourceNode(nullptr),
462 m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)), 455 m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)),
463 m_autoplayHelper( 456 m_autoplayHelper(
464 AutoplayExperimentHelper::create(m_autoplayHelperClient.get())), 457 AutoplayExperimentHelper::create(m_autoplayHelperClient.get())),
465 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), 458 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)),
466 m_remotePlaybackClient(nullptr), 459 m_remotePlaybackClient(nullptr),
467 m_autoplayVisibilityObserver(nullptr) { 460 m_autoplayVisibilityObserver(nullptr) {
468 ThreadState::current()->registerPreFinalizer(this); 461 ThreadState::current()->registerPreFinalizer(this);
469 462
470 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; 463 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // play promises or project pending play prmoises algorithms, immediately 778 // play promises or project pending play prmoises algorithms, immediately
786 // resolve or reject those promises in the order the corresponding tasks 779 // resolve or reject those promises in the order the corresponding tasks
787 // were queued. 780 // were queued.
788 // 781 //
789 // TODO(mlamouri): the promises are first resolved then rejected but the 782 // TODO(mlamouri): the promises are first resolved then rejected but the
790 // order between resolved/rejected promises isn't respected. This could be 783 // order between resolved/rejected promises isn't respected. This could be
791 // improved when the same task is used for both cases. 784 // improved when the same task is used for both cases.
792 // 785 //
793 // TODO(mlamouri): don't run the callback synchronously if we are not allowed 786 // TODO(mlamouri): don't run the callback synchronously if we are not allowed
794 // to run scripts. It can happen in some edge cases. https://crbug.com/660382 787 // to run scripts. It can happen in some edge cases. https://crbug.com/660382
795 if (m_playPromiseResolveTask->isPending() && 788 if (m_playPromiseResolveTaskHandle.isActive() &&
796 !ScriptForbiddenScope::isScriptForbidden()) { 789 !ScriptForbiddenScope::isScriptForbidden()) {
797 m_playPromiseResolveTask->cancel(); 790 m_playPromiseResolveTaskHandle.cancel();
798 resolveScheduledPlayPromises(); 791 resolveScheduledPlayPromises();
799 } 792 }
800 if (m_playPromiseRejectTask->isPending() && 793 if (m_playPromiseRejectTaskHandle.isActive() &&
801 !ScriptForbiddenScope::isScriptForbidden()) { 794 !ScriptForbiddenScope::isScriptForbidden()) {
802 m_playPromiseRejectTask->cancel(); 795 m_playPromiseRejectTaskHandle.cancel();
803 rejectScheduledPlayPromises(); 796 rejectScheduledPlayPromises();
804 } 797 }
805 798
806 // 4 - Remove each task in pending tasks from its task queue. 799 // 4 - Remove each task in pending tasks from its task queue.
807 cancelPendingEventsAndCallbacks(); 800 cancelPendingEventsAndCallbacks();
808 801
809 // 5 - If the media element's networkState is set to NETWORK_LOADING or 802 // 5 - If the media element's networkState is set to NETWORK_LOADING or
810 // NETWORK_IDLE, queue a task to fire a simple event named abort at the media 803 // NETWORK_IDLE, queue a task to fire a simple event named abort at the media
811 // element. 804 // element.
812 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) 805 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle)
(...skipping 3149 matching lines...) Expand 10 before | Expand all | Expand 10 after
3962 } 3955 }
3963 3956
3964 void HTMLMediaElement::scheduleResolvePlayPromises() { 3957 void HTMLMediaElement::scheduleResolvePlayPromises() {
3965 // TODO(mlamouri): per spec, we should create a new task but we can't create 3958 // TODO(mlamouri): per spec, we should create a new task but we can't create
3966 // a new cancellable task without cancelling the previous one. There are two 3959 // a new cancellable task without cancelling the previous one. There are two
3967 // approaches then: cancel the previous task and create a new one with the 3960 // approaches then: cancel the previous task and create a new one with the
3968 // appended promise list or append the new promise to the current list. The 3961 // appended promise list or append the new promise to the current list. The
3969 // latter approach is preferred because it might be the less observable 3962 // latter approach is preferred because it might be the less observable
3970 // change. 3963 // change.
3971 DCHECK(m_playPromiseResolveList.isEmpty() || 3964 DCHECK(m_playPromiseResolveList.isEmpty() ||
3972 m_playPromiseResolveTask->isPending()); 3965 m_playPromiseResolveTaskHandle.isActive());
3973 if (m_playPromiseResolvers.isEmpty()) 3966 if (m_playPromiseResolvers.isEmpty())
3974 return; 3967 return;
3975 3968
3976 m_playPromiseResolveList.appendVector(m_playPromiseResolvers); 3969 m_playPromiseResolveList.appendVector(m_playPromiseResolvers);
3977 m_playPromiseResolvers.clear(); 3970 m_playPromiseResolvers.clear();
3978 3971
3979 if (m_playPromiseResolveTask->isPending()) 3972 if (m_playPromiseResolveTaskHandle.isActive())
3980 return; 3973 return;
3981 3974
3982 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document()) 3975 // wrapWeakPersistent(this) is safe because a posted task is canceled when the
3983 ->postTask(BLINK_FROM_HERE, m_playPromiseResolveTask->cancelAndCreate()); 3976 // task handle is destroyed on the dtor of this HTMLMediaElement.
3977 m_playPromiseResolveTaskHandle =
3978 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document())
3979 ->postCancellableTask(
3980 BLINK_FROM_HERE,
3981 WTF::bind(&HTMLMediaElement::resolveScheduledPlayPromises,
3982 wrapWeakPersistent(this)));
haraken 2016/11/17 06:35:19 I'm not 100% sure, but this should probably be wra
nhiroki 2016/11/17 08:10:15 Before this CL, CancellableTaskFactory posts a tas
3984 } 3983 }
3985 3984
3986 void HTMLMediaElement::scheduleRejectPlayPromises(ExceptionCode code) { 3985 void HTMLMediaElement::scheduleRejectPlayPromises(ExceptionCode code) {
3987 // TODO(mlamouri): per spec, we should create a new task but we can't create 3986 // TODO(mlamouri): per spec, we should create a new task but we can't create
3988 // a new cancellable task without cancelling the previous one. There are two 3987 // a new cancellable task without cancelling the previous one. There are two
3989 // approaches then: cancel the previous task and create a new one with the 3988 // approaches then: cancel the previous task and create a new one with the
3990 // appended promise list or append the new promise to the current list. The 3989 // appended promise list or append the new promise to the current list. The
3991 // latter approach is preferred because it might be the less observable 3990 // latter approach is preferred because it might be the less observable
3992 // change. 3991 // change.
3993 DCHECK(m_playPromiseRejectList.isEmpty() || 3992 DCHECK(m_playPromiseRejectList.isEmpty() ||
3994 m_playPromiseRejectTask->isPending()); 3993 m_playPromiseRejectTaskHandle.isActive());
3995 if (m_playPromiseResolvers.isEmpty()) 3994 if (m_playPromiseResolvers.isEmpty())
3996 return; 3995 return;
3997 3996
3998 m_playPromiseRejectList.appendVector(m_playPromiseResolvers); 3997 m_playPromiseRejectList.appendVector(m_playPromiseResolvers);
3999 m_playPromiseResolvers.clear(); 3998 m_playPromiseResolvers.clear();
4000 3999
4001 if (m_playPromiseRejectTask->isPending()) 4000 if (m_playPromiseRejectTaskHandle.isActive())
4002 return; 4001 return;
4003 4002
4004 // TODO(mlamouri): because cancellable tasks can't take parameters, the 4003 // TODO(mlamouri): because cancellable tasks can't take parameters, the
4005 // error code needs to be saved. 4004 // error code needs to be saved.
tzik 2016/11/17 06:20:15 Can we put m_playPromiseErrorCode into the closure
nhiroki 2016/11/17 08:10:16 Done.
4006 m_playPromiseErrorCode = code; 4005 m_playPromiseErrorCode = code;
4007 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document()) 4006
4008 ->postTask(BLINK_FROM_HERE, m_playPromiseRejectTask->cancelAndCreate()); 4007 // wrapWeakPersistent(this) is safe because a posted task is canceled when the
4008 // task handle is destroyed on the dtor of this HTMLMediaElement.
tzik 2016/11/17 06:20:15 "wrapWeakPersistent(this) is safe because..." soun
nhiroki 2016/11/17 08:10:15 Good point. Removed the comment entirely.
4009 m_playPromiseRejectTaskHandle =
4010 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document())
4011 ->postCancellableTask(
4012 BLINK_FROM_HERE,
4013 WTF::bind(&HTMLMediaElement::rejectScheduledPlayPromises,
4014 wrapWeakPersistent(this)));
haraken 2016/11/17 06:35:19 Ditto.
4009 } 4015 }
4010 4016
4011 void HTMLMediaElement::scheduleNotifyPlaying() { 4017 void HTMLMediaElement::scheduleNotifyPlaying() {
4012 scheduleEvent(EventTypeNames::playing); 4018 scheduleEvent(EventTypeNames::playing);
4013 scheduleResolvePlayPromises(); 4019 scheduleResolvePlayPromises();
4014 } 4020 }
4015 4021
4016 void HTMLMediaElement::resolveScheduledPlayPromises() { 4022 void HTMLMediaElement::resolveScheduledPlayPromises() {
4017 for (auto& resolver : m_playPromiseResolveList) 4023 for (auto& resolver : m_playPromiseResolveList)
4018 resolver->resolve(); 4024 resolver->resolve();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 4193
4188 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4194 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4189 const { 4195 const {
4190 IntRect result; 4196 IntRect result;
4191 if (LayoutObject* object = m_element->layoutObject()) 4197 if (LayoutObject* object = m_element->layoutObject())
4192 result = object->absoluteBoundingBoxRect(); 4198 result = object->absoluteBoundingBoxRect();
4193 return result; 4199 return result;
4194 } 4200 }
4195 4201
4196 } // namespace blink 4202 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698