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

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

Issue 2734943003: Device Service: Decouple Wake Lock from //content (Closed)
Patch Set: Bugfix Created 3 years, 9 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_CONTEXT_H_ 5 #ifndef DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_
6 #define DEVICE_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 "device/wake_lock/public/interfaces/wake_lock_service_context.mojom.h"
17 #include "device/wake_lock/wake_lock_service_impl.h" 18 #include "device/wake_lock/wake_lock_service_impl.h"
19 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/interface_request.h" 20 #include "mojo/public/cpp/bindings/interface_request.h"
19 #include "ui/gfx/native_widget_types.h" 21 #include "ui/gfx/native_widget_types.h"
20 22
21 namespace device { 23 namespace device {
22 24
23 class PowerSaveBlocker; 25 class PowerSaveBlocker;
24 26
25 class WakeLockServiceContext { 27 // Callback that maps a context ID to the NativeView associated with
28 // that context.
29 using WakeLockContextCallback = base::Callback<gfx::NativeView(int)>;
30
31 class WakeLockServiceContext : public mojom::WakeLockServiceContext {
26 public: 32 public:
27 WakeLockServiceContext( 33 WakeLockServiceContext(
34 mojom::WakeLockServiceContextRequest request,
28 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 35 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
29 base::Callback<gfx::NativeView()> native_view_getter); 36 WakeLockContextCallback native_view_getter);
30 ~WakeLockServiceContext(); 37 ~WakeLockServiceContext() override;
31 38
32 // Creates a WakeLockServiceImpl that is strongly bound to |request|. 39 // mojom::WakeLockServiceContext:
33 void CreateService(mojo::InterfaceRequest<mojom::WakeLockService> request); 40 void SetContextID(int context_id) override;
41 void BindWakeLock(
42 mojo::InterfaceRequest<mojom::WakeLockService> request) override;
43 void HasWakeLockForTests(
44 const HasWakeLockForTestsCallback& callback) override;
34 45
35 // Requests wake lock. 46 // Requests wake lock.
36 void RequestWakeLock(); 47 void RequestWakeLock();
37 48
38 // Cancels pending wake lock request. 49 // Cancels pending wake lock request.
39 void CancelWakeLock(); 50 void CancelWakeLock();
40 51
41 // Used by tests.
42 bool HasWakeLockForTests() const;
43
44 private: 52 private:
45 void CreateWakeLock(); 53 void CreateWakeLock();
46 void RemoveWakeLock(); 54 void RemoveWakeLock();
47 void UpdateWakeLock(); 55 void UpdateWakeLock();
56 void OnConnectionError();
48 57
49 scoped_refptr<base::SequencedTaskRunner> main_task_runner_; 58 scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
50 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 59 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
60 int context_id_;
51 61
52 int num_lock_requests_; 62 int num_lock_requests_;
53 63
54 // The actual power save blocker for screen. 64 // The actual power save blocker for screen.
55 std::unique_ptr<PowerSaveBlocker> wake_lock_; 65 std::unique_ptr<PowerSaveBlocker> wake_lock_;
56 base::Callback<gfx::NativeView()> native_view_getter_; 66 WakeLockContextCallback native_view_getter_;
67
68 mojo::Binding<mojom::WakeLockServiceContext> binding_;
69
70 // The number of connections that the client has in this context,
71 // including both the connection to this implementation and all
72 // connections made via |BindWakeLock()|. When this number reaches
73 // 0 this instance isn't needed anymore and kills itself.
74 int num_connections_;
57 75
58 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_; 76 base::WeakPtrFactory<WakeLockServiceContext> weak_factory_;
59 77
60 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); 78 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext);
61 }; 79 };
62 80
63 } // namespace device 81 } // namespace device
64 82
65 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ 83 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698