Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: device/wake_lock/wake_lock_service_impl.h

Issue 2843353003: Move ownership of PowerSaveBlocker from WakeLockServiceContext to WakeLockServiceImpl (Closed)
Patch Set: seperate this CL into 2CLs Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "device/power_save_blocker/power_save_blocker.h"
9 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h" 13 #include "device/wake_lock/public/interfaces/wake_lock_service.mojom.h"
10 #include "mojo/public/cpp/bindings/interface_request.h" 14 #include "mojo/public/cpp/bindings/binding_set.h"
15 #include "ui/gfx/native_widget_types.h"
11 16
12 namespace device { 17 namespace device {
13 18
14 class WakeLockServiceContext; 19 // Callback that maps a context ID to the NativeView associated with
20 // that context. This callback is provided to the Device Service by its
21 // embedder.
22 using WakeLockContextCallback = base::Callback<gfx::NativeView(int)>;
15 23
16 class WakeLockServiceImpl : public mojom::WakeLockService { 24 class WakeLockServiceImpl : public mojom::WakeLockService {
17 public: 25 public:
18 explicit WakeLockServiceImpl(WakeLockServiceContext* context); 26 WakeLockServiceImpl(
27 mojom::WakeLockServiceRequest request,
28 device::PowerSaveBlocker::PowerSaveBlockerType type,
29 device::PowerSaveBlocker::Reason reason,
30 const std::string& description,
31 int context_id,
32 WakeLockContextCallback native_view_getter,
33 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
19 ~WakeLockServiceImpl() override; 34 ~WakeLockServiceImpl() override;
20 35
21 // WakeLockSevice implementation. 36 // WakeLockSevice implementation.
22 void RequestWakeLock() override; 37 void RequestWakeLock() override;
23 void CancelWakeLock() override; 38 void CancelWakeLock() override;
39 void AddClient(mojom::WakeLockServiceRequest request) override;
40 void HasWakeLockForTests(
41 const HasWakeLockForTestsCallback& callback) override;
24 42
25 private: 43 private:
26 // Will outlive this instance. 44 void UpdateWakeLock();
27 WakeLockServiceContext* context_; 45 void CreateWakeLock();
28 bool wake_lock_request_outstanding_; 46 void RemoveWakeLock();
47 void OnConnectionError();
48
49 device::PowerSaveBlocker::PowerSaveBlockerType type_;
50 device::PowerSaveBlocker::Reason reason_;
51 std::unique_ptr<std::string> description_;
52 int num_lock_requests_;
53
54 #if defined(OS_ANDROID)
55 int context_id_;
56 WakeLockContextCallback native_view_getter_;
57 #endif
58
59 scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
60 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
61
62 // The actual power save blocker for screen.
63 std::unique_ptr<PowerSaveBlocker> wake_lock_;
64
65 mojo::BindingSet<mojom::WakeLockService, int> binding_set_;
66 std::map<int, bool> outstandings_;
67 std::map<int, mojo::BindingId> binding_ids_;
29 68
30 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceImpl); 69 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceImpl);
31 }; 70 };
32 71
33 } // namespace device 72 } // namespace device
34 73
35 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_ 74 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698