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 <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 PowerSaveBlockerType type_; | 109 PowerSaveBlockerType type_; |
110 const std::string description_; | 110 const std::string description_; |
111 base::win::ScopedHandle handle_; | 111 base::win::ScopedHandle handle_; |
112 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 112 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
113 | 113 |
114 DISALLOW_COPY_AND_ASSIGN(Delegate); | 114 DISALLOW_COPY_AND_ASSIGN(Delegate); |
115 }; | 115 }; |
116 | 116 |
117 void PowerSaveBlocker::Delegate::ApplyBlock() { | 117 void PowerSaveBlocker::Delegate::ApplyBlock() { |
118 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 118 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
119 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 119 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
120 return ApplySimpleBlock(type_, 1); | 120 return ApplySimpleBlock(type_, 1); |
121 | 121 |
122 handle_.Set(CreatePowerRequest(RequestType(), description_)); | 122 handle_.Set(CreatePowerRequest(RequestType(), description_)); |
123 } | 123 } |
124 | 124 |
125 void PowerSaveBlocker::Delegate::RemoveBlock() { | 125 void PowerSaveBlocker::Delegate::RemoveBlock() { |
126 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 126 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence()); |
127 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 127 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
128 return ApplySimpleBlock(type_, -1); | 128 return ApplySimpleBlock(type_, -1); |
129 | 129 |
130 DeletePowerRequest(RequestType(), handle_.Take()); | 130 DeletePowerRequest(RequestType(), handle_.Take()); |
131 } | 131 } |
132 | 132 |
133 POWER_REQUEST_TYPE PowerSaveBlocker::Delegate::RequestType() { | 133 POWER_REQUEST_TYPE PowerSaveBlocker::Delegate::RequestType() { |
134 if (type_ == kPowerSaveBlockPreventDisplaySleep) | 134 if (type_ == kPowerSaveBlockPreventDisplaySleep) |
135 return PowerRequestDisplayRequired; | 135 return PowerRequestDisplayRequired; |
136 | 136 |
(...skipping 15 matching lines...) Expand all Loading... |
152 ui_task_runner_->PostTask(FROM_HERE, | 152 ui_task_runner_->PostTask(FROM_HERE, |
153 base::Bind(&Delegate::ApplyBlock, delegate_)); | 153 base::Bind(&Delegate::ApplyBlock, delegate_)); |
154 } | 154 } |
155 | 155 |
156 PowerSaveBlocker::~PowerSaveBlocker() { | 156 PowerSaveBlocker::~PowerSaveBlocker() { |
157 ui_task_runner_->PostTask(FROM_HERE, | 157 ui_task_runner_->PostTask(FROM_HERE, |
158 base::Bind(&Delegate::RemoveBlock, delegate_)); | 158 base::Bind(&Delegate::RemoveBlock, delegate_)); |
159 } | 159 } |
160 | 160 |
161 } // namespace device | 161 } // namespace device |
OLD | NEW |