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

Unified Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 1276143002: Defer media loading while on cellular networks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rework. Add tests. Fix singleton state. Created 5 years, 3 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/core/html/HTMLMediaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
index 614c6ce029563ab390b6395af1f1e283eed2f81d..11bc920351abb0c55bc7c83775645041964f2124 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -66,6 +66,7 @@
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/page/ChromeClient.h"
+#include "core/page/NetworkStateNotifier.h"
#include "platform/ContentType.h"
#include "platform/Logging.h"
#include "platform/MIMETypeFromURL.h"
@@ -247,6 +248,11 @@ static bool canLoadURL(const KURL& url, const ContentType& contentType, const St
return false;
}
+static bool shouldForcePreloadNoneForCellularNetwork()
+{
+ return networkStateNotifier().connectionType() == WebConnectionTypeCellular;
+}
+
void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric)
{
Platform::current()->histogramEnumeration("Blink.MediaElement.Autoplay", metric, NumberOfAutoplayMetrics);
@@ -1936,30 +1942,37 @@ void HTMLMediaElement::setPreload(const AtomicString& preload)
WebMediaPlayer::Preload HTMLMediaElement::preloadType() const
{
const AtomicString& preload = fastGetAttribute(preloadAttr);
+
+ WebMediaPlayer::Preload preloadType;
+ const bool forcePreloadNone = shouldForcePreloadNoneForCellularNetwork();
if (equalIgnoringCase(preload, "none")) {
UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadNone);
- return WebMediaPlayer::PreloadNone;
- }
- if (equalIgnoringCase(preload, "metadata")) {
+ preloadType = WebMediaPlayer::PreloadNone;
+ } else if (equalIgnoringCase(preload, "metadata")) {
UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadMetadata);
- return WebMediaPlayer::PreloadMetaData;
- }
- if (equalIgnoringCase(preload, "auto")) {
+ preloadType = WebMediaPlayer::PreloadMetaData;
+ } else if (equalIgnoringCase(preload, "auto")) {
UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadAuto);
- return WebMediaPlayer::PreloadAuto;
- }
+ preloadType = WebMediaPlayer::PreloadAuto;
+ } else {
+ UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadDefault);
+
+ // "The attribute's missing value default is user-agent defined, though the
+ // Metadata state is suggested as a compromise between reducing server load
+ // and providing an optimal user experience."
- // "The attribute's missing value default is user-agent defined, though the
- // Metadata state is suggested as a compromise between reducing server load
- // and providing an optimal user experience."
+ // The spec does not define an invalid value default:
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28950
+
+ // TODO(philipj): Try to make "metadata" the default preload state:
+ // https://crbug.com/310450
+ preloadType = forcePreloadNone ? WebMediaPlayer::PreloadNone : WebMediaPlayer::PreloadAuto;
watk 2015/09/30 01:21:52 It might be clearer to just set to Auto here, and
DaleCurtis 2015/09/30 01:33:44 Done.
+ }
- // The spec does not define an invalid value default:
- // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28950
+ if (forcePreloadNone)
+ preloadType = WebMediaPlayer::PreloadNone;
- // TODO(philipj): Try to make "metadata" the default preload state:
- // https://crbug.com/310450
- UseCounter::count(document(), UseCounter::HTMLMediaElementPreloadDefault);
- return WebMediaPlayer::PreloadAuto;
+ return preloadType;
}
WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const

Powered by Google App Engine
This is Rietveld 408576698