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

Side by Side Diff: content/browser/power_save_blocker_mac.cc

Issue 1207823004: PlatformThreadHandle: remove public id() interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: the last two nits Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/gpu/gpu_watchdog_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "content/browser/power_save_blocker_impl.h" 5 #include "content/browser/power_save_blocker_impl.h"
6 6
7 #include <IOKit/pwr_mgt/IOPMLib.h> 7 #include <IOKit/pwr_mgt/IOPMLib.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 private: 53 private:
54 friend class base::RefCountedThreadSafe<Delegate>; 54 friend class base::RefCountedThreadSafe<Delegate>;
55 ~Delegate() {} 55 ~Delegate() {}
56 PowerSaveBlockerType type_; 56 PowerSaveBlockerType type_;
57 std::string description_; 57 std::string description_;
58 IOPMAssertionID assertion_; 58 IOPMAssertionID assertion_;
59 }; 59 };
60 60
61 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { 61 void PowerSaveBlockerImpl::Delegate::ApplyBlock() {
62 DCHECK_EQ(base::PlatformThread::CurrentId(), 62 DCHECK_EQ(base::PlatformThread::CurrentId(),
63 g_power_thread.Pointer()->thread_id()); 63 g_power_thread.Pointer()->GetThreadId());
64 64
65 CFStringRef level = NULL; 65 CFStringRef level = NULL;
66 // See QA1340 <http://developer.apple.com/library/mac/#qa/qa1340/> for more 66 // See QA1340 <http://developer.apple.com/library/mac/#qa/qa1340/> for more
67 // details. 67 // details.
68 switch (type_) { 68 switch (type_) {
69 case PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension: 69 case PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension:
70 level = kIOPMAssertionTypeNoIdleSleep; 70 level = kIOPMAssertionTypeNoIdleSleep;
71 break; 71 break;
72 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: 72 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep:
73 level = kIOPMAssertionTypeNoDisplaySleep; 73 level = kIOPMAssertionTypeNoDisplaySleep;
74 break; 74 break;
75 default: 75 default:
76 NOTREACHED(); 76 NOTREACHED();
77 break; 77 break;
78 } 78 }
79 if (level) { 79 if (level) {
80 base::ScopedCFTypeRef<CFStringRef> cf_description( 80 base::ScopedCFTypeRef<CFStringRef> cf_description(
81 base::SysUTF8ToCFStringRef(description_)); 81 base::SysUTF8ToCFStringRef(description_));
82 IOReturn result = IOPMAssertionCreateWithName(level, kIOPMAssertionLevelOn, 82 IOReturn result = IOPMAssertionCreateWithName(level, kIOPMAssertionLevelOn,
83 cf_description, &assertion_); 83 cf_description, &assertion_);
84 LOG_IF(ERROR, result != kIOReturnSuccess) 84 LOG_IF(ERROR, result != kIOReturnSuccess)
85 << "IOPMAssertionCreate: " << result; 85 << "IOPMAssertionCreate: " << result;
86 } 86 }
87 } 87 }
88 88
89 void PowerSaveBlockerImpl::Delegate::RemoveBlock() { 89 void PowerSaveBlockerImpl::Delegate::RemoveBlock() {
90 DCHECK_EQ(base::PlatformThread::CurrentId(), 90 DCHECK_EQ(base::PlatformThread::CurrentId(),
91 g_power_thread.Pointer()->thread_id()); 91 g_power_thread.Pointer()->GetThreadId());
92 92
93 if (assertion_ != kIOPMNullAssertionID) { 93 if (assertion_ != kIOPMNullAssertionID) {
94 IOReturn result = IOPMAssertionRelease(assertion_); 94 IOReturn result = IOPMAssertionRelease(assertion_);
95 LOG_IF(ERROR, result != kIOReturnSuccess) 95 LOG_IF(ERROR, result != kIOReturnSuccess)
96 << "IOPMAssertionRelease: " << result; 96 << "IOPMAssertionRelease: " << result;
97 } 97 }
98 } 98 }
99 99
100 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type, 100 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type,
101 Reason reason, 101 Reason reason,
102 const std::string& description) 102 const std::string& description)
103 : delegate_(new Delegate(type, description)) { 103 : delegate_(new Delegate(type, description)) {
104 g_power_thread.Pointer()->message_loop()->PostTask( 104 g_power_thread.Pointer()->message_loop()->PostTask(
105 FROM_HERE, 105 FROM_HERE,
106 base::Bind(&Delegate::ApplyBlock, delegate_)); 106 base::Bind(&Delegate::ApplyBlock, delegate_));
107 } 107 }
108 108
109 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { 109 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
110 g_power_thread.Pointer()->message_loop()->PostTask( 110 g_power_thread.Pointer()->message_loop()->PostTask(
111 FROM_HERE, 111 FROM_HERE,
112 base::Bind(&Delegate::RemoveBlock, delegate_)); 112 base::Bind(&Delegate::RemoveBlock, delegate_));
113 } 113 }
114 114
115 } // namespace content 115 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/gpu/gpu_watchdog_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698