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