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

Side by Side Diff: content/renderer/pepper/plugin_power_saver_helper.cc

Issue 1528653002: Revert of Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/pepper/plugin_power_saver_helper.h" 5 #include "content/renderer/pepper/plugin_power_saver_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "content/common/frame_messages.h" 12 #include "content/common/frame_messages.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "content/public/renderer/render_frame.h" 14 #include "content/public/renderer/render_frame.h"
15 #include "content/renderer/peripheral_content_heuristic.h" 15 #include "content/renderer/peripheral_content_heuristic.h"
16 #include "ppapi/shared_impl/ppapi_constants.h" 16 #include "ppapi/shared_impl/ppapi_constants.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "ui/gfx/geometry/size.h"
19 18
20 namespace content { 19 namespace content {
21 20
22 namespace { 21 namespace {
23 22
24 const char kPeripheralHeuristicHistogram[] = 23 const char kPeripheralHeuristicHistogram[] =
25 "Plugin.PowerSaver.PeripheralHeuristic"; 24 "Plugin.PowerSaver.PeripheralHeuristic";
26 25
27 } // namespace 26 } // namespace
28 27
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 77 }
79 } 78 }
80 79
81 void PluginPowerSaverHelper::RegisterPeripheralPlugin( 80 void PluginPowerSaverHelper::RegisterPeripheralPlugin(
82 const url::Origin& content_origin, 81 const url::Origin& content_origin,
83 const base::Closure& unthrottle_callback) { 82 const base::Closure& unthrottle_callback) {
84 peripheral_plugins_.push_back( 83 peripheral_plugins_.push_back(
85 PeripheralPlugin(content_origin, unthrottle_callback)); 84 PeripheralPlugin(content_origin, unthrottle_callback));
86 } 85 }
87 86
88 RenderFrame::PeripheralContentStatus 87 bool PluginPowerSaverHelper::ShouldThrottleContent(
89 PluginPowerSaverHelper::GetPeripheralContentStatus(
90 const url::Origin& main_frame_origin, 88 const url::Origin& main_frame_origin,
91 const url::Origin& content_origin, 89 const url::Origin& content_origin,
92 const gfx::Size& unobscured_size) const { 90 int width,
91 int height,
92 bool* cross_origin_main_content) const {
93 if (cross_origin_main_content)
94 *cross_origin_main_content = false;
95
93 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 96 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
94 switches::kOverridePluginPowerSaverForTesting) == "always") { 97 switches::kOverridePluginPowerSaverForTesting) == "always") {
95 return RenderFrame::CONTENT_STATUS_PERIPHERAL; 98 return true;
96 } 99 }
97 100
98 auto status = PeripheralContentHeuristic::GetPeripheralStatus( 101 auto decision = PeripheralContentHeuristic::GetPeripheralStatus(
99 origin_whitelist_, main_frame_origin, content_origin, unobscured_size); 102 origin_whitelist_, main_frame_origin, content_origin, width, height);
100 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_UNKNOWN_SIZE) {
101 // Early exit here to avoid recording a UMA. Every plugin will call this
102 // method once before the size is known (to faciliate early-exit for
103 // same-origin and whitelisted-origin content).
104 return status;
105 }
106 103
107 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, status, 104 UMA_HISTOGRAM_ENUMERATION(
108 RenderFrame::CONTENT_STATUS_NUM_ITEMS); 105 kPeripheralHeuristicHistogram, decision,
109 return status; 106 PeripheralContentHeuristic::HEURISTIC_DECISION_NUM_ITEMS);
107
108 if (decision == PeripheralContentHeuristic::
109 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG &&
110 cross_origin_main_content)
111 *cross_origin_main_content = true;
112
113 return decision == PeripheralContentHeuristic::HEURISTIC_DECISION_PERIPHERAL;
110 } 114 }
111 115
112 void PluginPowerSaverHelper::WhitelistContentOrigin( 116 void PluginPowerSaverHelper::WhitelistContentOrigin(
113 const url::Origin& content_origin) { 117 const url::Origin& content_origin) {
114 if (origin_whitelist_.insert(content_origin).second) { 118 if (origin_whitelist_.insert(content_origin).second) {
115 Send(new FrameHostMsg_PluginContentOriginAllowed( 119 Send(new FrameHostMsg_PluginContentOriginAllowed(
116 render_frame()->GetRoutingID(), content_origin)); 120 render_frame()->GetRoutingID(), content_origin));
117 } 121 }
118 } 122 }
119 123
120 } // namespace content 124 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.h ('k') | content/renderer/pepper/plugin_power_saver_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698