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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/power_save_blocker_impl.h" | 8 #include "content/browser/power_save_blocker_impl.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/power_save_blocker.h" | 10 #include "content/public/browser/power_save_blocker.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 bool WakeLockServiceContext::HasWakeLockForTests() const { | 55 bool WakeLockServiceContext::HasWakeLockForTests() const { |
56 return wake_lock_; | 56 return wake_lock_; |
57 } | 57 } |
58 | 58 |
59 void WakeLockServiceContext::CreateWakeLock() { | 59 void WakeLockServiceContext::CreateWakeLock() { |
60 DCHECK(!wake_lock_); | 60 DCHECK(!wake_lock_); |
61 wake_lock_ = PowerSaveBlocker::Create( | 61 wake_lock_ = PowerSaveBlocker::Create( |
62 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 62 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
63 PowerSaveBlocker::kReasonOther, "Wake Lock API"); | 63 PowerSaveBlocker::kReasonOther, "Wake Lock API"); |
64 | 64 |
65 #if defined(OS_ANDROID) | 65 //TODO(mfomitchev): Support PowerSaveBlocker on Aura - crbug.com/546718. |
| 66 #if defined(OS_ANDROID) && !defined(USE_AURA) |
66 // On Android, additionaly associate the blocker with this WebContents. | 67 // On Android, additionaly associate the blocker with this WebContents. |
67 DCHECK(web_contents()); | 68 DCHECK(web_contents()); |
68 | 69 |
69 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get()) | 70 static_cast<PowerSaveBlockerImpl*>(wake_lock_.get()) |
70 ->InitDisplaySleepBlocker(web_contents()); | 71 ->InitDisplaySleepBlocker(web_contents()); |
71 #endif | 72 #endif |
72 } | 73 } |
73 | 74 |
74 void WakeLockServiceContext::RemoveWakeLock() { | 75 void WakeLockServiceContext::RemoveWakeLock() { |
75 DCHECK(wake_lock_); | 76 DCHECK(wake_lock_); |
76 wake_lock_.reset(); | 77 wake_lock_.reset(); |
77 } | 78 } |
78 | 79 |
79 void WakeLockServiceContext::UpdateWakeLock() { | 80 void WakeLockServiceContext::UpdateWakeLock() { |
80 if (!frames_requesting_lock_.empty()) { | 81 if (!frames_requesting_lock_.empty()) { |
81 if (!wake_lock_) | 82 if (!wake_lock_) |
82 CreateWakeLock(); | 83 CreateWakeLock(); |
83 } else { | 84 } else { |
84 if (wake_lock_) | 85 if (wake_lock_) |
85 RemoveWakeLock(); | 86 RemoveWakeLock(); |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 } // namespace content | 90 } // namespace content |
OLD | NEW |