| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/power_save_blocker.h" | 5 #include "chrome/browser/power_save_blocker.h" |
| 6 | 6 |
| 7 #include <IOKit/pwr_mgt/IOPMLib.h> | 7 #include <IOKit/pwr_mgt/IOPMLib.h> |
| 8 | 8 |
| 9 #include "chrome/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 10 | 10 |
| 11 // Run on the UI thread only. | 11 // Run on the UI thread only. |
| 12 void PowerSaveBlocker::ApplyBlock(bool blocking) { | 12 void PowerSaveBlocker::ApplyBlock(bool blocking) { |
| 13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 13 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 14 | 14 |
| 15 // Block just idle sleep; allow display sleep. | 15 // Block just idle sleep; allow display sleep. |
| 16 // See QA1340 <http://developer.apple.com/library/mac/#qa/qa2004/qa1340.html> | 16 // See QA1340 <http://developer.apple.com/library/mac/#qa/qa2004/qa1340.html> |
| 17 // for more details. | 17 // for more details. |
| 18 | 18 |
| 19 static IOPMAssertionID sleep_assertion = kIOPMNullAssertionID; | 19 static IOPMAssertionID sleep_assertion = kIOPMNullAssertionID; |
| 20 IOReturn result; | 20 IOReturn result; |
| 21 if (blocking) { | 21 if (blocking) { |
| 22 DCHECK_EQ(sleep_assertion, kIOPMNullAssertionID); | 22 DCHECK_EQ(sleep_assertion, kIOPMNullAssertionID); |
| 23 result = IOPMAssertionCreate( | 23 result = IOPMAssertionCreate( |
| 24 kIOPMAssertionTypeNoIdleSleep, | 24 kIOPMAssertionTypeNoIdleSleep, |
| 25 kIOPMAssertionLevelOn, | 25 kIOPMAssertionLevelOn, |
| 26 &sleep_assertion); | 26 &sleep_assertion); |
| 27 } else { | 27 } else { |
| 28 DCHECK_NE(sleep_assertion, kIOPMNullAssertionID); | 28 DCHECK_NE(sleep_assertion, kIOPMNullAssertionID); |
| 29 result = IOPMAssertionRelease(sleep_assertion); | 29 result = IOPMAssertionRelease(sleep_assertion); |
| 30 sleep_assertion = kIOPMNullAssertionID; | 30 sleep_assertion = kIOPMNullAssertionID; |
| 31 } | 31 } |
| 32 | 32 |
| 33 if (result != kIOReturnSuccess) { | 33 if (result != kIOReturnSuccess) { |
| 34 NOTREACHED(); | 34 NOTREACHED(); |
| 35 } | 35 } |
| 36 } | 36 } |
| OLD | NEW |