Chromium Code Reviews| 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 void RenderFrameHostChanged(RenderFrameHost* old_host, | |
| 35 RenderFrameHost* new_host) override; | |
| 36 | |
| 37 // Requests wake lock for |frame_id|. | |
| 38 void RequestWakeLock(int frame_id); | |
| 39 | |
| 40 // Cancels wake lock request for |frame_id|. | |
| 41 void CancelWakeLock(int frame_id); | |
| 42 | |
| 43 // Used by tests. | |
| 44 bool HasWakeLockForTests() const; | |
| 45 | |
| 46 private: | |
| 47 void CancelWakeLockForRFH(RenderFrameHost* render_frame_host); | |
| 48 void CreateWakeLock(); | |
| 49 void RemoveWakeLock(); | |
| 50 void UpdateWakeLock(); | |
| 51 | |
| 52 // Set of all frame ids currently requesting wake lock. | |
|
nasko
2015/09/04 21:06:45
nit: s/frame/FrameTreeNode/
alogvinov
2015/09/08 14:49:44
Done.
| |
| 53 std::set<int> 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 |