| 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 "content/browser/wake_lock/wake_lock_service_impl.h" | 5 #include "content/browser/wake_lock/wake_lock_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/wake_lock/wake_lock_service_context.h" | 9 #include "content/browser/wake_lock/wake_lock_service_context.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 WakeLockServiceImpl::WakeLockServiceImpl( | 13 WakeLockServiceImpl::WakeLockServiceImpl( |
| 14 base::WeakPtr<WakeLockServiceContext> context, | 14 base::WeakPtr<WakeLockServiceContext> context) |
| 15 int render_process_id, | 15 : context_(context), wake_lock_request_outstanding_(false) {} |
| 16 int render_frame_id) | |
| 17 : context_(context), | |
| 18 render_process_id_(render_process_id), | |
| 19 render_frame_id_(render_frame_id) {} | |
| 20 | 16 |
| 21 WakeLockServiceImpl::~WakeLockServiceImpl() {} | 17 WakeLockServiceImpl::~WakeLockServiceImpl() { |
| 18 CancelWakeLock(); |
| 19 } |
| 22 | 20 |
| 23 void WakeLockServiceImpl::RequestWakeLock() { | 21 void WakeLockServiceImpl::RequestWakeLock() { |
| 24 if (context_) | 22 if (!context_ || wake_lock_request_outstanding_) |
| 25 context_->RequestWakeLock(render_process_id_, render_frame_id_); | 23 return; |
| 24 |
| 25 wake_lock_request_outstanding_ = true; |
| 26 context_->RequestWakeLock(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 void WakeLockServiceImpl::CancelWakeLock() { | 29 void WakeLockServiceImpl::CancelWakeLock() { |
| 29 if (context_) | 30 if (!context_ || !wake_lock_request_outstanding_) |
| 30 context_->CancelWakeLock(render_process_id_, render_frame_id_); | 31 return; |
| 32 |
| 33 wake_lock_request_outstanding_ = false; |
| 34 context_->CancelWakeLock(); |
| 31 } | 35 } |
| 32 | 36 |
| 33 } // namespace content | 37 } // namespace content |
| OLD | NEW |