1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_POWER_SAVE_BLOCKER_H_ 6 #define CHROME_BROWSER_POWER_SAVE_BLOCKER_H_ 7 #pragma once 8 9 #include "base/basictypes.h" 10 11 // A RAII-style class to block the system from entering low-power 12 // (sleep) mode. 13 class PowerSaveBlocker { 14 public: 15 explicit PowerSaveBlocker(bool enabled); 16 ~PowerSaveBlocker(); 17 enabled()18 bool enabled() const { return enabled_; } 19 20 // Puts the sleep mode block into effect. 21 void Enable(); 22 // Disables the sleep block. 23 void Disable(); 24 25 private: 26 // Platform-specific function called when enable state is changed. 27 // Guarenteed to be called only from the UI thread. 28 static void ApplyBlock(bool blocked); 29 30 // Called only from UI thread. 31 static void AdjustBlockCount(int delta); 32 33 // Invokes AdjustBlockCount on the UI thread. 34 static void PostAdjustBlockCount(int delta); 35 36 bool enabled_; 37 38 static int blocker_count_; 39 40 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); 41 }; 42 43 #endif // CHROME_BROWSER_POWER_SAVE_BLOCKER_H_ 44