| 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/message_loop/message_loop.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/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
| 14 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/renderer/peripheral_content_heuristic.h" | 18 #include "content/renderer/peripheral_content_heuristic.h" |
| 17 #include "ppapi/shared_impl/ppapi_constants.h" | 19 #include "ppapi/shared_impl/ppapi_constants.h" |
| 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 19 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 20 | 22 |
| 21 namespace content { | 23 namespace content { |
| 22 | 24 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void PluginPowerSaverHelper::OnUpdatePluginContentOriginWhitelist( | 71 void PluginPowerSaverHelper::OnUpdatePluginContentOriginWhitelist( |
| 70 const std::set<url::Origin>& origin_whitelist) { | 72 const std::set<url::Origin>& origin_whitelist) { |
| 71 origin_whitelist_ = origin_whitelist; | 73 origin_whitelist_ = origin_whitelist; |
| 72 | 74 |
| 73 // Check throttled plugin instances to see if any can be unthrottled. | 75 // Check throttled plugin instances to see if any can be unthrottled. |
| 74 auto it = peripheral_plugins_.begin(); | 76 auto it = peripheral_plugins_.begin(); |
| 75 while (it != peripheral_plugins_.end()) { | 77 while (it != peripheral_plugins_.end()) { |
| 76 if (origin_whitelist.count(it->content_origin)) { | 78 if (origin_whitelist.count(it->content_origin)) { |
| 77 // Because the unthrottle callback may register another peripheral plugin | 79 // Because the unthrottle callback may register another peripheral plugin |
| 78 // and invalidate our iterator, we cannot run it synchronously. | 80 // and invalidate our iterator, we cannot run it synchronously. |
| 79 base::MessageLoop::current()->PostTask(FROM_HERE, | 81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 80 it->unthrottle_callback); | 82 it->unthrottle_callback); |
| 81 it = peripheral_plugins_.erase(it); | 83 it = peripheral_plugins_.erase(it); |
| 82 } else { | 84 } else { |
| 83 ++it; | 85 ++it; |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 | 89 |
| 88 void PluginPowerSaverHelper::RegisterPeripheralPlugin( | 90 void PluginPowerSaverHelper::RegisterPeripheralPlugin( |
| 89 const url::Origin& content_origin, | 91 const url::Origin& content_origin, |
| 90 const base::Closure& unthrottle_callback) { | 92 const base::Closure& unthrottle_callback) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 118 | 120 |
| 119 void PluginPowerSaverHelper::WhitelistContentOrigin( | 121 void PluginPowerSaverHelper::WhitelistContentOrigin( |
| 120 const url::Origin& content_origin) { | 122 const url::Origin& content_origin) { |
| 121 if (origin_whitelist_.insert(content_origin).second) { | 123 if (origin_whitelist_.insert(content_origin).second) { |
| 122 Send(new FrameHostMsg_PluginContentOriginAllowed( | 124 Send(new FrameHostMsg_PluginContentOriginAllowed( |
| 123 render_frame()->GetRoutingID(), content_origin)); | 125 render_frame()->GetRoutingID(), content_origin)); |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 } // namespace content | 129 } // namespace content |
| OLD | NEW |