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

Side by Side Diff: content/renderer/pepper/plugin_instance_throttler_impl.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_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_thread.h" 10 #include "content/public/renderer/render_thread.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void PluginInstanceThrottlerImpl::Initialize( 132 void PluginInstanceThrottlerImpl::Initialize(
133 RenderFrameImpl* frame, 133 RenderFrameImpl* frame,
134 const url::Origin& content_origin, 134 const url::Origin& content_origin,
135 const std::string& plugin_module_name, 135 const std::string& plugin_module_name,
136 const gfx::Size& unobscured_size) { 136 const gfx::Size& unobscured_size) {
137 DCHECK(unobscured_size_.IsEmpty()); 137 DCHECK(unobscured_size_.IsEmpty());
138 unobscured_size_ = unobscured_size; 138 unobscured_size_ = unobscured_size;
139 139
140 // |frame| may be nullptr in tests. 140 // |frame| may be nullptr in tests.
141 if (frame) { 141 if (frame) {
142 bool cross_origin_main_content = false;
143 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); 142 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor();
144 if (!frame->ShouldThrottleContent( 143 auto status = frame->GetPeripheralContentStatus(
145 frame->GetWebFrame()->top()->securityOrigin(), content_origin, 144 frame->GetWebFrame()->top()->securityOrigin(), content_origin,
146 roundf(unobscured_size.width() / zoom_factor), 145 gfx::Size(roundf(unobscured_size.width() / zoom_factor),
147 roundf(unobscured_size.height() / zoom_factor), 146 roundf(unobscured_size.height() / zoom_factor)));
148 &cross_origin_main_content)) { 147 if (status != RenderFrame::CONTENT_STATUS_PERIPHERAL) {
149 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); 148 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_);
150 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; 149 state_ = THROTTLER_STATE_MARKED_ESSENTIAL;
151 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); 150 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange());
152 151
153 if (cross_origin_main_content) 152 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG)
154 frame->WhitelistContentOrigin(content_origin); 153 frame->WhitelistContentOrigin(content_origin);
155 154
156 return; 155 return;
157 } 156 }
158 157
159 // To collect UMAs, register peripheral content even if power saver mode 158 // To collect UMAs, register peripheral content even if power saver mode
160 // is disabled. 159 // is disabled.
161 frame->RegisterPeripheralPlugin( 160 frame->RegisterPeripheralPlugin(
162 content_origin, 161 content_origin,
163 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential, 162 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 214
216 // Release our reference to the underlying pixel data. 215 // Release our reference to the underlying pixel data.
217 last_received_frame_.reset(); 216 last_received_frame_.reset();
218 } 217 }
219 218
220 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; 219 state_ = THROTTLER_STATE_PLUGIN_THROTTLED;
221 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); 220 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
222 } 221 }
223 222
224 } // namespace content 223 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698