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

Side by Side Diff: components/plugins/renderer/loadable_plugin_placeholder.cc

Issue 2211753002: Plugin Power Saver Tiny: Fix Plugin.PowerSaver.PeripheralHeuristic UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge. and change to enum Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/plugins/renderer/loadable_plugin_placeholder.h" 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 14 matching lines...) Expand all
25 #include "third_party/WebKit/public/web/WebLocalFrame.h" 25 #include "third_party/WebKit/public/web/WebLocalFrame.h"
26 #include "third_party/WebKit/public/web/WebPluginContainer.h" 26 #include "third_party/WebKit/public/web/WebPluginContainer.h"
27 #include "third_party/WebKit/public/web/WebScriptSource.h" 27 #include "third_party/WebKit/public/web/WebScriptSource.h"
28 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 28 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
29 #include "third_party/WebKit/public/web/WebView.h" 29 #include "third_party/WebKit/public/web/WebView.h"
30 #include "url/gurl.h" 30 #include "url/gurl.h"
31 #include "url/origin.h" 31 #include "url/origin.h"
32 32
33 using base::UserMetricsAction; 33 using base::UserMetricsAction;
34 using content::PluginInstanceThrottler; 34 using content::PluginInstanceThrottler;
35 using content::RenderFrame;
35 using content::RenderThread; 36 using content::RenderThread;
36 37
37 namespace plugins { 38 namespace plugins {
38 39
39 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { 40 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() {
40 DCHECK(!is_blocked_for_power_saver_poster_); 41 DCHECK(!is_blocked_for_power_saver_poster_);
41 is_blocked_for_power_saver_poster_ = true; 42 is_blocked_for_power_saver_poster_ = true;
42 43
43 render_frame()->RegisterPeripheralPlugin( 44 render_frame()->RegisterPeripheralPlugin(
44 url::Origin(GURL(GetPluginParams().url)), 45 url::Origin(GURL(GetPluginParams().url)),
45 base::Bind(&LoadablePluginPlaceholder::MarkPluginEssential, 46 base::Bind(&LoadablePluginPlaceholder::MarkPluginEssential,
46 weak_factory_.GetWeakPtr(), 47 weak_factory_.GetWeakPtr(),
47 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST)); 48 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST));
48 } 49 }
49 50
50 void LoadablePluginPlaceholder::SetPremadePlugin( 51 void LoadablePluginPlaceholder::SetPremadePlugin(
51 content::PluginInstanceThrottler* throttler) { 52 content::PluginInstanceThrottler* throttler) {
52 DCHECK(throttler); 53 DCHECK(throttler);
53 DCHECK(!premade_throttler_); 54 DCHECK(!premade_throttler_);
55 heuristic_run_before_ = true;
54 premade_throttler_ = throttler; 56 premade_throttler_ = throttler;
55 } 57 }
56 58
57 LoadablePluginPlaceholder::LoadablePluginPlaceholder( 59 LoadablePluginPlaceholder::LoadablePluginPlaceholder(
58 content::RenderFrame* render_frame, 60 RenderFrame* render_frame,
59 blink::WebLocalFrame* frame, 61 blink::WebLocalFrame* frame,
60 const blink::WebPluginParams& params, 62 const blink::WebPluginParams& params,
61 const std::string& html_data) 63 const std::string& html_data)
62 : PluginPlaceholderBase(render_frame, frame, params, html_data), 64 : PluginPlaceholderBase(render_frame, frame, params, html_data),
65 heuristic_run_before_(false),
63 is_blocked_for_tinyness_(false), 66 is_blocked_for_tinyness_(false),
64 is_blocked_for_background_tab_(false), 67 is_blocked_for_background_tab_(false),
65 is_blocked_for_prerendering_(false), 68 is_blocked_for_prerendering_(false),
66 is_blocked_for_power_saver_poster_(false), 69 is_blocked_for_power_saver_poster_(false),
67 power_saver_enabled_(false), 70 power_saver_enabled_(false),
68 premade_throttler_(nullptr), 71 premade_throttler_(nullptr),
69 allow_loading_(false), 72 allow_loading_(false),
70 finished_loading_(false), 73 finished_loading_(false),
71 heuristic_run_before_(premade_throttler_ != nullptr),
72 weak_factory_(this) {} 74 weak_factory_(this) {}
73 75
74 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { 76 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
75 } 77 }
76 78
77 void LoadablePluginPlaceholder::MarkPluginEssential( 79 void LoadablePluginPlaceholder::MarkPluginEssential(
78 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { 80 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
79 if (!power_saver_enabled_) 81 if (!power_saver_enabled_)
80 return; 82 return;
81 83
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 unobscured_rect_ = unobscured_rect; 194 unobscured_rect_ = unobscured_rect;
193 195
194 float zoom_factor = plugin()->container()->pageZoomFactor(); 196 float zoom_factor = plugin()->container()->pageZoomFactor();
195 int width = roundf(unobscured_rect_.width() / zoom_factor); 197 int width = roundf(unobscured_rect_.width() / zoom_factor);
196 int height = roundf(unobscured_rect_.height() / zoom_factor); 198 int height = roundf(unobscured_rect_.height() / zoom_factor);
197 int x = roundf(unobscured_rect_.x() / zoom_factor); 199 int x = roundf(unobscured_rect_.x() / zoom_factor);
198 int y = roundf(unobscured_rect_.y() / zoom_factor); 200 int y = roundf(unobscured_rect_.y() / zoom_factor);
199 201
200 // On a size update check if we now qualify as a essential plugin. 202 // On a size update check if we now qualify as a essential plugin.
201 url::Origin content_origin = url::Origin(GetPluginParams().url); 203 url::Origin content_origin = url::Origin(GetPluginParams().url);
202 content::RenderFrame::PeripheralContentStatus status = 204 RenderFrame::PeripheralContentStatus status =
203 render_frame()->GetPeripheralContentStatus( 205 render_frame()->GetPeripheralContentStatus(
204 render_frame()->GetWebFrame()->top()->getSecurityOrigin(), 206 render_frame()->GetWebFrame()->top()->getSecurityOrigin(),
205 content_origin, gfx::Size(width, height)); 207 content_origin, gfx::Size(width, height),
208 heuristic_run_before_ ? RenderFrame::DONT_RECORD_DECISION
209 : RenderFrame::RECORD_DECISION);
206 210
207 bool plugin_is_tiny_and_blocked = 211 bool plugin_is_tiny_and_blocked =
208 is_blocked_for_tinyness_ && 212 is_blocked_for_tinyness_ &&
209 status == 213 status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_TINY;
210 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_TINY;
211 214
212 // Early exit for plugins that we've discovered to be essential. 215 // Early exit for plugins that we've discovered to be essential.
213 if (!plugin_is_tiny_and_blocked && 216 if (!plugin_is_tiny_and_blocked &&
214 status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) { 217 status != RenderFrame::CONTENT_STATUS_PERIPHERAL) {
215 MarkPluginEssential( 218 MarkPluginEssential(
216 heuristic_run_before_ 219 heuristic_run_before_
217 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE 220 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE
218 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); 221 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD);
219 222
220 if (!heuristic_run_before_ && 223 if (!heuristic_run_before_ &&
221 status == 224 status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) {
222 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) {
223 render_frame()->WhitelistContentOrigin(content_origin); 225 render_frame()->WhitelistContentOrigin(content_origin);
224 } 226 }
225 227
226 return; 228 return;
227 } 229 }
228 heuristic_run_before_ = true; 230 heuristic_run_before_ = true;
229 231
230 if (is_blocked_for_tinyness_) { 232 if (is_blocked_for_tinyness_) {
231 if (plugin_is_tiny_and_blocked) { 233 if (plugin_is_tiny_and_blocked) {
232 OnBlockedTinyContent(); 234 OnBlockedTinyContent();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 return identifier_; 362 return identifier_;
361 } 363 }
362 364
363 bool LoadablePluginPlaceholder::LoadingBlocked() const { 365 bool LoadablePluginPlaceholder::LoadingBlocked() const {
364 DCHECK(allow_loading_); 366 DCHECK(allow_loading_);
365 return is_blocked_for_tinyness_ || is_blocked_for_background_tab_ || 367 return is_blocked_for_tinyness_ || is_blocked_for_background_tab_ ||
366 is_blocked_for_power_saver_poster_ || is_blocked_for_prerendering_; 368 is_blocked_for_power_saver_poster_ || is_blocked_for_prerendering_;
367 } 369 }
368 370
369 } // namespace plugins 371 } // namespace plugins
OLDNEW
« no previous file with comments | « components/plugins/renderer/loadable_plugin_placeholder.h ('k') | content/public/renderer/plugin_instance_throttler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698