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_SERVICE_CONTEXT_H_ |
| 6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/browser/wake_lock/wake_lock_service_impl.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 class PowerSaveBlocker; |
| 20 class RenderFrameHost; |
| 21 class WebContents; |
| 22 |
| 23 class CONTENT_EXPORT WakeLockServiceContext |
| 24 : public WebContentsObserver { |
| 25 public: |
| 26 explicit WakeLockServiceContext(WebContents* web_contents); |
| 27 ~WakeLockServiceContext() override; |
| 28 |
| 29 // Creates a WakeLockServiceImpl that is strongly bound to |request|. |
| 30 void CreateService(const RenderFrameHost* render_frame_host, |
| 31 mojo::InterfaceRequest<WakeLockService> request); |
| 32 |
| 33 // WebContentsObserver implementation. |
| 34 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 35 void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 36 RenderFrameHost* new_host) override; |
| 37 |
| 38 // Requests wake lock for |render_frame_host|. |
| 39 void RequestWakeLock(const RenderFrameHost* render_frame_host); |
| 40 |
| 41 // Cancels wake lock request for |render_frame_host|. |
| 42 void CancelWakeLock(const RenderFrameHost* render_frame_host); |
| 43 |
| 44 // Used by tests. |
| 45 bool HasWakeLockForTests() const; |
| 46 |
| 47 private: |
| 48 void CreateWakeLock(); |
| 49 void RemoveWakeLock(); |
| 50 void UpdateWakeLock(); |
| 51 |
| 52 // Set of all frames currently requesting wake lock. |
| 53 std::set<const RenderFrameHost*> frames_requesting_lock_; |
| 54 |
| 55 // The actual power save blocker for screen. |
| 56 scoped_ptr<PowerSaveBlocker> wake_lock_; |
| 57 |
| 58 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); |
| 61 }; |
| 62 |
| 63 } // namespace content |
| 64 |
| 65 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ |
OLD | NEW |