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

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

Issue 2843353003: Move ownership of PowerSaveBlocker from WakeLockServiceContext to WakeLockServiceImpl (Closed)
Patch Set: error fix, non-frame client. 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_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/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "device/wake_lock/public/interfaces/wake_lock_context.mojom.h" 16 #include "device/wake_lock/public/interfaces/wake_lock_context.mojom.h"
17 #include "device/wake_lock/wake_lock_service_impl.h" 17 #include "device/wake_lock/wake_lock_service_impl.h"
18 #include "mojo/public/cpp/bindings/binding.h" 18 #include "mojo/public/cpp/bindings/binding.h"
19 #include "mojo/public/cpp/bindings/interface_request.h"
20 #include "mojo/public/cpp/bindings/strong_binding_set.h" 19 #include "mojo/public/cpp/bindings/strong_binding_set.h"
21 #include "ui/gfx/native_widget_types.h" 20 #include "ui/gfx/native_widget_types.h"
22 21
23 namespace device { 22 namespace device {
24 23
25 class PowerSaveBlocker; 24 class PowerSaveBlocker;
26 25
27 // Callback that maps a context ID to the NativeView associated with 26 // Callback that maps a context ID to the NativeView associated with
28 // that context. This callback is provided to the Device Service by its 27 // that context. This callback is provided to the Device Service by its
29 // embedder. 28 // embedder.
(...skipping 12 matching lines...) Expand all
42 class WakeLockServiceContext : public mojom::WakeLockContext { 41 class WakeLockServiceContext : public mojom::WakeLockContext {
43 public: 42 public:
44 WakeLockServiceContext( 43 WakeLockServiceContext(
45 mojom::WakeLockContextRequest request, 44 mojom::WakeLockContextRequest request,
46 int context_id, 45 int context_id,
47 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 46 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
48 const WakeLockContextCallback& native_view_getter); 47 const WakeLockContextCallback& native_view_getter);
49 ~WakeLockServiceContext() override; 48 ~WakeLockServiceContext() override;
50 49
51 // mojom::WakeLockContext: 50 // mojom::WakeLockContext:
52 void GetWakeLock( 51 void GetWakeLock(device::PowerSaveBlocker::PowerSaveBlockerType type,
53 mojo::InterfaceRequest<mojom::WakeLockService> request) override; 52 device::PowerSaveBlocker::Reason reason,
53 const std::string& description,
54 mojom::WakeLockServiceRequest request) override;
54 void HasWakeLockForTests( 55 void HasWakeLockForTests(
blundell 2017/05/02 11:27:43 IIUC, the only reason that this class still has an
ke.he 2017/05/04 11:54:14 Done.
55 const HasWakeLockForTestsCallback& callback) override; 56 const HasWakeLockForTestsCallback& callback) override;
56 57 void IncreaseWakeLockCount();
57 // Requests wake lock. 58 void DecreaseWakeLockCount();
58 void RequestWakeLock();
59
60 // Cancels pending wake lock request.
61 void CancelWakeLock();
62 59
63 private: 60 private:
64 void CreateWakeLock();
65 void RemoveWakeLock();
66 void UpdateWakeLock();
67 void OnContextBindingError(); 61 void OnContextBindingError();
68 62
69 // Checks whether this instance is still needed, and if not, destroys it. 63 // Checks whether this instance is still needed, and if not, destroys it.
70 void DestroyIfNoLongerNeeded(); 64 void DestroyIfNoLongerNeeded();
71 65
72 scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
73 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 66 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
74 67
75 int num_lock_requests_; 68 // Counts number of wake lock instances, for test usage.
69 int wake_lock_count_;
76 70
77 // The actual power save blocker for screen.
78 std::unique_ptr<PowerSaveBlocker> wake_lock_;
79
80 #if defined(OS_ANDROID)
81 int context_id_; 71 int context_id_;
82 WakeLockContextCallback native_view_getter_; 72 WakeLockContextCallback native_view_getter_;
83 #endif
84 73
85 mojo::Binding<mojom::WakeLockContext> context_binding_; 74 mojo::Binding<mojom::WakeLockContext> context_binding_;
86 bool context_binding_encountered_error_; 75 bool context_binding_encountered_error_;
87 76
88 mojo::StrongBindingSet<mojom::WakeLockService> wake_lock_bindings_; 77 mojo::StrongBindingSet<mojom::WakeLockService> wake_lock_bindings_;
89 78
90 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext); 79 DISALLOW_COPY_AND_ASSIGN(WakeLockServiceContext);
91 }; 80 };
92 81
93 } // namespace device 82 } // namespace device
94 83
95 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_ 84 #endif // DEVICE_WAKE_LOCK_WAKE_LOCK_SERVICE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698