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