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 #include <utility> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/browser/wake_lock/wake_lock_service_impl.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class PowerSaveBlocker; |
| 21 class RenderFrameHost; |
| 22 class WebContents; |
| 23 |
| 24 class CONTENT_EXPORT WakeLockServiceContext : 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(int render_process_id, |
| 31 int render_frame_id, |
| 32 mojo::InterfaceRequest<WakeLockService> request); |
| 33 |
| 34 // WebContentsObserver implementation. |
| 35 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 36 |
| 37 // Requests wake lock for RenderFrame identified by |render_process_id| and |
| 38 // |render_frame_id|. |
| 39 void RequestWakeLock(int render_process_id, int render_frame_id); |
| 40 |
| 41 // Cancels wake lock request for RenderFrame identified by |
| 42 // |render_process_id| and |render_frame_id|. |
| 43 void CancelWakeLock(int render_process_id, int render_frame_id); |
| 44 |
| 45 // Used by tests. |
| 46 bool HasWakeLockForTests() const; |
| 47 |
| 48 private: |
| 49 void CreateWakeLock(); |
| 50 void RemoveWakeLock(); |
| 51 void UpdateWakeLock(); |
| 52 |
| 53 // Set of (render_process_id, render_frame_id) pairs identifying all |
| 54 // RenderFrames requesting wake lock. |
| 55 std::set<std::pair<int, int>> frames_requesting_lock_; |
| 56 |
| 57 // The actual power save blocker for screen. |
| 58 scoped_ptr<PowerSaveBlocker> wake_lock_; |
| 59 |
| 60 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); |
| 63 }; |
| 64 |
| 65 } // namespace content |
| 66 |
| 67 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ |
OLD | NEW |