summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/system/screen_locker_settings.cc
blob: 620c3f2c81aeb07aac96990290bbeac4b2f1aeb5 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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 "chrome/browser/chromeos/system/touchpad_settings.h"

#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/stringprintf.h"
#include "chrome/browser/chromeos/system/runtime_environment.h"
#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

namespace {

const char kLockOnIdleSuspendPath[] =
    "/var/lib/power_manager/lock_on_idle_suspend";

void EnableScreenLockOnFileThread(bool enable) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));

  if (chromeos::system::runtime_environment::IsRunningOnChromeOS()) {
    std::string config = base::StringPrintf("%d", enable);
    file_util::WriteFile(FilePath(kLockOnIdleSuspendPath),
                         config.c_str(),
                         config.size());
  }
}

}  // namespace

namespace chromeos {
namespace system {
namespace screen_locker_settings {

void EnableScreenLock(bool enable) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  // Run this on the FILE thread.
  BrowserThread::PostTask(
      BrowserThread::FILE, FROM_HERE,
      base::Bind(&EnableScreenLockOnFileThread, enable));
}

}  // namespace screen_locker_settings
}  // namespace system
}  // namespace chromeos