[ServiceWorker] Implement WebServiceWorkerContextClient::openWindow().
[chromium-blink-merge.git] / content / renderer / pepper / plugin_instance_throttler_impl.h
blob14352c119b204e5b736ef010e86d6c1ef3c3a68a
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "content/common/content_export.h"
12 #include "content/public/renderer/plugin_instance_throttler.h"
13 #include "ppapi/shared_impl/ppb_view_shared.h"
14 #include "third_party/WebKit/public/platform/WebRect.h"
16 namespace blink {
17 class WebInputEvent;
20 class SkBitmap;
22 namespace content {
24 class CONTENT_EXPORT PluginInstanceThrottlerImpl
25 : public PluginInstanceThrottler {
26 public:
27 PluginInstanceThrottlerImpl(RenderFrame* frame,
28 const GURL& plugin_url,
29 bool power_saver_enabled);
31 ~PluginInstanceThrottlerImpl() override;
33 // PluginInstanceThrottler implementation:
34 void AddObserver(Observer* observer) override;
35 void RemoveObserver(Observer* observer) override;
36 bool IsThrottled() const override;
37 void MarkPluginEssential(PowerSaverUnthrottleMethod method) override;
39 bool needs_representative_keyframe() const {
40 return state_ == POWER_SAVER_ENABLED_AWAITING_KEYFRAME;
43 bool power_saver_enabled() const {
44 return state_ == POWER_SAVER_ENABLED_AWAITING_KEYFRAME ||
45 state_ == POWER_SAVER_ENABLED_PLUGIN_THROTTLED;
48 // Called when the plugin flushes it's graphics context. Supplies the
49 // throttler with a candidate to use as the representative keyframe.
50 void OnImageFlush(const SkBitmap* bitmap);
52 // Returns true if |event| was handled and shouldn't be further processed.
53 bool ConsumeInputEvent(const blink::WebInputEvent& event);
55 private:
56 friend class PluginInstanceThrottlerImplTest;
58 enum State {
59 // Initial state if Power Saver is disabled. We are just collecting metrics.
60 POWER_SAVER_DISABLED,
61 // Initial state if Power Saver is enabled. Waiting for a keyframe.
62 POWER_SAVER_ENABLED_AWAITING_KEYFRAME,
63 // We've chosen a keyframe and the plug-in is throttled.
64 POWER_SAVER_ENABLED_PLUGIN_THROTTLED,
65 // Plugin instance is no longer considered peripheral. This can happen from
66 // a user click, whitelisting, or some other reason. We can end up in this
67 // state regardless of whether power saver is enabled.
68 PLUGIN_INSTANCE_MARKED_ESSENTIAL
71 void EngageThrottle();
73 State state_;
75 // Number of consecutive interesting frames we've encountered.
76 int consecutive_interesting_frames_;
78 ObserverList<Observer> observer_list_;
80 base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_;
82 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl);
86 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_