| 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 DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ |
| 6 #define CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 6 #define DEVICE_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/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "content/browser/wake_lock/wake_lock_service_impl.h" | 17 #include "device/wake_lock/wake_lock_service_impl.h" |
| 18 #include "content/common/content_export.h" | |
| 19 #include "mojo/public/cpp/bindings/interface_request.h" | 18 #include "mojo/public/cpp/bindings/interface_request.h" |
| 20 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 21 | 20 |
| 22 namespace device { | 21 namespace device { |
| 22 |
| 23 class PowerSaveBlocker; | 23 class PowerSaveBlocker; |
| 24 } // namespace device | |
| 25 | 24 |
| 26 namespace content { | 25 class WakeLockServiceContext { |
| 27 | |
| 28 class CONTENT_EXPORT WakeLockServiceContext { | |
| 29 public: | 26 public: |
| 30 WakeLockServiceContext( | 27 WakeLockServiceContext( |
| 31 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | 28 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, |
| 32 base::Callback<gfx::NativeView()> native_view_getter); | 29 base::Callback<gfx::NativeView()> native_view_getter); |
| 33 ~WakeLockServiceContext(); | 30 ~WakeLockServiceContext(); |
| 34 | 31 |
| 35 // Creates a WakeLockServiceImpl that is strongly bound to |request|. | 32 // Creates a WakeLockServiceImpl that is strongly bound to |request|. |
| 36 void CreateService( | 33 void CreateService(mojo::InterfaceRequest<mojom::WakeLockService> request); |
| 37 mojo::InterfaceRequest<blink::mojom::WakeLockService> request); | |
| 38 | 34 |
| 39 // Requests wake lock. | 35 // Requests wake lock. |
| 40 void RequestWakeLock(); | 36 void RequestWakeLock(); |
| 41 | 37 |
| 42 // Cancels pending wake lock request. | 38 // Cancels pending wake lock request. |
| 43 void CancelWakeLock(); | 39 void CancelWakeLock(); |
| 44 | 40 |
| 45 // Used by tests. | 41 // Used by tests. |
| 46 bool HasWakeLockForTests() const; | 42 bool HasWakeLockForTests() const; |
| 47 | 43 |
| 48 private: | 44 private: |
| 49 void CreateWakeLock(); | 45 void CreateWakeLock(); |
| 50 void RemoveWakeLock(); | 46 void RemoveWakeLock(); |
| 51 void UpdateWakeLock(); | 47 void UpdateWakeLock(); |
| 52 | 48 |
| 53 scoped_refptr<base::SequencedTaskRunner> main_task_runner_; | 49 scoped_refptr<base::SequencedTaskRunner> main_task_runner_; |
| 54 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 50 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 55 | 51 |
| 56 int num_lock_requests_; | 52 int num_lock_requests_; |
| 57 | 53 |
| 58 // The actual power save blocker for screen. | 54 // The actual power save blocker for screen. |
| 59 std::unique_ptr<device::PowerSaveBlocker> wake_lock_; | 55 std::unique_ptr<PowerSaveBlocker> wake_lock_; |
| 60 base::Callback<gfx::NativeView()> native_view_getter_; | 56 base::Callback<gfx::NativeView()> native_view_getter_; |
| 61 | 57 |
| 62 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; | 58 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; |
| 63 | 59 |
| 64 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); | 60 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); |
| 65 }; | 61 }; |
| 66 | 62 |
| 67 } // namespace content | 63 } // namespace device |
| 68 | 64 |
| 69 #endif // CONTENT_BROWSER_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ | 65 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ |
| OLD | NEW |