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> | |
9 | |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 #include "device/power_save_blocker/power_save_blocker.h" | |
9 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h" | 14 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h" |
10 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/binding_set.h" |
16 #include "ui/gfx/native_widget_types.h" | |
11 | 17 |
12 namespace device { | 18 namespace device { |
13 | 19 |
14 class WakeLockServiceContext; | 20 // Callback that maps a context ID to the NativeView associated with |
21 // that context. This callback is provided to the Device Service by its | |
22 // embedder. | |
23 using WakeLockContextCallback = base::Callback<gfx::NativeView(int)>; | |
blundell
2017/05/05 12:49:38
Just include wake_lock_service_context.h?
ke.he
2017/05/05 14:56:36
Done.
| |
15 | 24 |
16 class WakeLockServiceImpl : public mojom::WakeLockService { | 25 class WakeLockServiceImpl : public mojom::WakeLockService { |
17 public: | 26 public: |
18 explicit WakeLockServiceImpl(WakeLockServiceContext* context); | 27 WakeLockServiceImpl( |
28 mojom::WakeLockServiceRequest request, | |
29 device::PowerSaveBlocker::PowerSaveBlockerType type, | |
30 device::PowerSaveBlocker::Reason reason, | |
31 const std::string& description, | |
32 int context_id, | |
33 WakeLockContextCallback native_view_getter, | |
34 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | |
19 ~WakeLockServiceImpl() override; | 35 ~WakeLockServiceImpl() override; |
20 | 36 |
21 // WakeLockSevice implementation. | 37 // WakeLockSevice implementation. |
22 void RequestWakeLock() override; | 38 void RequestWakeLock() override; |
23 void CancelWakeLock() override; | 39 void CancelWakeLock() override; |
40 void AddClient(mojom::WakeLockServiceRequest request) override; | |
41 void HasWakeLockForTests( | |
42 const HasWakeLockForTestsCallback& callback) override; | |
24 | 43 |
25 private: | 44 private: |
26 // Will outlive this instance. | 45 void UpdateWakeLock(); |
27 WakeLockServiceContext* context_; | 46 void CreateWakeLock(); |
28 bool wake_lock_request_outstanding_; | 47 void RemoveWakeLock(); |
48 void OnConnectionError(); | |
49 | |
50 device::PowerSaveBlocker::PowerSaveBlockerType type_; | |
51 device::PowerSaveBlocker::Reason reason_; | |
52 std::unique_ptr<std::string> description_; | |
53 int num_lock_requests_; | |
54 | |
55 #if defined(OS_ANDROID) | |
56 int context_id_; | |
57 WakeLockContextCallback native_view_getter_; | |
58 #endif | |
59 | |
60 scoped_refptr<base::SequencedTaskRunner> main_task_runner_; | |
61 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | |
62 | |
63 // The actual power save blocker for screen. | |
64 std::unique_ptr<PowerSaveBlocker> wake_lock_; | |
65 | |
66 mojo::BindingSet<mojom::WakeLockService, std::unique_ptr<bool>> binding_set_; | |
29 | 67 |
30 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceImpl); | 68 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceImpl); |
31 }; | 69 }; |
32 | 70 |
33 } // namespace device | 71 } // namespace device |
34 | 72 |
35 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_ | 73 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_ |
OLD | NEW |