| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 WakeLockServiceImpl::~WakeLockServiceImpl() {} | 71 WakeLockServiceImpl::~WakeLockServiceImpl() {} |
| 72 | 72 |
| 73 void WakeLockServiceImpl::AddClient(mojom::WakeLockServiceRequest request) { | 73 void WakeLockServiceImpl::AddClient(mojom::WakeLockServiceRequest request) { |
| 74 binding_set_.AddBinding(this, std::move(request), | 74 binding_set_.AddBinding(this, std::move(request), |
| 75 base::MakeUnique<bool>(false)); | 75 base::MakeUnique<bool>(false)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void WakeLockServiceImpl::RequestWakeLock() { | 78 void WakeLockServiceImpl::RequestWakeLock() { |
| 79 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); | 79 DCHECK(main_task_runner_->RunsTasksInCurrentSequence()); |
| 80 DCHECK(binding_set_.dispatch_context()); | 80 DCHECK(binding_set_.dispatch_context()); |
| 81 | 81 |
| 82 // Uses the Context to get the outstanding status of current binding. | 82 // Uses the Context to get the outstanding status of current binding. |
| 83 // Two consecutive requests from the same client should be coalesced | 83 // Two consecutive requests from the same client should be coalesced |
| 84 // as one request. | 84 // as one request. |
| 85 if (*binding_set_.dispatch_context()) | 85 if (*binding_set_.dispatch_context()) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 *binding_set_.dispatch_context() = true; | 88 *binding_set_.dispatch_context() = true; |
| 89 num_lock_requests_++; | 89 num_lock_requests_++; |
| 90 UpdateWakeLock(); | 90 UpdateWakeLock(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void WakeLockServiceImpl::CancelWakeLock() { | 93 void WakeLockServiceImpl::CancelWakeLock() { |
| 94 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); | 94 DCHECK(main_task_runner_->RunsTasksInCurrentSequence()); |
| 95 DCHECK(binding_set_.dispatch_context()); | 95 DCHECK(binding_set_.dispatch_context()); |
| 96 | 96 |
| 97 if (!(*binding_set_.dispatch_context())) | 97 if (!(*binding_set_.dispatch_context())) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 DCHECK(num_lock_requests_ > 0); | 100 DCHECK(num_lock_requests_ > 0); |
| 101 *binding_set_.dispatch_context() = false; | 101 *binding_set_.dispatch_context() = false; |
| 102 num_lock_requests_--; | 102 num_lock_requests_--; |
| 103 UpdateWakeLock(); | 103 UpdateWakeLock(); |
| 104 } | 104 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { | 156 if (*binding_set_.dispatch_context() && num_lock_requests_ > 0) { |
| 157 num_lock_requests_--; | 157 num_lock_requests_--; |
| 158 UpdateWakeLock(); | 158 UpdateWakeLock(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 if (binding_set_.empty()) | 161 if (binding_set_.empty()) |
| 162 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 162 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace device | 165 } // namespace device |
| OLD | NEW |