summaryrefslogtreecommitdiffstats
path: root/content/browser/power_save_blocker_win.cc
blob: 98df4de33f470145e688cf85c065568559096242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/power_save_blocker.h"

#include <windows.h>

#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

// Called only from UI thread.
// static
void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  DWORD flags = ES_CONTINUOUS;

  switch (type) {
    case kPowerSaveBlockPreventSystemSleep:
      flags |= ES_SYSTEM_REQUIRED;
      break;
    case kPowerSaveBlockPreventDisplaySleep:
      flags |= ES_DISPLAY_REQUIRED;
      break;
    default:
      break;
  }

  SetThreadExecutionState(flags);
}