OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #endif | 94 #endif |
95 } | 95 } |
96 | 96 |
97 #if defined(ENABLE_PLUGINS) | 97 #if defined(ENABLE_PLUGINS) |
98 void LoadablePluginPlaceholder::MarkPluginEssential( | 98 void LoadablePluginPlaceholder::MarkPluginEssential( |
99 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { | 99 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { |
100 if (plugin_marked_essential_) | 100 if (plugin_marked_essential_) |
101 return; | 101 return; |
102 | 102 |
103 plugin_marked_essential_ = true; | 103 plugin_marked_essential_ = true; |
104 if (premade_throttler_) { | 104 if (premade_throttler_) |
105 premade_throttler_->MarkPluginEssential(method); | 105 premade_throttler_->MarkPluginEssential(method); |
106 } | 106 else |
| 107 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); |
107 | 108 |
108 if (is_blocked_for_power_saver_poster_) { | 109 if (is_blocked_for_power_saver_poster_) { |
109 is_blocked_for_power_saver_poster_ = false; | 110 is_blocked_for_power_saver_poster_ = false; |
110 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); | |
111 if (!LoadingBlocked()) | 111 if (!LoadingBlocked()) |
112 LoadPlugin(); | 112 LoadPlugin(); |
113 } | 113 } |
114 } | 114 } |
115 #endif | 115 #endif |
116 | 116 |
117 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( | 117 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( |
118 v8::Isolate* isolate) { | 118 v8::Isolate* isolate) { |
119 return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) | 119 return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) |
120 .SetMethod("load", &LoadablePluginPlaceholder::LoadCallback) | 120 .SetMethod("load", &LoadablePluginPlaceholder::LoadCallback) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 ReplacePlugin(premade_throttler_->GetWebPlugin()); | 292 ReplacePlugin(premade_throttler_->GetWebPlugin()); |
293 premade_throttler_ = nullptr; | 293 premade_throttler_ = nullptr; |
294 } else { | 294 } else { |
295 // TODO(mmenke): In the case of prerendering, feed into | 295 // TODO(mmenke): In the case of prerendering, feed into |
296 // ChromeContentRendererClient::CreatePlugin instead, to | 296 // ChromeContentRendererClient::CreatePlugin instead, to |
297 // reduce the chance of future regressions. | 297 // reduce the chance of future regressions. |
298 scoped_ptr<PluginInstanceThrottler> throttler; | 298 scoped_ptr<PluginInstanceThrottler> throttler; |
299 #if defined(ENABLE_PLUGINS) | 299 #if defined(ENABLE_PLUGINS) |
300 // If the plugin has already been marked essential in its placeholder form, | 300 // If the plugin has already been marked essential in its placeholder form, |
301 // we shouldn't create a new throttler and start the process all over again. | 301 // we shouldn't create a new throttler and start the process all over again. |
302 if (!plugin_marked_essential_) | 302 if (!plugin_marked_essential_ && power_saver_enabled_) |
303 throttler = PluginInstanceThrottler::Create(power_saver_enabled_); | 303 throttler = PluginInstanceThrottler::Create(); |
304 #endif | 304 #endif |
305 WebPlugin* plugin = render_frame()->CreatePlugin( | 305 WebPlugin* plugin = render_frame()->CreatePlugin( |
306 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass()); | 306 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass()); |
307 | 307 |
308 ReplacePlugin(plugin); | 308 ReplacePlugin(plugin); |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 void LoadablePluginPlaceholder::LoadCallback() { | 312 void LoadablePluginPlaceholder::LoadCallback() { |
313 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); | 313 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 identifier_ = identifier; | 348 identifier_ = identifier; |
349 } | 349 } |
350 | 350 |
351 bool LoadablePluginPlaceholder::LoadingBlocked() const { | 351 bool LoadablePluginPlaceholder::LoadingBlocked() const { |
352 DCHECK(allow_loading_); | 352 DCHECK(allow_loading_); |
353 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 353 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
354 is_blocked_for_prerendering_; | 354 is_blocked_for_prerendering_; |
355 } | 355 } |
356 | 356 |
357 } // namespace plugins | 357 } // namespace plugins |
OLD | NEW |