| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 
| 6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 
| 7 | 7 | 
| 8 #include <memory> | 8 #include <memory> | 
| 9 #include <set> | 9 #include <set> | 
| 10 #include <utility> | 10 #include <utility> | 
| 11 | 11 | 
| 12 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" | 
| 14 #include "content/browser/wake_lock/wake_lock_service_impl.h" | 14 #include "content/browser/wake_lock/wake_lock_service_impl.h" | 
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" | 
| 16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" | 
| 17 #include "mojo/public/cpp/bindings/interface_request.h" | 17 #include "mojo/public/cpp/bindings/interface_request.h" | 
| 18 | 18 | 
|  | 19 #if defined(OS_ANDROID) | 
|  | 20 #include "ui/android/view_android.h" | 
|  | 21 #endif  // OS_ANDROID | 
|  | 22 | 
| 19 namespace content { | 23 namespace content { | 
| 20 | 24 | 
| 21 class PowerSaveBlocker; | 25 class PowerSaveBlocker; | 
| 22 class RenderFrameHost; | 26 class RenderFrameHost; | 
| 23 class WebContents; | 27 class WebContents; | 
| 24 | 28 | 
| 25 class CONTENT_EXPORT WakeLockServiceContext : public WebContentsObserver { | 29 class CONTENT_EXPORT WakeLockServiceContext : public WebContentsObserver { | 
| 26  public: | 30  public: | 
| 27   explicit WakeLockServiceContext(WebContents* web_contents); | 31   explicit WakeLockServiceContext(WebContents* web_contents); | 
| 28   ~WakeLockServiceContext() override; | 32   ~WakeLockServiceContext() override; | 
| 29 | 33 | 
| 30   // Creates a WakeLockServiceImpl that is strongly bound to |request|. | 34   // Creates a WakeLockServiceImpl that is strongly bound to |request|. | 
| 31   void CreateService( | 35   void CreateService( | 
| 32       int render_process_id, | 36       int render_process_id, | 
| 33       int render_frame_id, | 37       int render_frame_id, | 
| 34       mojo::InterfaceRequest<blink::mojom::WakeLockService> request); | 38       mojo::InterfaceRequest<blink::mojom::WakeLockService> request); | 
| 35 | 39 | 
| 36   // WebContentsObserver implementation. | 40   // WebContentsObserver implementation. | 
| 37   void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 41   void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 
|  | 42   void WebContentsDestroyed() override; | 
| 38 | 43 | 
| 39   // Requests wake lock for RenderFrame identified by |render_process_id| and | 44   // Requests wake lock for RenderFrame identified by |render_process_id| and | 
| 40   // |render_frame_id|. | 45   // |render_frame_id|. | 
| 41   void RequestWakeLock(int render_process_id, int render_frame_id); | 46   void RequestWakeLock(int render_process_id, int render_frame_id); | 
| 42 | 47 | 
| 43   // Cancels wake lock request for RenderFrame identified by | 48   // Cancels wake lock request for RenderFrame identified by | 
| 44   // |render_process_id| and |render_frame_id|. | 49   // |render_process_id| and |render_frame_id|. | 
| 45   void CancelWakeLock(int render_process_id, int render_frame_id); | 50   void CancelWakeLock(int render_process_id, int render_frame_id); | 
| 46 | 51 | 
| 47   // Used by tests. | 52   // Used by tests. | 
| 48   bool HasWakeLockForTests() const; | 53   bool HasWakeLockForTests() const; | 
| 49 | 54 | 
| 50  private: | 55  private: | 
| 51   void CreateWakeLock(); | 56   void CreateWakeLock(); | 
| 52   void RemoveWakeLock(); | 57   void RemoveWakeLock(); | 
| 53   void UpdateWakeLock(); | 58   void UpdateWakeLock(); | 
| 54 | 59 | 
| 55   // Set of (render_process_id, render_frame_id) pairs identifying all | 60   // Set of (render_process_id, render_frame_id) pairs identifying all | 
| 56   // RenderFrames requesting wake lock. | 61   // RenderFrames requesting wake lock. | 
| 57   std::set<std::pair<int, int>> frames_requesting_lock_; | 62   std::set<std::pair<int, int>> frames_requesting_lock_; | 
| 58 | 63 | 
| 59   // The actual power save blocker for screen. | 64   // The actual power save blocker for screen. | 
| 60   std::unique_ptr<PowerSaveBlocker> wake_lock_; | 65   std::unique_ptr<PowerSaveBlocker> wake_lock_; | 
|  | 66 #if defined(OS_ANDROID) | 
|  | 67   std::unique_ptr<base::WeakPtrFactory<ui::ViewAndroid>> view_weak_factory_; | 
|  | 68 #endif | 
| 61 | 69 | 
| 62   base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; | 70   base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; | 
| 63 | 71 | 
| 64   DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); | 72   DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); | 
| 65 }; | 73 }; | 
| 66 | 74 | 
| 67 }  // namespace content | 75 }  // namespace content | 
| 68 | 76 | 
| 69 #endif  // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 77 #endif  // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 
| OLD | NEW | 
|---|