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

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

Issue 11340029: Move remaining files in content\browser to the content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
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 <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/win/scoped_handle.h" 11 #include "base/win/scoped_handle.h"
12 #include "base/win/windows_version.h" 12 #include "base/win/windows_version.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 14
15 namespace content {
15 namespace { 16 namespace {
16 17
17 int g_blocker_count[2]; 18 int g_blocker_count[2];
18 19
19 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, const std::string& reason) { 20 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, const std::string& reason) {
20 typedef HANDLE (WINAPI* PowerCreateRequestPtr)(PREASON_CONTEXT); 21 typedef HANDLE (WINAPI* PowerCreateRequestPtr)(PREASON_CONTEXT);
21 typedef BOOL (WINAPI* PowerSetRequestPtr)(HANDLE, POWER_REQUEST_TYPE); 22 typedef BOOL (WINAPI* PowerSetRequestPtr)(HANDLE, POWER_REQUEST_TYPE);
22 23
23 if (type == PowerRequestExecutionRequired && 24 if (type == PowerRequestExecutionRequired &&
24 base::win::GetVersion() < base::win::VERSION_WIN8) { 25 base::win::GetVersion() < base::win::VERSION_WIN8) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 reinterpret_cast<PowerClearRequestPtr>( 73 reinterpret_cast<PowerClearRequestPtr>(
73 GetProcAddress(module, "PowerClearRequest")); 74 GetProcAddress(module, "PowerClearRequest"));
74 75
75 if (!PowerClearRequestFn) 76 if (!PowerClearRequestFn)
76 return; 77 return;
77 78
78 BOOL success = PowerClearRequestFn(request_handle, type); 79 BOOL success = PowerClearRequestFn(request_handle, type);
79 DCHECK(success); 80 DCHECK(success);
80 } 81 }
81 82
82 void ApplySimpleBlock(content::PowerSaveBlocker::PowerSaveBlockerType type, 83 void ApplySimpleBlock(PowerSaveBlocker::PowerSaveBlockerType type,
83 int delta) { 84 int delta) {
tfarina 2012/10/30 22:19:06 probably fits above now.
84 g_blocker_count[type] += delta; 85 g_blocker_count[type] += delta;
85 DCHECK_GE(g_blocker_count[type], 0); 86 DCHECK_GE(g_blocker_count[type], 0);
86 87
87 if (g_blocker_count[type] > 1) 88 if (g_blocker_count[type] > 1)
88 return; 89 return;
89 90
90 DWORD this_flag = 0; 91 DWORD this_flag = 0;
91 if (type == content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension) 92 if (type == PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension)
92 this_flag |= ES_SYSTEM_REQUIRED; 93 this_flag |= ES_SYSTEM_REQUIRED;
93 else 94 else
94 this_flag |= ES_DISPLAY_REQUIRED; 95 this_flag |= ES_DISPLAY_REQUIRED;
95 96
96 DCHECK(this_flag); 97 DCHECK(this_flag);
97 98
98 static DWORD flags = ES_CONTINUOUS; 99 static DWORD flags = ES_CONTINUOUS;
99 if (!g_blocker_count[type]) 100 if (!g_blocker_count[type])
100 flags &= ~this_flag; 101 flags &= ~this_flag;
101 else 102 else
102 flags |= this_flag; 103 flags |= this_flag;
103 104
104 SetThreadExecutionState(flags); 105 SetThreadExecutionState(flags);
105 } 106 }
106 107
107 } // namespace. 108 } // namespace.
108 109
109 namespace content {
110
111 class PowerSaveBlocker::Delegate 110 class PowerSaveBlocker::Delegate
112 : public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> { 111 : public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> {
113 public: 112 public:
114 Delegate(PowerSaveBlockerType type, const std::string& reason) 113 Delegate(PowerSaveBlockerType type, const std::string& reason)
115 : type_(type), reason_(reason) {} 114 : type_(type), reason_(reason) {}
116 115
117 // Does the actual work to apply or remove the desired power save block. 116 // Does the actual work to apply or remove the desired power save block.
118 void ApplyBlock(); 117 void ApplyBlock();
119 void RemoveBlock(); 118 void RemoveBlock();
120 119
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::Bind(&Delegate::ApplyBlock, delegate_)); 165 base::Bind(&Delegate::ApplyBlock, delegate_));
167 } 166 }
168 167
169 PowerSaveBlocker::~PowerSaveBlocker() { 168 PowerSaveBlocker::~PowerSaveBlocker() {
170 BrowserThread::PostTask( 169 BrowserThread::PostTask(
171 BrowserThread::UI, FROM_HERE, 170 BrowserThread::UI, FROM_HERE,
172 base::Bind(&Delegate::RemoveBlock, delegate_)); 171 base::Bind(&Delegate::RemoveBlock, delegate_));
173 } 172 }
174 173
175 } // namespace content 174 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698