| 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: public WebContentsObserver { | |
| 24 public: | |
| 25 explicit WakeLockServiceContext(WebContents* web_contents); | |
| 26 ~WakeLockServiceContext() override; | |
| 27 | |
| 28 // Creates a WakeLockServiceImpl that is strongly bound to |request|. | |
| 29 void CreateService(int frame_id, | |
| 30 mojo::InterfaceRequest<WakeLockService> request); | |
| 31 | |
| 32 // WebContentsObserver implementation. | |
| 33 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | |
| 34 | |
| 35 // Requests wake lock for |frame_id|. | |
| 36 void RequestWakeLock(int frame_id); | |
| 37 | |
| 38 // Cancels wake lock request for |frame_id|. | |
| 39 void CancelWakeLock(int frame_id); | |
| 40 | |
| 41 // Used by tests. | |
| 42 bool HasWakeLockForTests() const; | |
| 43 | |
| 44 private: | |
| 45 void CreateWakeLock(); | |
| 46 void RemoveWakeLock(); | |
| 47 void UpdateWakeLock(); | |
| 48 | |
| 49 // Set of all FrameTreeNode ids currently requesting wake lock. | |
| 50 std::set<int> frames_requesting_lock_; | |
| 51 | |
| 52 // The actual power save blocker for screen. | |
| 53 scoped_ptr<PowerSaveBlocker> wake_lock_; | |
| 54 | |
| 55 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); | |
| 58 }; | |
| 59 | |
| 60 } // namespace content | |
| 61 | |
| 62 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | |
| OLD | NEW |