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

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

Issue 10832392: Fix leak in Mac PowerSaveBlocker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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.h" 5 #include "content/browser/power_save_blocker.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"
11 #include "base/mac/scoped_cftyperef.h"
11 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
12 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 namespace { 17 namespace {
17 18
18 // Power management cannot be done on the UI thread. IOPMAssertionCreate does a 19 // Power management cannot be done on the UI thread. IOPMAssertionCreate does a
19 // synchronous MIG call to configd, so if it is called on the main thread the UI 20 // synchronous MIG call to configd, so if it is called on the main thread the UI
20 // is at the mercy of another process. See http://crbug.com/79559 and 21 // is at the mercy of another process. See http://crbug.com/79559 and
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 level = kIOPMAssertionTypeNoIdleSleep; 68 level = kIOPMAssertionTypeNoIdleSleep;
68 break; 69 break;
69 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: 70 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep:
70 level = kIOPMAssertionTypeNoDisplaySleep; 71 level = kIOPMAssertionTypeNoDisplaySleep;
71 break; 72 break;
72 default: 73 default:
73 NOTREACHED(); 74 NOTREACHED();
74 break; 75 break;
75 } 76 }
76 if (level) { 77 if (level) {
77 IOReturn result = IOPMAssertionCreateWithName(level, kIOPMAssertionLevelOn, 78 base::mac::ScopedCFTypeRef<CFStringRef> cf_reason(
78 base::SysUTF8ToCFStringRef(reason_), &assertion_); 79 base::SysUTF8ToCFStringRef(reason_));
80 IOReturn result = IOPMAssertionCreateWithName(level,
81 kIOPMAssertionLevelOn,
82 cf_reason,
83 &assertion_);
79 LOG_IF(ERROR, result != kIOReturnSuccess) 84 LOG_IF(ERROR, result != kIOReturnSuccess)
80 << "IOPMAssertionCreate: " << result; 85 << "IOPMAssertionCreate: " << result;
81 } 86 }
82 } 87 }
83 88
84 void PowerSaveBlocker::Delegate::RemoveBlock() { 89 void PowerSaveBlocker::Delegate::RemoveBlock() {
85 DCHECK_EQ(base::PlatformThread::CurrentId(), 90 DCHECK_EQ(base::PlatformThread::CurrentId(),
86 g_power_thread.Pointer()->thread_id()); 91 g_power_thread.Pointer()->thread_id());
87 92
88 if (assertion_ != kIOPMNullAssertionID) { 93 if (assertion_ != kIOPMNullAssertionID) {
(...skipping 11 matching lines...) Expand all
100 base::Bind(&Delegate::ApplyBlock, delegate_)); 105 base::Bind(&Delegate::ApplyBlock, delegate_));
101 } 106 }
102 107
103 PowerSaveBlocker::~PowerSaveBlocker() { 108 PowerSaveBlocker::~PowerSaveBlocker() {
104 g_power_thread.Pointer()->message_loop()->PostTask( 109 g_power_thread.Pointer()->message_loop()->PostTask(
105 FROM_HERE, 110 FROM_HERE,
106 base::Bind(&Delegate::RemoveBlock, delegate_)); 111 base::Bind(&Delegate::RemoveBlock, delegate_));
107 } 112 }
108 113
109 } // namespace content 114 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698