| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 CHROMEOS_POWER_POWER_STATE_OVERRIDE_H_ | |
| 6 #define CHROMEOS_POWER_POWER_STATE_OVERRIDE_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/timer.h" | |
| 11 #include "chromeos/chromeos_export.h" | |
| 12 #include "chromeos/dbus/dbus_thread_manager_observer.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 | |
| 16 class DBusThreadManager; | |
| 17 | |
| 18 // This class overrides the current power state on the machine, disabling | |
| 19 // a set of power management features. | |
| 20 class CHROMEOS_EXPORT PowerStateOverride | |
| 21 : public base::RefCountedThreadSafe<PowerStateOverride>, | |
| 22 public DBusThreadManagerObserver { | |
| 23 public: | |
| 24 enum Mode { | |
| 25 // Blocks the screen from being dimmed or blanked due to user inactivity. | |
| 26 // Also implies BLOCK_SYSTEM_SUSPEND. | |
| 27 BLOCK_DISPLAY_SLEEP, | |
| 28 | |
| 29 // Blocks the system from being suspended due to user inactivity. | |
| 30 BLOCK_SYSTEM_SUSPEND, | |
| 31 }; | |
| 32 | |
| 33 explicit PowerStateOverride(Mode mode); | |
| 34 | |
| 35 // DBusThreadManagerObserver implementation: | |
| 36 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager) | |
| 37 OVERRIDE; | |
| 38 | |
| 39 private: | |
| 40 friend class base::RefCountedThreadSafe<PowerStateOverride>; | |
| 41 | |
| 42 // This destructor cancels the current power state override. There might be | |
| 43 // a very slight delay between the the last reference to an instance being | |
| 44 // released and the power state override being canceled. This is only in | |
| 45 // the case that the current instance has JUST been created and ChromeOS | |
| 46 // hasn't had a chance to service the initial power override request yet. | |
| 47 virtual ~PowerStateOverride(); | |
| 48 | |
| 49 // Callback from RequestPowerStateOverride which receives our request_id. | |
| 50 void SetRequestId(uint32 request_id); | |
| 51 | |
| 52 // Actually make a call to power manager; we need this to be able to post a | |
| 53 // delayed task since we cannot call back into power manager from Heartbeat | |
| 54 // since the last request has just been completed at that point. | |
| 55 void CallRequestPowerStateOverrides(); | |
| 56 | |
| 57 // Asks the power manager to cancel |request_id_| and sets it to zero. | |
| 58 // Does nothing if it's already zero. | |
| 59 void CancelRequest(); | |
| 60 | |
| 61 // Bitmap containing requested override types from | |
| 62 // PowerManagerClient::PowerStateOverrideType. | |
| 63 uint32 override_types_; | |
| 64 | |
| 65 // Outstanding override request ID, or 0 if there is no outstanding request. | |
| 66 uint32 request_id_; | |
| 67 | |
| 68 // Periodically invokes CallRequestPowerStateOverrides() to refresh the | |
| 69 // override. | |
| 70 base::RepeatingTimer<PowerStateOverride> heartbeat_; | |
| 71 | |
| 72 DBusThreadManager* dbus_thread_manager_; // not owned | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(PowerStateOverride); | |
| 75 }; | |
| 76 | |
| 77 } // namespace chromeos | |
| 78 | |
| 79 #endif // CHROMEOS_POWER_POWER_STATE_OVERRIDE_H_ | |
| OLD | NEW |