Chromium Code Reviews| Index: device/wake_lock/fake_wake_lock_service_impl.cc |
| diff --git a/device/wake_lock/fake_wake_lock_service_impl.cc b/device/wake_lock/fake_wake_lock_service_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..144cf996471c1adac672d5bce92617b82bd4a241 |
| --- /dev/null |
| +++ b/device/wake_lock/fake_wake_lock_service_impl.cc |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "device/wake_lock/fake_wake_lock_service_impl.h" |
| + |
| +#include <utility> |
| + |
| +namespace device { |
| + |
| +FakeWakeLockServiceImpl::FakeWakeLockServiceImpl( |
|
blundell
2017/06/01 11:35:58
nit: Let's call this WakeLockServiceImplForTesting
ke.he
2017/06/06 05:25:57
Done.
|
| + mojom::WakeLockServiceRequest request, |
| + mojom::WakeLockType type, |
| + mojom::WakeLockReason reason, |
| + const std::string& description, |
| + int context_id, |
| + WakeLockContextCallback native_view_getter, |
| + scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) |
| + : WakeLockServiceImpl(std::move(request), |
| + type, |
| + reason, |
| + description, |
| + context_id, |
| + native_view_getter, |
| + file_task_runner), |
| + has_fake_wake_lock_(false) {} |
|
blundell
2017/06/01 11:35:58
nit: Let's just call this |has_wake_lock_|.
ke.he
2017/06/06 05:25:57
Done.
|
| + |
| +FakeWakeLockServiceImpl::~FakeWakeLockServiceImpl() {} |
| + |
| +void FakeWakeLockServiceImpl::HasWakeLockForTests( |
| + const HasWakeLockForTestsCallback& callback) { |
| + callback.Run(has_fake_wake_lock_); |
| +} |
| + |
| +void FakeWakeLockServiceImpl::UpdateWakeLock() { |
| + DCHECK(num_lock_requests_ >= 0); |
| + |
| + if (num_lock_requests_) { |
| + if (!has_fake_wake_lock_) |
| + CreateWakeLock(); |
| + } else { |
| + if (has_fake_wake_lock_) |
| + RemoveWakeLock(); |
| + } |
| +} |
| + |
| +void FakeWakeLockServiceImpl::CreateWakeLock() { |
| + DCHECK(!has_fake_wake_lock_); |
| + has_fake_wake_lock_ = true; |
| +} |
| + |
| +void FakeWakeLockServiceImpl::RemoveWakeLock() { |
| + DCHECK(has_fake_wake_lock_); |
| + has_fake_wake_lock_ = false; |
| +} |
| + |
| +} // namespace device |