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

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

Issue 879403002: Plugin Power Saver: Mute throttled plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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_instance_throttler_impl.h" 5 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/public/common/content_constants.h" 9 #include "content/public/common/content_constants.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 if (power_saver_enabled) { 72 if (power_saver_enabled) {
73 base::MessageLoop::current()->PostDelayedTask( 73 base::MessageLoop::current()->PostDelayedTask(
74 FROM_HERE, base::Bind(&PluginInstanceThrottlerImpl::EngageThrottle, 74 FROM_HERE, base::Bind(&PluginInstanceThrottlerImpl::EngageThrottle,
75 weak_factory_.GetWeakPtr()), 75 weak_factory_.GetWeakPtr()),
76 base::TimeDelta::FromMilliseconds(kThrottleTimeout)); 76 base::TimeDelta::FromMilliseconds(kThrottleTimeout));
77 } 77 }
78 } 78 }
79 79
80 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { 80 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() {
81 if (state_ != PLUGIN_INSTANCE_MARKED_ESSENTIAL) 81 if (state_ != POWER_SAVER_MARKED_ESSENTIAL)
82 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); 82 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER);
83 } 83 }
84 84
85 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { 85 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) {
86 observer_list_.AddObserver(observer); 86 observer_list_.AddObserver(observer);
87 } 87 }
88 88
89 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) { 89 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) {
90 observer_list_.RemoveObserver(observer); 90 observer_list_.RemoveObserver(observer);
91 } 91 }
92 92
93 bool PluginInstanceThrottlerImpl::IsThrottled() const { 93 bool PluginInstanceThrottlerImpl::IsThrottled() const {
94 return state_ == POWER_SAVER_ENABLED_PLUGIN_THROTTLED; 94 return state_ == POWER_SAVER_ENABLED_PLUGIN_THROTTLED;
95 } 95 }
96 96
97 void PluginInstanceThrottlerImpl::MarkPluginEssential( 97 void PluginInstanceThrottlerImpl::MarkPluginEssential(
98 PowerSaverUnthrottleMethod method) { 98 PowerSaverUnthrottleMethod method) {
99 if (state_ == PLUGIN_INSTANCE_MARKED_ESSENTIAL) 99 if (state_ == POWER_SAVER_MARKED_ESSENTIAL)
100 return; 100 return;
101 101
102 bool was_throttled = IsThrottled(); 102 state_ = POWER_SAVER_MARKED_ESSENTIAL;
103 state_ = PLUGIN_INSTANCE_MARKED_ESSENTIAL;
104 RecordUnthrottleMethodMetric(method); 103 RecordUnthrottleMethodMetric(method);
105 104 FOR_EACH_OBSERVER(Observer, observer_list_, OnPowerSaverStateChange(state_));
106 if (was_throttled)
107 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
108 } 105 }
109 106
110 void PluginInstanceThrottlerImpl::OnImageFlush(const SkBitmap* bitmap) { 107 void PluginInstanceThrottlerImpl::OnImageFlush(const SkBitmap* bitmap) {
111 DCHECK(needs_representative_keyframe()); 108 DCHECK(needs_representative_keyframe());
112 if (!bitmap) 109 if (!bitmap)
113 return; 110 return;
114 111
115 double boring_score = color_utils::CalculateBoringScore(*bitmap); 112 double boring_score = color_utils::CalculateBoringScore(*bitmap);
116 if (boring_score <= kAcceptableFrameMaximumBoringness) 113 if (boring_score <= kAcceptableFrameMaximumBoringness)
117 ++consecutive_interesting_frames_; 114 ++consecutive_interesting_frames_;
118 else 115 else
119 consecutive_interesting_frames_ = 0; 116 consecutive_interesting_frames_ = 0;
120 117
121 if (consecutive_interesting_frames_ >= kMinimumConsecutiveInterestingFrames) 118 if (consecutive_interesting_frames_ >= kMinimumConsecutiveInterestingFrames)
122 EngageThrottle(); 119 EngageThrottle();
123 } 120 }
124 121
125 bool PluginInstanceThrottlerImpl::ConsumeInputEvent( 122 bool PluginInstanceThrottlerImpl::ConsumeInputEvent(
126 const blink::WebInputEvent& event) { 123 const blink::WebInputEvent& event) {
127 // Always allow right-clicks through so users may verify it's a plug-in. 124 // Always allow right-clicks through so users may verify it's a plug-in.
128 // TODO(tommycli): We should instead show a custom context menu (probably 125 // TODO(tommycli): We should instead show a custom context menu (probably
129 // using PluginPlaceholder) so users aren't confused and try to click the 126 // using PluginPlaceholder) so users aren't confused and try to click the
130 // Flash-internal 'Play' menu item. This is a stopgap solution. 127 // Flash-internal 'Play' menu item. This is a stopgap solution.
131 if (event.modifiers & blink::WebInputEvent::Modifiers::RightButtonDown) 128 if (event.modifiers & blink::WebInputEvent::Modifiers::RightButtonDown)
132 return false; 129 return false;
133 130
134 if (state_ != PLUGIN_INSTANCE_MARKED_ESSENTIAL && 131 if (state_ != POWER_SAVER_MARKED_ESSENTIAL &&
135 event.type == blink::WebInputEvent::MouseUp && 132 event.type == blink::WebInputEvent::MouseUp &&
136 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) { 133 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
137 bool was_throttled = IsThrottled(); 134 bool was_throttled = IsThrottled();
138 MarkPluginEssential(UNTHROTTLE_METHOD_BY_CLICK); 135 MarkPluginEssential(UNTHROTTLE_METHOD_BY_CLICK);
139 return was_throttled; 136 return was_throttled;
140 } 137 }
141 138
142 return IsThrottled(); 139 return IsThrottled();
143 } 140 }
144 141
145 void PluginInstanceThrottlerImpl::EngageThrottle() { 142 void PluginInstanceThrottlerImpl::EngageThrottle() {
146 if (state_ != POWER_SAVER_ENABLED_AWAITING_KEYFRAME) 143 if (state_ != POWER_SAVER_ENABLED_AWAITING_KEYFRAME)
147 return; 144 return;
148 145
149 state_ = POWER_SAVER_ENABLED_PLUGIN_THROTTLED; 146 state_ = POWER_SAVER_ENABLED_PLUGIN_THROTTLED;
150 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); 147 FOR_EACH_OBSERVER(Observer, observer_list_, OnPowerSaverStateChange(state_));
151 } 148 }
152 149
153 } // namespace content 150 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698