Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 void WakeLockServiceImpl::CancelWakeLock() { | 58 void WakeLockServiceImpl::CancelWakeLock() { |
| 59 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); | 59 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); |
| 60 DCHECK(binding_set_.dispatch_context()); | 60 DCHECK(binding_set_.dispatch_context()); |
| 61 | 61 |
| 62 if (!(*binding_set_.dispatch_context())) | 62 if (!(*binding_set_.dispatch_context())) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 *binding_set_.dispatch_context() = false; | 65 *binding_set_.dispatch_context() = false; |
| 66 if (num_lock_requests_ > 0) { | 66 DCHECK(num_lock_requests_ > 0); |
|
blundell
2017/05/09 16:05:11
tiny nit: I would order this above line 65 from a
ke.he
2017/05/10 02:42:14
Done.
| |
| 67 num_lock_requests_--; | 67 num_lock_requests_--; |
| 68 UpdateWakeLock(); | 68 UpdateWakeLock(); |
| 69 } | |
| 70 } | 69 } |
| 71 | 70 |
| 72 void WakeLockServiceImpl::HasWakeLockForTests( | 71 void WakeLockServiceImpl::HasWakeLockForTests( |
| 73 const HasWakeLockForTestsCallback& callback) { | 72 const HasWakeLockForTestsCallback& callback) { |
| 74 callback.Run(!!wake_lock_); | 73 callback.Run(!!wake_lock_); |
| 75 } | 74 } |
| 76 void WakeLockServiceImpl::UpdateWakeLock() { | 75 void WakeLockServiceImpl::UpdateWakeLock() { |
| 77 DCHECK(num_lock_requests_ >= 0); | 76 DCHECK(num_lock_requests_ >= 0); |
| 78 | 77 |
| 79 if (num_lock_requests_) { | 78 if (num_lock_requests_) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 105 wake_lock_.get()->InitDisplaySleepBlocker(native_view); | 104 wake_lock_.get()->InitDisplaySleepBlocker(native_view); |
| 106 #endif | 105 #endif |
| 107 } | 106 } |
| 108 | 107 |
| 109 void WakeLockServiceImpl::RemoveWakeLock() { | 108 void WakeLockServiceImpl::RemoveWakeLock() { |
| 110 DCHECK(wake_lock_); | 109 DCHECK(wake_lock_); |
| 111 wake_lock_.reset(); | 110 wake_lock_.reset(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void WakeLockServiceImpl::OnConnectionError() { | 113 void WakeLockServiceImpl::OnConnectionError() { |
| 115 DCHECK(binding_set_.dispatch_context()); | |
| 116 | |
| 117 // If the error-happening client's wakelock is in outstanding status, | 114 // If the error-happening client's wakelock is in outstanding status, |
|
blundell
2017/05/09 16:05:11
tiny nit: "the error-happening client's wakelock i
ke.he
2017/05/10 02:42:14
Thanks:)
Done.
| |
| 118 // decrease the num_lock_requests and call UpdateWakeLock(). | 115 // decrease the num_lock_requests and call UpdateWakeLock(). |
| 119 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { | 116 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { |
| 120 num_lock_requests_--; | 117 num_lock_requests_--; |
| 121 UpdateWakeLock(); | 118 UpdateWakeLock(); |
| 122 } | 119 } |
| 123 | 120 |
| 124 // If |binding_set_| is empty, WakeLockServiceImpl should delele itself. | |
| 125 if (binding_set_.empty()) | 121 if (binding_set_.empty()) |
| 126 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 122 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 127 } | 123 } |
| 128 | 124 |
| 129 } // namespace device | 125 } // namespace device |
| OLD | NEW |