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

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

Issue 2006143006: Revert of Pass SequencedTaskRunner to PowerSaveBlocker for ui/file operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@device-power-save-blocker
Patch Set: Created 4 years, 7 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/power_save_blocker_ozone.cc ('k') | content/browser/power_save_blocker_x11.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"
6
5 #include <windows.h> 7 #include <windows.h>
6 8
7 #include "base/bind.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/win/scoped_handle.h" 12 #include "base/win/scoped_handle.h"
12 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
13 #include "content/browser/power_save_blocker_impl.h" 14 #include "content/public/browser/browser_thread.h"
14 15
15 namespace content { 16 namespace content {
16 namespace { 17 namespace {
17 18
18 int g_blocker_count[2]; 19 int g_blocker_count[2];
19 20
20 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, 21 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type,
21 const std::string& description) { 22 const std::string& description) {
22 if (type == PowerRequestExecutionRequired && 23 if (type == PowerRequestExecutionRequired &&
23 base::win::GetVersion() < base::win::VERSION_WIN8) { 24 base::win::GetVersion() < base::win::VERSION_WIN8) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 flags |= this_flag; 81 flags |= this_flag;
81 82
82 SetThreadExecutionState(flags); 83 SetThreadExecutionState(flags);
83 } 84 }
84 85
85 } // namespace 86 } // namespace
86 87
87 class PowerSaveBlockerImpl::Delegate 88 class PowerSaveBlockerImpl::Delegate
88 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { 89 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
89 public: 90 public:
90 Delegate(PowerSaveBlockerType type, 91 Delegate(PowerSaveBlockerType type, const std::string& description)
91 const std::string& description, 92 : type_(type), description_(description) {}
92 scoped_refptr<base::SequencedTaskRunner> ui_task_runner)
93 : type_(type),
94 description_(description),
95 ui_task_runner_(ui_task_runner) {}
96 93
97 // Does the actual work to apply or remove the desired power save block. 94 // Does the actual work to apply or remove the desired power save block.
98 void ApplyBlock(); 95 void ApplyBlock();
99 void RemoveBlock(); 96 void RemoveBlock();
100 97
101 // Returns the equivalent POWER_REQUEST_TYPE for this request. 98 // Returns the equivalent POWER_REQUEST_TYPE for this request.
102 POWER_REQUEST_TYPE RequestType(); 99 POWER_REQUEST_TYPE RequestType();
103 100
104 private: 101 private:
105 friend class base::RefCountedThreadSafe<Delegate>; 102 friend class base::RefCountedThreadSafe<Delegate>;
106 ~Delegate() {} 103 ~Delegate() {}
107 104
108 PowerSaveBlockerType type_; 105 PowerSaveBlockerType type_;
109 const std::string description_; 106 const std::string description_;
110 base::win::ScopedHandle handle_; 107 base::win::ScopedHandle handle_;
111 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
112 108
113 DISALLOW_COPY_AND_ASSIGN(Delegate); 109 DISALLOW_COPY_AND_ASSIGN(Delegate);
114 }; 110 };
115 111
116 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { 112 void PowerSaveBlockerImpl::Delegate::ApplyBlock() {
117 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 113 DCHECK_CURRENTLY_ON(BrowserThread::UI);
118 if (base::win::GetVersion() < base::win::VERSION_WIN7) 114 if (base::win::GetVersion() < base::win::VERSION_WIN7)
119 return ApplySimpleBlock(type_, 1); 115 return ApplySimpleBlock(type_, 1);
120 116
121 handle_.Set(CreatePowerRequest(RequestType(), description_)); 117 handle_.Set(CreatePowerRequest(RequestType(), description_));
122 } 118 }
123 119
124 void PowerSaveBlockerImpl::Delegate::RemoveBlock() { 120 void PowerSaveBlockerImpl::Delegate::RemoveBlock() {
125 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 121 DCHECK_CURRENTLY_ON(BrowserThread::UI);
126 if (base::win::GetVersion() < base::win::VERSION_WIN7) 122 if (base::win::GetVersion() < base::win::VERSION_WIN7)
127 return ApplySimpleBlock(type_, -1); 123 return ApplySimpleBlock(type_, -1);
128 124
129 DeletePowerRequest(RequestType(), handle_.Take()); 125 DeletePowerRequest(RequestType(), handle_.Take());
130 } 126 }
131 127
132 POWER_REQUEST_TYPE PowerSaveBlockerImpl::Delegate::RequestType() { 128 POWER_REQUEST_TYPE PowerSaveBlockerImpl::Delegate::RequestType() {
133 if (type_ == kPowerSaveBlockPreventDisplaySleep) 129 if (type_ == kPowerSaveBlockPreventDisplaySleep)
134 return PowerRequestDisplayRequired; 130 return PowerRequestDisplayRequired;
135 131
136 if (base::win::GetVersion() < base::win::VERSION_WIN8) 132 if (base::win::GetVersion() < base::win::VERSION_WIN8)
137 return PowerRequestSystemRequired; 133 return PowerRequestSystemRequired;
138 134
139 return PowerRequestExecutionRequired; 135 return PowerRequestExecutionRequired;
140 } 136 }
141 137
142 PowerSaveBlockerImpl::PowerSaveBlockerImpl( 138 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type,
143 PowerSaveBlockerType type, 139 Reason reason,
144 Reason reason, 140 const std::string& description)
145 const std::string& description, 141 : delegate_(new Delegate(type, description)) {
146 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 142 BrowserThread::PostTask(
147 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) 143 BrowserThread::UI, FROM_HERE,
148 : delegate_(new Delegate(type, description, ui_task_runner)), 144 base::Bind(&Delegate::ApplyBlock, delegate_));
149 ui_task_runner_(ui_task_runner),
150 blocking_task_runner_(blocking_task_runner) {
151 ui_task_runner_->PostTask(FROM_HERE,
152 base::Bind(&Delegate::ApplyBlock, delegate_));
153 } 145 }
154 146
155 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { 147 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
156 ui_task_runner_->PostTask(FROM_HERE, 148 BrowserThread::PostTask(
157 base::Bind(&Delegate::RemoveBlock, delegate_)); 149 BrowserThread::UI, FROM_HERE,
150 base::Bind(&Delegate::RemoveBlock, delegate_));
158 } 151 }
159 152
160 } // namespace content 153 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/power_save_blocker_ozone.cc ('k') | content/browser/power_save_blocker_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698