Chromium Code Reviews| Index: content/renderer/pepper/plugin_instance_throttler_impl.h |
| diff --git a/content/renderer/pepper/plugin_instance_throttler_impl.h b/content/renderer/pepper/plugin_instance_throttler_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14352c119b204e5b736ef010e86d6c1ef3c3a68a |
| --- /dev/null |
| +++ b/content/renderer/pepper/plugin_instance_throttler_impl.h |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
| +#define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "content/common/content_export.h" |
| +#include "content/public/renderer/plugin_instance_throttler.h" |
| +#include "ppapi/shared_impl/ppb_view_shared.h" |
| +#include "third_party/WebKit/public/platform/WebRect.h" |
| + |
| +namespace blink { |
| +class WebInputEvent; |
| +} |
| + |
| +class SkBitmap; |
| + |
| +namespace content { |
| + |
| +class CONTENT_EXPORT PluginInstanceThrottlerImpl |
|
Lei Zhang
2015/01/16 00:19:32
You may want to define "essential" and "peripheral
tommycli
2015/01/16 00:51:56
Done. I added to the comments in the plugin_instan
|
| + : public PluginInstanceThrottler { |
| + public: |
| + PluginInstanceThrottlerImpl(RenderFrame* frame, |
| + const GURL& plugin_url, |
| + bool power_saver_enabled); |
| + |
| + ~PluginInstanceThrottlerImpl() override; |
| + |
| + // PluginInstanceThrottler implementation: |
| + void AddObserver(Observer* observer) override; |
| + void RemoveObserver(Observer* observer) override; |
| + bool IsThrottled() const override; |
| + void MarkPluginEssential(PowerSaverUnthrottleMethod method) override; |
| + |
| + bool needs_representative_keyframe() const { |
| + return state_ == POWER_SAVER_ENABLED_AWAITING_KEYFRAME; |
| + } |
| + |
| + bool power_saver_enabled() const { |
| + return state_ == POWER_SAVER_ENABLED_AWAITING_KEYFRAME || |
| + state_ == POWER_SAVER_ENABLED_PLUGIN_THROTTLED; |
| + } |
| + |
| + // Called when the plugin flushes it's graphics context. Supplies the |
| + // throttler with a candidate to use as the representative keyframe. |
| + void OnImageFlush(const SkBitmap* bitmap); |
| + |
| + // Returns true if |event| was handled and shouldn't be further processed. |
| + bool ConsumeInputEvent(const blink::WebInputEvent& event); |
| + |
| + private: |
| + friend class PluginInstanceThrottlerImplTest; |
| + |
| + enum State { |
| + // Initial state if Power Saver is disabled. We are just collecting metrics. |
| + POWER_SAVER_DISABLED, |
| + // Initial state if Power Saver is enabled. Waiting for a keyframe. |
| + POWER_SAVER_ENABLED_AWAITING_KEYFRAME, |
| + // We've chosen a keyframe and the plug-in is throttled. |
| + POWER_SAVER_ENABLED_PLUGIN_THROTTLED, |
| + // Plugin instance is no longer considered peripheral. This can happen from |
| + // a user click, whitelisting, or some other reason. We can end up in this |
| + // state regardless of whether power saver is enabled. |
| + PLUGIN_INSTANCE_MARKED_ESSENTIAL |
| + }; |
| + |
| + void EngageThrottle(); |
| + |
| + State state_; |
| + |
| + // Number of consecutive interesting frames we've encountered. |
| + int consecutive_interesting_frames_; |
| + |
| + ObserverList<Observer> observer_list_; |
| + |
| + base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl); |
| +}; |
| +} |
| + |
| +#endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |