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

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

Issue 866173002: Plugin Power Saver: Add UI Overlay to throttled plugin using placeholder. (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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); 53 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS);
54 } 54 }
55 55
56 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl( 56 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl(
57 RenderFrame* frame, 57 RenderFrame* frame,
58 const GURL& plugin_url, 58 const GURL& plugin_url,
59 bool power_saver_enabled) 59 bool power_saver_enabled)
60 : state_(power_saver_enabled ? POWER_SAVER_ENABLED_AWAITING_KEYFRAME 60 : state_(power_saver_enabled ? POWER_SAVER_ENABLED_AWAITING_KEYFRAME
61 : POWER_SAVER_DISABLED), 61 : POWER_SAVER_DISABLED),
62 consecutive_interesting_frames_(0), 62 consecutive_interesting_frames_(0),
63 keyframe_extraction_timed_out_(false),
63 weak_factory_(this) { 64 weak_factory_(this) {
64 // To collect UMAs, register peripheral content even if power saver disabled. 65 // To collect UMAs, register peripheral content even if power saver disabled.
65 if (frame) { 66 if (frame) {
66 frame->RegisterPeripheralPlugin( 67 frame->RegisterPeripheralPlugin(
67 plugin_url.GetOrigin(), 68 plugin_url.GetOrigin(),
68 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential, 69 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential,
69 weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST)); 70 weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST));
70 } 71 }
71 72
72 if (power_saver_enabled) { 73 if (power_saver_enabled) {
73 base::MessageLoop::current()->PostDelayedTask( 74 base::MessageLoop::current()->PostDelayedTask(
74 FROM_HERE, base::Bind(&PluginInstanceThrottlerImpl::EngageThrottle, 75 FROM_HERE,
75 weak_factory_.GetWeakPtr()), 76 base::Bind(&PluginInstanceThrottlerImpl::TimeoutKeyframeExtraction,
77 weak_factory_.GetWeakPtr()),
76 base::TimeDelta::FromMilliseconds(kThrottleTimeout)); 78 base::TimeDelta::FromMilliseconds(kThrottleTimeout));
77 } 79 }
78 } 80 }
79 81
80 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { 82 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() {
83 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottlerDestroyed());
81 if (state_ != PLUGIN_INSTANCE_MARKED_ESSENTIAL) 84 if (state_ != PLUGIN_INSTANCE_MARKED_ESSENTIAL)
82 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); 85 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER);
83 } 86 }
84 87
85 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { 88 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) {
86 observer_list_.AddObserver(observer); 89 observer_list_.AddObserver(observer);
87 } 90 }
88 91
89 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) { 92 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) {
90 observer_list_.RemoveObserver(observer); 93 observer_list_.RemoveObserver(observer);
(...skipping 20 matching lines...) Expand all
111 DCHECK(needs_representative_keyframe()); 114 DCHECK(needs_representative_keyframe());
112 if (!bitmap) 115 if (!bitmap)
113 return; 116 return;
114 117
115 double boring_score = color_utils::CalculateBoringScore(*bitmap); 118 double boring_score = color_utils::CalculateBoringScore(*bitmap);
116 if (boring_score <= kAcceptableFrameMaximumBoringness) 119 if (boring_score <= kAcceptableFrameMaximumBoringness)
117 ++consecutive_interesting_frames_; 120 ++consecutive_interesting_frames_;
118 else 121 else
119 consecutive_interesting_frames_ = 0; 122 consecutive_interesting_frames_ = 0;
120 123
121 if (consecutive_interesting_frames_ >= kMinimumConsecutiveInterestingFrames) 124 if (keyframe_extraction_timed_out_ ||
125 consecutive_interesting_frames_ >= kMinimumConsecutiveInterestingFrames) {
126 FOR_EACH_OBSERVER(Observer, observer_list_, OnKeyframeExtracted(bitmap));
groby-ooo-7-16 2015/01/30 02:22:44 Do we expect multiple observers?
tommycli 2015/01/30 17:02:40 In general, yes. For this particular call, there's
122 EngageThrottle(); 127 EngageThrottle();
128 }
123 } 129 }
124 130
125 bool PluginInstanceThrottlerImpl::ConsumeInputEvent( 131 bool PluginInstanceThrottlerImpl::ConsumeInputEvent(
126 const blink::WebInputEvent& event) { 132 const blink::WebInputEvent& event) {
127 // Always allow right-clicks through so users may verify it's a plug-in. 133 // 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 134 // TODO(tommycli): We should instead show a custom context menu (probably
129 // using PluginPlaceholder) so users aren't confused and try to click the 135 // using PluginPlaceholder) so users aren't confused and try to click the
130 // Flash-internal 'Play' menu item. This is a stopgap solution. 136 // Flash-internal 'Play' menu item. This is a stopgap solution.
131 if (event.modifiers & blink::WebInputEvent::Modifiers::RightButtonDown) 137 if (event.modifiers & blink::WebInputEvent::Modifiers::RightButtonDown)
132 return false; 138 return false;
(...skipping 10 matching lines...) Expand all
143 } 149 }
144 150
145 void PluginInstanceThrottlerImpl::EngageThrottle() { 151 void PluginInstanceThrottlerImpl::EngageThrottle() {
146 if (state_ != POWER_SAVER_ENABLED_AWAITING_KEYFRAME) 152 if (state_ != POWER_SAVER_ENABLED_AWAITING_KEYFRAME)
147 return; 153 return;
148 154
149 state_ = POWER_SAVER_ENABLED_PLUGIN_THROTTLED; 155 state_ = POWER_SAVER_ENABLED_PLUGIN_THROTTLED;
150 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); 156 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
151 } 157 }
152 158
159 void PluginInstanceThrottlerImpl::TimeoutKeyframeExtraction() {
160 DCHECK(!keyframe_extraction_timed_out_);
groby-ooo-7-16 2015/01/30 02:22:44 Why do we care about this as a precondition? Will
tommycli 2015/01/30 17:02:40 Done.
161 keyframe_extraction_timed_out_ = true;
162 }
163
153 } // namespace content 164 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698