| 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_context.h" | 5 #include "content/browser/wake_lock/wake_lock_service_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 bool WakeLockServiceContext::HasWakeLockForTests() const { | 63 bool WakeLockServiceContext::HasWakeLockForTests() const { |
| 64 return !!wake_lock_; | 64 return !!wake_lock_; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void WakeLockServiceContext::CreateWakeLock() { | 67 void WakeLockServiceContext::CreateWakeLock() { |
| 68 DCHECK(!wake_lock_); | 68 DCHECK(!wake_lock_); |
| 69 wake_lock_.reset(new device::PowerSaveBlocker( | 69 wake_lock_.reset(new device::PowerSaveBlocker( |
| 70 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 70 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
| 71 device::PowerSaveBlocker::kReasonOther, "Wake Lock API", | 71 device::PowerSaveBlocker::kReasonOther, "Wake Lock API", |
| 72 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 72 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 73 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 73 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 74 | 74 |
| 75 #if defined(OS_ANDROID) | 75 #if defined(OS_ANDROID) |
| 76 // On Android, additionaly associate the blocker with this WebContents. | 76 // On Android, additionaly associate the blocker with this WebContents. |
| 77 DCHECK(web_contents()); | 77 DCHECK(web_contents()); |
| 78 | 78 |
| 79 if (web_contents()->GetNativeView()) { | 79 if (web_contents()->GetNativeView()) { |
| 80 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( | 80 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( |
| 81 web_contents()->GetNativeView())); | 81 web_contents()->GetNativeView())); |
| 82 wake_lock_.get()->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); | 82 wake_lock_.get()->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); |
| 83 } | 83 } |
| 84 #endif | 84 #endif |
| 85 } | 85 } |
| 86 | 86 |
| 87 void WakeLockServiceContext::RemoveWakeLock() { | 87 void WakeLockServiceContext::RemoveWakeLock() { |
| 88 DCHECK(wake_lock_); | 88 DCHECK(wake_lock_); |
| 89 wake_lock_.reset(); | 89 wake_lock_.reset(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void WakeLockServiceContext::UpdateWakeLock() { | 92 void WakeLockServiceContext::UpdateWakeLock() { |
| 93 if (!frames_requesting_lock_.empty()) { | 93 if (!frames_requesting_lock_.empty()) { |
| 94 if (!wake_lock_) | 94 if (!wake_lock_) |
| 95 CreateWakeLock(); | 95 CreateWakeLock(); |
| 96 } else { | 96 } else { |
| 97 if (wake_lock_) | 97 if (wake_lock_) |
| 98 RemoveWakeLock(); | 98 RemoveWakeLock(); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace content | 102 } // namespace content |
| OLD | NEW |