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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 1292433002: Defer media playback in background tabs. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/crash_logging.h" 8 #include "base/debug/crash_logging.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return std::string(); 334 return std::string();
335 } 335 }
336 #endif 336 #endif
337 337
338 #if defined(ENABLE_EXTENSIONS) 338 #if defined(ENABLE_EXTENSIONS)
339 bool IsStandaloneExtensionProcess() { 339 bool IsStandaloneExtensionProcess() {
340 return base::CommandLine::ForCurrentProcess()->HasSwitch( 340 return base::CommandLine::ForCurrentProcess()->HasSwitch(
341 extensions::switches::kExtensionProcess); 341 extensions::switches::kExtensionProcess);
342 } 342 }
343 #endif 343 #endif
344
345 // Defers media player loading in background pages until they're visible.
346 class MediaLoadDeferrer : public content::RenderFrameObserver {
347 public:
348 MediaLoadDeferrer(content::RenderFrame* render_frame,
349 const base::Closure& continue_loading_cb)
350 : content::RenderFrameObserver(render_frame),
351 continue_loading_cb_(continue_loading_cb) {}
352 ~MediaLoadDeferrer() override {}
353
354 private:
355 // content::RenderFrameObserver implementation:
356 void WasShown() override {
357 continue_loading_cb_.Run();
358 delete this;
359 }
360
361 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135
362
363 const base::Closure continue_loading_cb_;
364
365 DISALLOW_COPY_AND_ASSIGN(MediaLoadDeferrer);
366 };
367
344 } // namespace 368 } // namespace
345 369
346 ChromeContentRendererClient::ChromeContentRendererClient() { 370 ChromeContentRendererClient::ChromeContentRendererClient() {
347 g_current_client = this; 371 g_current_client = this;
348 372
349 #if defined(ENABLE_EXTENSIONS) 373 #if defined(ENABLE_EXTENSIONS)
350 extensions::ExtensionsClient::Set( 374 extensions::ExtensionsClient::Set(
351 extensions::ChromeExtensionsClient::GetInstance()); 375 extensions::ChromeExtensionsClient::GetInstance());
352 extensions::ExtensionsRendererClient::Set( 376 extensions::ExtensionsRendererClient::Set(
353 ChromeExtensionsRendererClient::GetInstance()); 377 ChromeExtensionsRendererClient::GetInstance());
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 706 }
683 707
684 void ChromeContentRendererClient::DeferMediaLoad( 708 void ChromeContentRendererClient::DeferMediaLoad(
685 content::RenderFrame* render_frame, 709 content::RenderFrame* render_frame,
686 const base::Closure& closure) { 710 const base::Closure& closure) {
687 #if defined(OS_ANDROID) 711 #if defined(OS_ANDROID)
688 // Chromium for Android doesn't support prerender yet. 712 // Chromium for Android doesn't support prerender yet.
689 closure.Run(); 713 closure.Run();
690 return; 714 return;
691 #else 715 #else
692 if (!prerender::PrerenderHelper::IsPrerendering(render_frame)) { 716 if (prerender::PrerenderHelper::IsPrerendering(render_frame)) {
717 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
718 new prerender::PrerenderMediaLoadDeferrer(render_frame, closure);
719 return;
720 }
721
722 // TODO(dalecurtis): Include an idle check too. http://crbug.com/509135
723 if (!render_frame->IsHidden()) {
Lei Zhang 2015/08/13 19:11:47 nit, how about we structure this block consistentl
DaleCurtis 2015/08/13 21:44:48 Done.
693 closure.Run(); 724 closure.Run();
694 return; 725 return;
695 } 726 }
696 727
697 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. 728 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
698 new prerender::PrerenderMediaLoadDeferrer(render_frame, closure); 729 new MediaLoadDeferrer(render_frame, closure);
699 #endif 730 #endif
700 } 731 }
701 732
702 #if defined(ENABLE_PLUGINS) 733 #if defined(ENABLE_PLUGINS)
703 WebPlugin* ChromeContentRendererClient::CreatePlugin( 734 WebPlugin* ChromeContentRendererClient::CreatePlugin(
704 content::RenderFrame* render_frame, 735 content::RenderFrame* render_frame,
705 blink::WebLocalFrame* frame, 736 blink::WebLocalFrame* frame,
706 const WebPluginParams& original_params, 737 const WebPluginParams& original_params,
707 const ChromeViewHostMsg_GetPluginInfo_Output& output) { 738 const ChromeViewHostMsg_GetPluginInfo_Output& output) {
708 const WebPluginInfo& info = output.plugin; 739 const WebPluginInfo& info = output.plugin;
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 WebString header_key(ASCIIToUTF16( 1655 WebString header_key(ASCIIToUTF16(
1625 data_reduction_proxy::chrome_proxy_header())); 1656 data_reduction_proxy::chrome_proxy_header()));
1626 if (!response.httpHeaderField(header_key).isNull() && 1657 if (!response.httpHeaderField(header_key).isNull() &&
1627 response.httpHeaderField(header_key).utf8().find( 1658 response.httpHeaderField(header_key).utf8().find(
1628 data_reduction_proxy::chrome_proxy_lo_fi_directive()) != 1659 data_reduction_proxy::chrome_proxy_lo_fi_directive()) !=
1629 std::string::npos) { 1660 std::string::npos) {
1630 (*properties)[data_reduction_proxy::chrome_proxy_header()] = 1661 (*properties)[data_reduction_proxy::chrome_proxy_header()] =
1631 data_reduction_proxy::chrome_proxy_lo_fi_directive(); 1662 data_reduction_proxy::chrome_proxy_lo_fi_directive();
1632 } 1663 }
1633 } 1664 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698