Commit a329ebef authored by sque@chromium.org's avatar sque@chromium.org

chromeos: Move EnableScreenLock to PowerManagerClient from PowerLibrary

Part of libcros removal.  Directly writing to the prefs file, instead of going
thru libcros.

BUG=chromium-os:16558
TEST=Go to VT2 and make sure /var/lib/power_manager/lock_on_idle_suspend does not exist (delete if it does).  Type 'stop powerd'.  Sign in as a user.  Press power button to lock screen.  Go to VT2 and look at /var/lib/power_manager/lock_on_idle_suspend.  The file should have been created.
Signed-off-by: default avatarSimon Que <sque@chromium.org>

R=satorux@chromium.org,stevenjb@chromium.org


Review URL: http://codereview.chromium.org/8573025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111248 0039d316-1c4b-4281-b951-d872f2087c98
parent 2505827b
......@@ -230,10 +230,6 @@ void CrosMock::SetPowerLibraryStatusAreaExpectations() {
}
void CrosMock::SetPowerLibraryExpectations() {
// EnableScreenLock is currently bounded with a prefs value and thus is
// always called when loading
EXPECT_CALL(*mock_power_library_, EnableScreenLock(_))
.Times(AnyNumber());
}
void CrosMock::TearDownMocks() {
......
......@@ -21,8 +21,6 @@ class MockPowerLibrary : public PowerLibrary {
MOCK_METHOD1(AddObserver, void(Observer*));
MOCK_METHOD1(RemoveObserver, void(Observer*));
MOCK_METHOD1(EnableScreenLock, void(bool));
};
} // namespace chromeos
......
......@@ -48,23 +48,9 @@ class PowerLibraryImpl : public PowerLibrary {
observers_.RemoveObserver(observer);
}
virtual void EnableScreenLock(bool enable) OVERRIDE {
// Called when the screen preference is changed, which should always
// run on UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Post the task to FILE thread as chromeos::EnableScreenLock
// would write power manager config file to disk.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&PowerLibraryImpl::DoEnableScreenLock, enable));
}
// End PowerLibrary implementation.
private:
static void DoEnableScreenLock(bool enable) {
chromeos::EnableScreenLock(enable);
}
static void SystemResumedHandler(void* object) {
PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object);
......@@ -105,8 +91,6 @@ class PowerLibraryStubImpl : public PowerLibrary {
observers_.RemoveObserver(observer);
}
virtual void EnableScreenLock(bool enable) OVERRIDE {}
// End PowerLibrary implementation.
private:
ObserverList<Observer> observers_;
......
......@@ -32,9 +32,6 @@ class PowerLibrary {
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// Enable/disable screen lock for current session.
virtual void EnableScreenLock(bool enable) = 0;
// Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via CrosLibrary::Get().
static PowerLibrary* GetImpl(bool stub);
......
......@@ -11,12 +11,11 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/input_method/xkeyboard.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/system/screen_locker_settings.h"
#include "chrome/browser/chromeos/system/touchpad_settings.h"
#include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/prefs/pref_service.h"
......@@ -456,7 +455,7 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
// Init or update power manager config.
if (!pref_name || *pref_name == prefs::kEnableScreenLock) {
CrosLibrary::Get()->GetPowerLibrary()->EnableScreenLock(
system::screen_locker_settings::EnableScreenLock(
enable_screen_lock_.GetValue());
}
}
......
// 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
// 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.
#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_SCREEN_LOCKER_SETTINGS_H_
#define CHROME_BROWSER_CHROMEOS_SYSTEM_SCREEN_LOCKER_SETTINGS_H_
#pragma once
namespace chromeos {
namespace system {
namespace screen_locker_settings {
// Enables/disables screen locking.
void EnableScreenLock(bool enabled);
} // namespace screen_locker_settings
} // namespace system
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_SCREEN_LOCKER_SETTINGS_H_
......@@ -773,6 +773,8 @@
'browser/chromeos/system/name_value_pairs_parser.h',
'browser/chromeos/system/runtime_environment.cc',
'browser/chromeos/system/runtime_environment.h',
'browser/chromeos/system/screen_locker_settings.cc',
'browser/chromeos/system/screen_locker_settings.h',
'browser/chromeos/system/statistics_provider.cc',
'browser/chromeos/system/statistics_provider.h',
'browser/chromeos/system/syslogs_provider.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment