| OLD | NEW |
| 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 "device/power_save_blocker/power_save_blocker.h" | 5 #include "device/power_save_blocker/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/mac/scoped_cftyperef.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 | 16 |
| 16 namespace device { | 17 namespace device { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Power management cannot be done on the UI thread. IOPMAssertionCreate does a | 20 // Power management cannot be done on the UI thread. IOPMAssertionCreate does a |
| 20 // synchronous MIG call to configd, so if it is called on the main thread the UI | 21 // synchronous MIG call to configd, so if it is called on the main thread the UI |
| 21 // is at the mercy of another process. See http://crbug.com/79559 and | 22 // is at the mercy of another process. See http://crbug.com/79559 and |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 101 |
| 101 PowerSaveBlocker::PowerSaveBlocker( | 102 PowerSaveBlocker::PowerSaveBlocker( |
| 102 PowerSaveBlockerType type, | 103 PowerSaveBlockerType type, |
| 103 Reason reason, | 104 Reason reason, |
| 104 const std::string& description, | 105 const std::string& description, |
| 105 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 106 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 106 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) | 107 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) |
| 107 : delegate_(new Delegate(type, description)), | 108 : delegate_(new Delegate(type, description)), |
| 108 ui_task_runner_(ui_task_runner), | 109 ui_task_runner_(ui_task_runner), |
| 109 blocking_task_runner_(blocking_task_runner) { | 110 blocking_task_runner_(blocking_task_runner) { |
| 110 g_power_thread.Pointer()->message_loop()->PostTask( | 111 g_power_thread.Pointer()->task_runner()->PostTask( |
| 111 FROM_HERE, base::Bind(&Delegate::ApplyBlock, delegate_)); | 112 FROM_HERE, base::Bind(&Delegate::ApplyBlock, delegate_)); |
| 112 } | 113 } |
| 113 | 114 |
| 114 PowerSaveBlocker::~PowerSaveBlocker() { | 115 PowerSaveBlocker::~PowerSaveBlocker() { |
| 115 g_power_thread.Pointer()->message_loop()->PostTask( | 116 g_power_thread.Pointer()->task_runner()->PostTask( |
| 116 FROM_HERE, base::Bind(&Delegate::RemoveBlock, delegate_)); | 117 FROM_HERE, base::Bind(&Delegate::RemoveBlock, delegate_)); |
| 117 } | 118 } |
| 118 | 119 |
| 119 } // namespace device | 120 } // namespace device |
| OLD | NEW |