| OLD | NEW |
| 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_power_saver_helper.h" | 5 #include "content/renderer/pepper/plugin_power_saver_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
| 18 #include "content/renderer/peripheral_content_heuristic.h" | 18 #include "content/renderer/peripheral_content_heuristic.h" |
| 19 #include "ppapi/shared_impl/ppapi_constants.h" | 19 #include "ppapi/shared_impl/ppapi_constants.h" |
| 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 21 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char kPeripheralHeuristicHistogram[] = | 27 const char kPeripheralHeuristicHistogram[] = |
| 28 "Plugin.PowerSaver.PeripheralHeuristic"; | 28 "Plugin.PowerSaver.PeripheralHeuristicInitialDecision"; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( | 32 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( |
| 33 const url::Origin& content_origin, | 33 const url::Origin& content_origin, |
| 34 const base::Closure& unthrottle_callback) | 34 const base::Closure& unthrottle_callback) |
| 35 : content_origin(content_origin), | 35 : content_origin(content_origin), |
| 36 unthrottle_callback(unthrottle_callback) {} | 36 unthrottle_callback(unthrottle_callback) {} |
| 37 | 37 |
| 38 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( | 38 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 const url::Origin& content_origin, | 95 const url::Origin& content_origin, |
| 96 const base::Closure& unthrottle_callback) { | 96 const base::Closure& unthrottle_callback) { |
| 97 peripheral_plugins_.push_back( | 97 peripheral_plugins_.push_back( |
| 98 PeripheralPlugin(content_origin, unthrottle_callback)); | 98 PeripheralPlugin(content_origin, unthrottle_callback)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 RenderFrame::PeripheralContentStatus | 101 RenderFrame::PeripheralContentStatus |
| 102 PluginPowerSaverHelper::GetPeripheralContentStatus( | 102 PluginPowerSaverHelper::GetPeripheralContentStatus( |
| 103 const url::Origin& main_frame_origin, | 103 const url::Origin& main_frame_origin, |
| 104 const url::Origin& content_origin, | 104 const url::Origin& content_origin, |
| 105 const gfx::Size& unobscured_size) const { | 105 const gfx::Size& unobscured_size, |
| 106 RenderFrame::RecordPeripheralDecision record_decision) const { |
| 106 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 107 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 107 switches::kOverridePluginPowerSaverForTesting) == "always") { | 108 switches::kOverridePluginPowerSaverForTesting) == "always") { |
| 108 return RenderFrame::CONTENT_STATUS_PERIPHERAL; | 109 return RenderFrame::CONTENT_STATUS_PERIPHERAL; |
| 109 } | 110 } |
| 110 | 111 |
| 111 auto status = PeripheralContentHeuristic::GetPeripheralStatus( | 112 auto status = PeripheralContentHeuristic::GetPeripheralStatus( |
| 112 origin_whitelist_, main_frame_origin, content_origin, unobscured_size); | 113 origin_whitelist_, main_frame_origin, content_origin, unobscured_size); |
| 113 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_UNKNOWN_SIZE) { | 114 |
| 114 // Early exit here to avoid recording a UMA. Every plugin will call this | 115 // Never record ESSENTIAL_UNKNOWN_SIZE. Wait for retest after size is known. |
| 115 // method once before the size is known (to faciliate early-exit for | 116 if (record_decision == RenderFrame::RECORD_DECISION && |
| 116 // same-origin and whitelisted-origin content). | 117 status != RenderFrame::CONTENT_STATUS_ESSENTIAL_UNKNOWN_SIZE) { |
| 117 return status; | 118 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, status, |
| 119 RenderFrame::CONTENT_STATUS_NUM_ITEMS); |
| 118 } | 120 } |
| 119 | 121 |
| 120 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, status, | |
| 121 RenderFrame::CONTENT_STATUS_NUM_ITEMS); | |
| 122 return status; | 122 return status; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void PluginPowerSaverHelper::WhitelistContentOrigin( | 125 void PluginPowerSaverHelper::WhitelistContentOrigin( |
| 126 const url::Origin& content_origin) { | 126 const url::Origin& content_origin) { |
| 127 if (origin_whitelist_.insert(content_origin).second) { | 127 if (origin_whitelist_.insert(content_origin).second) { |
| 128 Send(new FrameHostMsg_PluginContentOriginAllowed( | 128 Send(new FrameHostMsg_PluginContentOriginAllowed( |
| 129 render_frame()->GetRoutingID(), content_origin)); | 129 render_frame()->GetRoutingID(), content_origin)); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace content | 133 } // namespace content |
| OLD | NEW |