OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_DISPATCHER_HOST_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" |
| 11 #include "content/browser/wake_lock/wake_lock_state.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class PowerSaveBlocker; |
| 18 class RenderFrameHost; |
| 19 class WebContents; |
| 20 |
| 21 class CONTENT_EXPORT WakeLockDispatcherHost |
| 22 : public WebContentsObserver { |
| 23 public: |
| 24 explicit WakeLockDispatcherHost(WebContents* web_contents); |
| 25 ~WakeLockDispatcherHost() override; |
| 26 |
| 27 // WebContentsObserver |
| 28 void RenderFrameCreated(RenderFrameHost* render_frame_host) override; |
| 29 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 30 void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 31 RenderFrameHost* new_host) override; |
| 32 |
| 33 bool has_blocker_for_testing() const { |
| 34 return blocker_; |
| 35 } |
| 36 |
| 37 class CONTENT_EXPORT Observer { |
| 38 public: |
| 39 virtual void OnUpdate() = 0; |
| 40 }; |
| 41 |
| 42 void AddObserver(Observer* obs) { |
| 43 observer_list_.AddObserver(obs); |
| 44 } |
| 45 |
| 46 void RemoveObserver(Observer* obs) { |
| 47 observer_list_.RemoveObserver(obs); |
| 48 } |
| 49 |
| 50 private: |
| 51 void OnKeepScreenAwake(RenderFrameHost* render_frame_host, bool intention); |
| 52 |
| 53 void CreateBlocker(); |
| 54 void RemoveBlocker(); |
| 55 void UpdateBlocker(); |
| 56 |
| 57 void NotifyUpdate(); |
| 58 |
| 59 WakeLockState wake_lock_state_; |
| 60 |
| 61 scoped_ptr<PowerSaveBlocker> blocker_; |
| 62 ObserverList<Observer> observer_list_; |
| 63 |
| 64 friend class WakeLockDispatcherHostTest; |
| 65 |
| 66 base::WeakPtrFactory<WakeLockDispatcherHost> weak_factory_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(WakeLockDispatcherHost); |
| 69 }; |
| 70 |
| 71 } // namespace content |
| 72 |
| 73 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_DISPATCHER_HOST_H_ |
OLD | NEW |