| 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 DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_ | 5 #ifndef DEVICE_WAKE_LOCK_WAKE_LOCK_H_ |
| 6 #define DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_ | 6 #define DEVICE_WAKE_LOCK_WAKE_LOCK_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "device/power_save_blocker/power_save_blocker.h" | 13 #include "device/power_save_blocker/power_save_blocker.h" |
| 14 #include "device/wake_lock/public/interfaces/wake_lock.mojom.h" |
| 14 #include "device/wake_lock/public/interfaces/wake_lock_context.mojom.h" | 15 #include "device/wake_lock/public/interfaces/wake_lock_context.mojom.h" |
| 15 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h" | 16 #include "device/wake_lock/wake_lock_context.h" |
| 16 #include "device/wake_lock/wake_lock_service_context.h" | |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" | 17 #include "mojo/public/cpp/bindings/binding_set.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 19 | 19 |
| 20 namespace device { | 20 namespace device { |
| 21 | 21 |
| 22 class WakeLockServiceImpl : public mojom::WakeLockService { | 22 class WakeLock : public mojom::WakeLock { |
| 23 public: | 23 public: |
| 24 WakeLockServiceImpl( | 24 WakeLock(mojom::WakeLockRequest request, |
| 25 mojom::WakeLockServiceRequest request, | 25 mojom::WakeLockType type, |
| 26 mojom::WakeLockType type, | 26 mojom::WakeLockReason reason, |
| 27 mojom::WakeLockReason reason, | 27 const std::string& description, |
| 28 const std::string& description, | 28 int context_id, |
| 29 int context_id, | 29 WakeLockContextCallback native_view_getter, |
| 30 WakeLockContextCallback native_view_getter, | 30 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
| 31 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 31 ~WakeLock() override; |
| 32 ~WakeLockServiceImpl() override; | |
| 33 | 32 |
| 34 // WakeLockSevice implementation. | 33 // WakeLockSevice implementation. |
| 35 void RequestWakeLock() override; | 34 void RequestWakeLock() override; |
| 36 void CancelWakeLock() override; | 35 void CancelWakeLock() override; |
| 37 void AddClient(mojom::WakeLockServiceRequest request) override; | 36 void AddClient(mojom::WakeLockRequest request) override; |
| 38 void HasWakeLockForTests(HasWakeLockForTestsCallback callback) override; | 37 void HasWakeLockForTests(HasWakeLockForTestsCallback callback) override; |
| 39 | 38 |
| 40 protected: | 39 protected: |
| 41 int num_lock_requests_; | 40 int num_lock_requests_; |
| 42 | 41 |
| 43 private: | 42 private: |
| 44 virtual void UpdateWakeLock(); | 43 virtual void UpdateWakeLock(); |
| 45 virtual void CreateWakeLock(); | 44 virtual void CreateWakeLock(); |
| 46 virtual void RemoveWakeLock(); | 45 virtual void RemoveWakeLock(); |
| 47 | 46 |
| 48 void OnConnectionError(); | 47 void OnConnectionError(); |
| 49 | 48 |
| 50 mojom::WakeLockType type_; | 49 mojom::WakeLockType type_; |
| 51 mojom::WakeLockReason reason_; | 50 mojom::WakeLockReason reason_; |
| 52 std::unique_ptr<std::string> description_; | 51 std::unique_ptr<std::string> description_; |
| 53 | 52 |
| 54 #if defined(OS_ANDROID) | 53 #if defined(OS_ANDROID) |
| 55 int context_id_; | 54 int context_id_; |
| 56 WakeLockContextCallback native_view_getter_; | 55 WakeLockContextCallback native_view_getter_; |
| 57 #endif | 56 #endif |
| 58 | 57 |
| 59 scoped_refptr<base::SequencedTaskRunner> main_task_runner_; | 58 scoped_refptr<base::SequencedTaskRunner> main_task_runner_; |
| 60 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 59 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 61 | 60 |
| 62 // The actual power save blocker for screen. | 61 // The actual power save blocker for screen. |
| 63 std::unique_ptr<PowerSaveBlocker> wake_lock_; | 62 std::unique_ptr<PowerSaveBlocker> wake_lock_; |
| 64 | 63 |
| 65 // Multiple clients that associate to the same WebContents share the same one | 64 // Multiple clients that associate to the same WebContents share the same one |
| 66 // WakeLockServiceImpl instance. Two consecutive |RequestWakeLock| requests | 65 // WakeLock instance. Two consecutive |RequestWakeLock| requests |
| 67 // from the same client should be coalesced as one request. Everytime a new | 66 // from the same client should be coalesced as one request. Everytime a new |
| 68 // client is being added into the BindingSet, we create an unique_ptr<bool> | 67 // client is being added into the BindingSet, we create an unique_ptr<bool> |
| 69 // as its context, which records this client's request status. | 68 // as its context, which records this client's request status. |
| 70 mojo::BindingSet<mojom::WakeLockService, std::unique_ptr<bool>> binding_set_; | 69 mojo::BindingSet<mojom::WakeLock, std::unique_ptr<bool>> binding_set_; |
| 71 | 70 |
| 72 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceImpl); | 71 DISALLOW_COPY_AND_ASSIGN(WakeLock); |
| 73 }; | 72 }; |
| 74 | 73 |
| 75 } // namespace device | 74 } // namespace device |
| 76 | 75 |
| 77 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_ | 76 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_H_ |
| OLD | NEW |