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

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

Issue 1522173002: Reland: Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix an NPE crash/race on plugin destruction 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"
18 19
19 namespace content { 20 namespace content {
20 21
21 namespace { 22 namespace {
22 23
23 const char kPeripheralHeuristicHistogram[] = 24 const char kPeripheralHeuristicHistogram[] =
24 "Plugin.PowerSaver.PeripheralHeuristic"; 25 "Plugin.PowerSaver.PeripheralHeuristic";
25 26
26 } // namespace 27 } // namespace
27 28
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 78 }
78 } 79 }
79 80
80 void PluginPowerSaverHelper::RegisterPeripheralPlugin( 81 void PluginPowerSaverHelper::RegisterPeripheralPlugin(
81 const url::Origin& content_origin, 82 const url::Origin& content_origin,
82 const base::Closure& unthrottle_callback) { 83 const base::Closure& unthrottle_callback) {
83 peripheral_plugins_.push_back( 84 peripheral_plugins_.push_back(
84 PeripheralPlugin(content_origin, unthrottle_callback)); 85 PeripheralPlugin(content_origin, unthrottle_callback));
85 } 86 }
86 87
87 bool PluginPowerSaverHelper::ShouldThrottleContent( 88 RenderFrame::PeripheralContentStatus
89 PluginPowerSaverHelper::GetPeripheralContentStatus(
88 const url::Origin& main_frame_origin, 90 const url::Origin& main_frame_origin,
89 const url::Origin& content_origin, 91 const url::Origin& content_origin,
90 int width, 92 const gfx::Size& unobscured_size) const {
91 int height,
92 bool* cross_origin_main_content) const {
93 if (cross_origin_main_content)
94 *cross_origin_main_content = false;
95
96 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 93 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
97 switches::kOverridePluginPowerSaverForTesting) == "always") { 94 switches::kOverridePluginPowerSaverForTesting) == "always") {
98 return true; 95 return RenderFrame::CONTENT_STATUS_PERIPHERAL;
99 } 96 }
100 97
101 auto decision = PeripheralContentHeuristic::GetPeripheralStatus( 98 auto status = PeripheralContentHeuristic::GetPeripheralStatus(
102 origin_whitelist_, main_frame_origin, content_origin, width, height); 99 origin_whitelist_, main_frame_origin, content_origin, unobscured_size);
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 }
103 106
104 UMA_HISTOGRAM_ENUMERATION( 107 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, status,
105 kPeripheralHeuristicHistogram, decision, 108 RenderFrame::CONTENT_STATUS_NUM_ITEMS);
106 PeripheralContentHeuristic::HEURISTIC_DECISION_NUM_ITEMS); 109 return status;
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;
114 } 110 }
115 111
116 void PluginPowerSaverHelper::WhitelistContentOrigin( 112 void PluginPowerSaverHelper::WhitelistContentOrigin(
117 const url::Origin& content_origin) { 113 const url::Origin& content_origin) {
118 if (origin_whitelist_.insert(content_origin).second) { 114 if (origin_whitelist_.insert(content_origin).second) {
119 Send(new FrameHostMsg_PluginContentOriginAllowed( 115 Send(new FrameHostMsg_PluginContentOriginAllowed(
120 render_frame()->GetRoutingID(), content_origin)); 116 render_frame()->GetRoutingID(), content_origin));
121 } 117 }
122 } 118 }
123 119
124 } // namespace content 120 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698