Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Unified Diff: content/browser/power_save_blocker_mac.cc

Issue 10542089: Power save blocker: switch to new implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/power_save_blocker_linux.cc ('k') | content/browser/power_save_blocker_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/power_save_blocker_mac.cc
===================================================================
--- content/browser/power_save_blocker_mac.cc (revision 141149)
+++ content/browser/power_save_blocker_mac.cc (working copy)
@@ -12,76 +12,12 @@
#include "base/threading/thread.h"
#include "content/public/browser/browser_thread.h"
-using content::BrowserThread;
-
namespace {
// Power management cannot be done on the UI thread. IOPMAssertionCreate does a
// synchronous MIG call to configd, so if it is called on the main thread the UI
// is at the mercy of another process. See http://crbug.com/79559 and
// http://www.opensource.apple.com/source/IOKitUser/IOKitUser-514.16.31/pwr_mgt.subproj/IOPMLibPrivate.c .
-base::Thread* g_power_thread;
-IOPMAssertionID g_power_assertion;
-
-void CreateSleepAssertion(PowerSaveBlocker::PowerSaveBlockerType type) {
- DCHECK_EQ(base::PlatformThread::CurrentId(), g_power_thread->thread_id());
- IOReturn result;
-
- if (g_power_assertion != kIOPMNullAssertionID) {
- result = IOPMAssertionRelease(g_power_assertion);
- g_power_assertion = kIOPMNullAssertionID;
- LOG_IF(ERROR, result != kIOReturnSuccess)
- << "IOPMAssertionRelease: " << result;
- }
-
- CFStringRef level = NULL;
- // See QA1340 <http://developer.apple.com/library/mac/#qa/qa1340/> for more
- // details.
- switch (type) {
- case PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep:
- level = kIOPMAssertionTypeNoIdleSleep;
- break;
- case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep:
- level = kIOPMAssertionTypeNoDisplaySleep;
- break;
- default:
- break;
- }
- if (level) {
- result = IOPMAssertionCreate(level,
- kIOPMAssertionLevelOn,
- &g_power_assertion);
- LOG_IF(ERROR, result != kIOReturnSuccess)
- << "IOPMAssertionCreate: " << result;
- }
-}
-
-} // namespace
-
-// Called only from UI thread.
-// static
-void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- if (!g_power_thread) {
- g_power_assertion = kIOPMNullAssertionID;
- g_power_thread = new base::Thread("PowerSaveBlocker");
- g_power_thread->Start();
- }
-
- g_power_thread->message_loop()->
- PostTask(FROM_HERE, base::Bind(CreateSleepAssertion, type));
-}
-
-// TODO(avi): Remove ^^^ this code in favor of vvv this code.
-// http://crbug.com/126591
-
-namespace {
-
-// Power management cannot be done on the UI thread. IOPMAssertionCreate does a
-// synchronous MIG call to configd, so if it is called on the main thread the UI
-// is at the mercy of another process. See http://crbug.com/79559 and
-// http://www.opensource.apple.com/source/IOKitUser/IOKitUser-514.16.31/pwr_mgt.subproj/IOPMLibPrivate.c .
struct PowerSaveBlockerLazyInstanceTraits {
static const bool kRegisterOnExit = false;
static const bool kAllowedToAccessOnNonjoinableThread = true;
@@ -100,8 +36,8 @@
namespace content {
-class PowerSaveBlocker2::Delegate
- : public base::RefCountedThreadSafe<PowerSaveBlocker2::Delegate> {
+class PowerSaveBlocker::Delegate
+ : public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> {
public:
Delegate(PowerSaveBlockerType type, const std::string& reason)
: type_(type), reason_(reason), assertion_(kIOPMNullAssertionID) {}
@@ -111,14 +47,14 @@
void RemoveBlock();
private:
- friend class base::RefCountedThreadSafe<PowerSaveBlocker2::Delegate>;
+ friend class base::RefCountedThreadSafe<Delegate>;
~Delegate() {}
PowerSaveBlockerType type_;
std::string reason_;
IOPMAssertionID assertion_;
};
-void PowerSaveBlocker2::Delegate::ApplyBlock() {
+void PowerSaveBlocker::Delegate::ApplyBlock() {
DCHECK_EQ(base::PlatformThread::CurrentId(),
g_power_thread2.Pointer()->thread_id());
@@ -126,10 +62,10 @@
// See QA1340 <http://developer.apple.com/library/mac/#qa/qa1340/> for more
// details.
switch (type_) {
- case PowerSaveBlocker2::kPowerSaveBlockPreventAppSuspension:
+ case PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension:
level = kIOPMAssertionTypeNoIdleSleep;
break;
- case PowerSaveBlocker2::kPowerSaveBlockPreventDisplaySleep:
+ case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep:
level = kIOPMAssertionTypeNoDisplaySleep;
break;
default:
@@ -147,7 +83,7 @@
}
}
-void PowerSaveBlocker2::Delegate::RemoveBlock() {
+void PowerSaveBlocker::Delegate::RemoveBlock() {
DCHECK_EQ(base::PlatformThread::CurrentId(),
g_power_thread2.Pointer()->thread_id());
@@ -158,18 +94,18 @@
}
}
-PowerSaveBlocker2::PowerSaveBlocker2(PowerSaveBlockerType type,
- const std::string& reason)
- : delegate_(new PowerSaveBlocker2::Delegate(type, reason)) {
+PowerSaveBlocker::PowerSaveBlocker(PowerSaveBlockerType type,
+ const std::string& reason)
+ : delegate_(new Delegate(type, reason)) {
g_power_thread2.Pointer()->message_loop()->PostTask(
FROM_HERE,
- base::Bind(&PowerSaveBlocker2::Delegate::ApplyBlock, delegate_));
+ base::Bind(&Delegate::ApplyBlock, delegate_));
}
-PowerSaveBlocker2::~PowerSaveBlocker2() {
+PowerSaveBlocker::~PowerSaveBlocker() {
g_power_thread2.Pointer()->message_loop()->PostTask(
FROM_HERE,
- base::Bind(&PowerSaveBlocker2::Delegate::RemoveBlock, delegate_));
+ base::Bind(&Delegate::RemoveBlock, delegate_));
}
} // namespace content
« no previous file with comments | « content/browser/power_save_blocker_linux.cc ('k') | content/browser/power_save_blocker_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698