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 #include "device/wake_lock/wake_lock_service_impl.h" | 5 #include "device/wake_lock/wake_lock_service_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 CreateWakeLock(); | 81 CreateWakeLock(); |
82 } else { | 82 } else { |
83 if (wake_lock_) | 83 if (wake_lock_) |
84 RemoveWakeLock(); | 84 RemoveWakeLock(); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 void WakeLockServiceImpl::CreateWakeLock() { | 88 void WakeLockServiceImpl::CreateWakeLock() { |
89 DCHECK(!wake_lock_); | 89 DCHECK(!wake_lock_); |
90 | 90 |
91 if (type_ != device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep || | |
92 reason_ != device::PowerSaveBlocker::kReasonOther || | |
93 *description_ != "Wake Lock API") { | |
94 // TODO(ke.he@intel.com): Fully generalize the WakeLock interface and impl. | |
95 NOTREACHED(); | |
96 return; | |
97 } | |
98 | |
99 wake_lock_ = base::MakeUnique<device::PowerSaveBlocker>( | 91 wake_lock_ = base::MakeUnique<device::PowerSaveBlocker>( |
100 type_, reason_, *description_, main_task_runner_, file_task_runner_); | 92 type_, reason_, *description_, main_task_runner_, file_task_runner_); |
101 | 93 |
102 #if defined(OS_ANDROID) | 94 #if defined(OS_ANDROID) |
103 gfx::NativeView native_view = native_view_getter_.Run(context_id_); | 95 gfx::NativeView native_view = native_view_getter_.Run(context_id_); |
blundell
2017/05/09 15:53:24
Hmm. This code currently only executes at some usa
ke.he
2017/05/10 07:00:20
Oh, Thanks pointing out this! I'm sorry.
I found t
| |
104 if (native_view) | 96 if (native_view) |
105 wake_lock_.get()->InitDisplaySleepBlocker(native_view); | 97 wake_lock_.get()->InitDisplaySleepBlocker(native_view); |
106 #endif | 98 #endif |
107 } | 99 } |
108 | 100 |
109 void WakeLockServiceImpl::RemoveWakeLock() { | 101 void WakeLockServiceImpl::RemoveWakeLock() { |
110 DCHECK(wake_lock_); | 102 DCHECK(wake_lock_); |
111 wake_lock_.reset(); | 103 wake_lock_.reset(); |
112 } | 104 } |
113 | 105 |
114 void WakeLockServiceImpl::OnConnectionError() { | 106 void WakeLockServiceImpl::OnConnectionError() { |
115 DCHECK(binding_set_.dispatch_context()); | 107 DCHECK(binding_set_.dispatch_context()); |
116 | 108 |
117 // If the error-happening client's wakelock is in outstanding status, | 109 // If the error-happening client's wakelock is in outstanding status, |
118 // decrease the num_lock_requests and call UpdateWakeLock(). | 110 // decrease the num_lock_requests and call UpdateWakeLock(). |
119 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { | 111 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { |
120 num_lock_requests_--; | 112 num_lock_requests_--; |
121 UpdateWakeLock(); | 113 UpdateWakeLock(); |
122 } | 114 } |
123 | 115 |
124 // If |binding_set_| is empty, WakeLockServiceImpl should delele itself. | 116 // If |binding_set_| is empty, WakeLockServiceImpl should delele itself. |
125 if (binding_set_.empty()) | 117 if (binding_set_.empty()) |
126 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 118 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
127 } | 119 } |
128 | 120 |
129 } // namespace device | 121 } // namespace device |
OLD | NEW |