| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // mojom::WakeLockReason once all its clients are converted to be the clients | 126 // mojom::WakeLockReason once all its clients are converted to be the clients |
| 127 // of WakeLock. | 127 // of WakeLock. |
| 128 wake_lock_ = base::MakeUnique<PowerSaveBlocker>( | 128 wake_lock_ = base::MakeUnique<PowerSaveBlocker>( |
| 129 ToPowerSaveBlockerType(type_), ToPowerSaveBlockerReason(reason_), | 129 ToPowerSaveBlockerType(type_), ToPowerSaveBlockerReason(reason_), |
| 130 *description_, main_task_runner_, file_task_runner_); | 130 *description_, main_task_runner_, file_task_runner_); |
| 131 | 131 |
| 132 if (type_ != mojom::WakeLockType::PreventDisplaySleep) | 132 if (type_ != mojom::WakeLockType::PreventDisplaySleep) |
| 133 return; | 133 return; |
| 134 | 134 |
| 135 #if defined(OS_ANDROID) | 135 #if defined(OS_ANDROID) |
| 136 if (context_id_ == WakeLockServiceContext::WakeLockInvalidContextId) { |
| 137 LOG(ERROR) << "Client must pass a valid context_id when requests wake lock " |
| 138 "on Android."; |
| 139 return; |
| 140 } |
| 141 |
| 136 gfx::NativeView native_view = native_view_getter_.Run(context_id_); | 142 gfx::NativeView native_view = native_view_getter_.Run(context_id_); |
| 137 if (native_view) | 143 if (native_view) |
| 138 wake_lock_.get()->InitDisplaySleepBlocker(native_view); | 144 wake_lock_.get()->InitDisplaySleepBlocker(native_view); |
| 139 #endif | 145 #endif |
| 140 } | 146 } |
| 141 | 147 |
| 142 void WakeLockServiceImpl::RemoveWakeLock() { | 148 void WakeLockServiceImpl::RemoveWakeLock() { |
| 143 DCHECK(wake_lock_); | 149 DCHECK(wake_lock_); |
| 144 wake_lock_.reset(); | 150 wake_lock_.reset(); |
| 145 } | 151 } |
| 146 | 152 |
| 147 void WakeLockServiceImpl::OnConnectionError() { | 153 void WakeLockServiceImpl::OnConnectionError() { |
| 148 // If this client has an outstanding wake lock request, decrease the | 154 // If this client has an outstanding wake lock request, decrease the |
| 149 // num_lock_requests and call UpdateWakeLock(). | 155 // num_lock_requests and call UpdateWakeLock(). |
| 150 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { | 156 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { |
| 151 num_lock_requests_--; | 157 num_lock_requests_--; |
| 152 UpdateWakeLock(); | 158 UpdateWakeLock(); |
| 153 } | 159 } |
| 154 | 160 |
| 155 if (binding_set_.empty()) | 161 if (binding_set_.empty()) |
| 156 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 162 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 157 } | 163 } |
| 158 | 164 |
| 159 } // namespace device | 165 } // namespace device |
| OLD | NEW |